-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
127 lines (97 loc) · 3.04 KB
/
main.py
File metadata and controls
127 lines (97 loc) · 3.04 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/python3
# Import library code
from p5 import *
from random import randint, seed
level = 1
score = 0
lives = 3
invun = 0
# The draw_obstacle function goes here
def draw_obstacles():
global level
seed(random_seed)
if frame_count % height == height - 1 and level < 8:
level += 1
print('You reached level', level)
for i in range(6 + level):
ob_x = randint(0, width)
ob_y = randint(0, height) + (frame_count * level)
ob_y %= height # wrap around
push_matrix()
translate(ob_x, ob_y)
rotate(degrees(randint(1, 359)+frame_count / 1000))
image(rock, 0, 0, randint(18,24), randint(18,24))
pop_matrix()
# The draw_player function goes here
def draw_player():
global score, level, lives, invun
player_y = int(height * 0.8)
player_x = mouse_x
collide = get(player_x, player_y).hex
collide2 = get(player_x - 18, player_y + 17).hex
collide3 = get(player_x + 18, player_y + 17).hex
collide4 = get(player_x, player_y + 25).hex
if player_x < width: # off the left of the screen
collide2 = safe.hex
if player_x > width: # off the right of the screen
collide3 = safe.hex
if (collide == safe.hex and collide2 == safe.hex and collide3 == safe.hex and collide4 == safe.hex) or invun > 0:
if lives == 0 and frame_count % 12 == 0:
tint(200, 0, 0)
image(rocket, player_x, player_y + 25, 64, 64)
score += level
invun -= 1
no_tint()
if invun > 0:
stroke(220)
fill(220, 220, 220, 60)
ellipse(player_x, player_y + 18, 47, 47)
elif lives > 1:
lives -= 1
invun = 50
tint(200, 0, 0)
image(rocket, player_x, player_y + 25, 64, 64)
no_tint()
score += level
else:
text('💥', player_x + 10, player_y + 5)
level = 0
def display_score():
global level
fill(255)
text_size(16)
text_align(RIGHT, TOP)
text('Score', width * 0.45, 10, width * 0.5, 20)
text(str(score), width * 0.45, 25, width * 0.5, 20)
if score > 10000:
level = 0
print('🎉🎉 You win! 🎉🎉')
def display_lives():
fill(255)
text_size(16)
text_align(LEFT, TOP)
text('Lives', width * 0.05, 10, 30, 20)
for i in range(lives):
image(rocket, width * 0.05 + i * 25, 40, 20, 20)
def setup():
# Setup your animation here
size(400, 400)
global rocket, rock, random_seed
text_size(40)
text_align(CENTER, TOP) # position around the centre, top
rocket = load_image('rocket.png')
rock = load_image('moon.png')
random_seed = randint(0, 1000000)
def draw():
# Things to do in every frame
global score, safe, level
safe = Color(0)
if level > 0:
background(safe)
fill(255)
image_mode(CENTER)
draw_obstacles()
draw_player()
display_score()
display_lives()
run()