-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
68 lines (56 loc) · 1.51 KB
/
main.py
File metadata and controls
68 lines (56 loc) · 1.51 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import pygame
import random
import colours
import snake
import block
pygame.init()
FRAMEX = 500
FRAMEY = 500
BOUNDSX = 500
BOUNDSY = 500
FPS = 20
pastSize = 0
gameDisplay = pygame.display.set_mode((FRAMEX, FRAMEY))
clock = pygame.time.Clock()
snakey = snake.Snake([250, 450], 10, colours.blue, colours.black, pygame, gameDisplay)
apple = block.Block([BOUNDSX/2, BOUNDSY/2], colours.red, pygame, gameDisplay, 10)
def clear() :
gameDisplay.fill(colours.white)
def update() :
global FPS
global pastSize
snakey.move()
if snakey.head.getCoordinates() == apple.getCoordinates() :
snakey.needsGrowth = True
newX = random.randint(0, (FRAMEX-10)/10) * 10
newY = random.randint(0, (FRAMEY-10)/10) * 10
apple.x = newX
apple.y = newY
else :
if not snakey.badMove(BOUNDSX, BOUNDSY) :
pygame.quit()
quit()
apple.draw()
snakey.turnedThisTurn = False
if (snakey.size != pastSize) :
pastSize = snakey.size
if (snakey.size%10 == 0) and (snakey.size != 0) :
FPS += 1
pygame.display.set_caption("Pyhton in Python - " + str(snakey.size))
def render() :
pygame.display.update()
def eventHandler() :
for event in pygame.event.get() :
if event.type == pygame.QUIT :
pygame.quit()
quit()
elif event.type == pygame.KEYDOWN :
snakey.dirChange(event)
while True :
clear()
eventHandler()
update()
render()
clock.tick(FPS)
pygame.quit()
quit()