-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanPlay.py
More file actions
58 lines (45 loc) · 1.77 KB
/
Copy pathHumanPlay.py
File metadata and controls
58 lines (45 loc) · 1.77 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
import time
import pygame
import resources.GameUtils as GameUtils
def game_loop():
pygame.init()
GameUtils.gameDisplay, GameUtils.traffic_images, GameUtils.car_image = GameUtils.initialize_resources()
high_score = 0
while True:
car, traffic_objects = GameUtils.initialize_traffic()
dodged = 0
while True:
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
car.go_left()
if keys[pygame.K_RIGHT]:
car.go_right()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
GameUtils.gameDisplay.fill(GameUtils.black)
traffic_objects.lines += car.speed + 15
GameUtils.draw_traffic(traffic_objects.x, traffic_objects.y, traffic_objects.lines, traffic_objects.curr_vehicle)
traffic_objects.y += car.speed
GameUtils.display_car(car.x, car.y)
GameUtils.display_score(dodged)
GameUtils.display_high_score(high_score)
if traffic_objects.y > GameUtils.display_height:
traffic_objects.update_state()
dodged += 1
car.speed += 0.15
if traffic_objects.lines > 0:
traffic_objects.lines = -GameUtils.display_height
if car.crashed(traffic_objects):
GameUtils.message_display("CRASH")
if dodged > high_score:
high_score = dodged
time.sleep(1)
break
pygame.display.update()
if __name__ == '__main__':
GameUtils.RENDER = True
game_loop()
pygame.quit()
quit()