-
Notifications
You must be signed in to change notification settings - Fork 0
/
snake2.py
50 lines (43 loc) · 1.24 KB
/
snake2.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
49
50
import pygame, sys
from pygame.locals import *
catx = 10
caty = 10
screen = 0
def myquit():
#Quit Function
pygame.quit()
sys.exit(0)
def check_inputs(events):
global catx,caty,screen
#Fucntion to handle the events occured
for event in events:
if event.type == QUIT:
quit()
else:
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
myquit()
elif event.key == K_LEFT:
catx-=5
print("Move Rect Left")
elif event.key == K_RIGHT:
catx+=5
print("Move Rect Right")
else:
print(event.key)
screen.fill((0,0,0))
pygame.draw.rect(screen,(255, 255, 255),(catx,50, 50, 10))
pygame.display.update()
def main():
global screen
#initialize game
pygame.init()
SCREEN_WIDTH = 600
SCREEN_HEIGHT = 400
window = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT))
pygame.display.set_caption("SNAKE GAME BY SUBHAM")
screen = pygame.display.get_surface()
pygame.display.update()
while True:
check_inputs(pygame.event.get())
main()