-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworld.py
178 lines (166 loc) · 5.63 KB
/
world.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import random
import logic
from actors import *
from ui import Scoreboard
class World:
def __init__(self, graphics, player):
self.graphics = graphics;
self.player = player
self.enemies = {}
self.spawn_timer = 50
def update(self, delta):
# Generate new enemies
self.spawn_timer -= delta
if self.spawn_timer <= 0:
self.spawn_timer = random.randint(800, 1200)
# Chance for a new enemy
self.add_enemy(self.__get_random_shape(), self.__get_random_size(), self.__get_random_rot(), self.__get_random_color(),
self.__get_random_pos())
self.player.size_change = True #missuse of this variable, but we need to update the image to reflect if you can use it
def create_shape(self, shape_type, size, rotation, color):
if shape_type == "hexagon":
return Hexagon(size, rotation, color)
elif shape_type == "octagon":
return Octagon(size, rotation, color)
elif shape_type == "pentagon":
return Pentagon(size, rotation, color)
elif shape_type == "square":
return Square(size, rotation, color)
else: #tri
return Tri(size, rotation, color)
def add_enemy(self, shape_type, size, rotation, color, pos = (0,0)):
shape = self.create_shape(shape_type, size, rotation, color)
shape.rect.move_ip(pos)
self.enemies[shape.id] = shape
self.graphics.add_enemy_shape(shape)
shape.randirx = random.choice([-10, -6, -4, -4, -2, -2,-1,-1, 0, 0, 0, 1, 1, 2, 2, 4, 4, 6, 10])
shape.randiry = random.choice([-10, -6, -4, -4, -2, -2,-1,-1, 0, 0, 0, 1, 1, 2, 2, 4, 4, 6, 10])
def add_enemy_shape(self, shape):
self.enemies[shape.id] = shape
shape.randirx = random.choice([-10, -6, -4, -4, -2, -2,-1,-1, 0, 0, 0, 1, 1, 2, 2, 4, 4, 6, 10])
shape.randiry = random.choice([-10, -6, -4, -4, -2, -2,-1,-1, 0, 0, 0, 1, 1, 2, 2, 4, 4, 6, 10])
def remove_enemy(self, shapeid):
if shapeid in self.enemies:
self.graphics.remove_enemy_shape(self.enemies[shapeid])
del self.enemies[shapeid]
def __get_random_color(self):
x = random.randint(0, 3)
if x == 0:
return "yellow"
elif x == 1:
return "white"
elif x == 2:
return "green"
else:
return "purple"
def __get_random_shape(self):
x = random.randint(0, 4)
if x == 0:
return "hexagon"
elif x == 1:
return "octagon"
elif x == 2:
return "pentagon"
elif x == 3:
return "square"
else:
return "tri"
def __get_random_size(self):
if self.player.total_size < 32:
x = random.randint(0, 4)
if x == 0:
return 20
elif x == 1:
return 20
elif x == 2:
return 20
elif x == 3:
return 40
else:
return 70
elif self.player.total_size < 40:
x = random.randint(0, 4)
if x == 0:
return 20
elif x == 1:
return 20
elif x == 2:
return 40
elif x == 3:
return 70
else:
return 95
elif self.player.total_size < 70:
x = random.randint(0, 5)
if x == 0:
return 20
elif x == 1:
return 40
elif x == 2:
return 40
elif x == 3:
return 70
elif x == 4:
return 95
else:
return 128
elif self.player.total_size < 95:
x = random.randint(0, 4)
if x == 0:
return 40
elif x == 1:
return 70
elif x == 2:
return 70
elif x == 3:
return 95
else:
return 128
elif self.player.total_size < 128:
x = random.randint(0, 5)
if x == 0:
return 40
elif x == 1:
return 70
elif x == 2:
return 70
elif x == 3:
return 95
elif x == 4:
return 95
else:
return 128
elif self.player.total_size > 128:
x = random.randint(0, 3)
if x == 0:
return 70
elif x == 1:
return 90
elif x == 2:
return 128
else:
return 128
def __get_random_rot(self):
x = random.randint(0, 6)
if x == 0:
return 0
elif x == 1:
return 40
elif x == 2:
return 70
elif x == 3:
return 150
elif x == 4:
return 220
elif x == 5:
return 270
else:
return 310
def __get_random_pos(self):
r = random.randint(0, 6)
x = 0
y = 0
while (x == 0 or (x < 640 and x > 384)) and (y == 0 or (y < 512 and y > 256)):
x = random.randint(-100, 1024+100)
y = random.randint(-100, 768+100)
return (x,y)