-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDemo_10_DefiningVelocity.py
48 lines (47 loc) · 1.11 KB
/
Demo_10_DefiningVelocity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pygame
x=pygame.init()
#Colors
white=(255,255,255)
red=(255,0,0)
black=(0,0,0)
#print(x)
#Creating Window
screen_width=600
screen_height=300
screen_caption="Snake Game"
gameWindow=pygame.display.set_mode((screen_width,screen_height))
pygame.display.set_caption(screen_caption)
pygame.display.update()
# Game specific Variable
exit_game=False
game_over=False
Snake_x=45
Snake_y=55
Snake_size=10
velocity_x=3
velocity_y=3
fps=30 #means frame per secound
clock=pygame.time.Clock()
#Creating Game loop
while not exit_game:
for event in pygame.event.get():
print(event)
if event.type==pygame.QUIT:
exit_game=True
if event.type==pygame.KEYDOWN:
if event.key==pygame.K_RIGHT:
Snake_x=Snake_x+10
if event.key==pygame.K_LEFT:
Snake_x=Snake_x-10
if event.key==pygame.K_UP:
Snake_y=Snake_y-10
if event.key==pygame.K_DOWN:
Snake_y=Snake_y+10
Snake_x +=velocity_x
Snake_y +=velocity_y
gameWindow.fill(white)
pygame.draw.rect(gameWindow,black,[Snake_x,Snake_y,Snake_size,Snake_size])
pygame.display.update()
clock.tick(fps)
pygame.quit()
quit()