-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathninjarunner.py
63 lines (47 loc) · 1.25 KB
/
ninjarunner.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
import pgzrun
from pgzhelper import *
WIDTH=800
HEIGHT=600
runner = Actor('run__000')
run_images = ['run__000', 'run__001', 'run__002', 'run__003', 'run__004', 'run__005', 'run__006', 'run__007', 'run__008', 'run__009']
runner.images = run_images
runner.x = 100
runner.y = 400
velocity_y = 0
gravity = 1
obstacles = []
obstacles_timeout = 0
game_over = False
def update():
global velocity_y, obstacles_timeout, game_over
runner.next_image()
obstacles_timeout += 1
if obstacles_timeout > 50:
actor = Actor('cactus')
actor.x = 850
actor.y = 430
obstacles.append(actor)
obstacles_timeout = 0
for actor in obstacles:
actor.x -= 8
if actor.x < -50:
obstacles.remove(actor)
if keyboard.up:
velocity_y = -15
runner.y += velocity_y
velocity_y += gravity
if runner.y > 400:
velocity_y = 0
runner.y = 400
if runner.collidelist(obstacles) != -1:
game_over = True
def draw():
screen.draw.filled_rect(Rect(0,0,800,400), (163, 232, 254))
screen.draw.filled_rect(Rect(0,400,800,200), (88, 242, 152))
if game_over:
screen.draw.text('Game Over', centerx=400, centery=270, color=(255,255,255), fontsize=60)
else:
runner.draw()
for actor in obstacles:
actor.draw()
pgzrun.go() # Must be last line