-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
87 lines (56 loc) · 2.11 KB
/
game.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import pygame, sys
import myInputs, movement, settings
pygame.init()
size = width, height = 640, 640
speed = [settings.scalar_speed, 0]
black = 0, 0, 0
max_render_time = settings.max_render_time
images_folder = "./images/"
screen = pygame.display.set_mode(size)
head = pygame.image.load(images_folder + "right_head.png")
body = pygame.image.load(images_folder + "right_body.png")
headrect = head.get_rect()
bodyrect = body.get_rect()
bodyrect.centerx = headrect.centerx - 100
bodyrect.centery = headrect.centery
ghost = head.get_rect()
bodyGhost = body.get_rect()
lastDrawTime = 0
justJumped = 0
bodyJustJumped = 0
turningPoints = list()
oldspeed = list()
while True:
newSpeed = myInputs.getDirection()
if newSpeed:
if newSpeed != speed:
turningPoints.append(headrect.center)
imagePrefix = movement.getFacing(newSpeed)
head = pygame.image.load(images_folder + imagePrefix.lower() + "_head.png")
oldspeed.append(speed)
speed = newSpeed
elapsed = pygame.time.get_ticks()-lastDrawTime
if elapsed < max_render_time:
pygame.time.wait(max_render_time-elapsed)
headrect = headrect.move(speed)
try:
if len(turningPoints) == 0:
bodyrect = bodyrect.move(speed)
else:
bodyrect = bodyrect.move(oldspeed[0])
turningPoints, oldspeed = movement.checkTurn(bodyrect.centerx,bodyrect.centery, turningPoints,oldspeed)
except:
bodyrect = bodyrect.move(speed)
ghost,justJumped = movement.edges(width,height,headrect,ghost,justJumped)
bodyGhost,bodyJustJumped = movement.edges(width,height,bodyrect,bodyGhost,bodyJustJumped)
screen.fill(black)
screen.blit(head, headrect)
screen.blit(body, bodyrect)
if justJumped > 0 :
screen.blit(head,ghost)
ghost = ghost.move(speed)
if bodyJustJumped > 0 :
screen.blit(body,bodyGhost)
bodyGhost = bodyGhost.move(speed)
pygame.display.flip()
lastDrawTime = pygame.time.get_ticks()