-
Notifications
You must be signed in to change notification settings - Fork 0
/
battlefield.py
233 lines (184 loc) · 7.79 KB
/
battlefield.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import entities
import progress
import display
import player
import events
import worlds
import ships
import clock
import random
LEVEL = 1
NOTERIETY = 0
TRANSITION_PAUSE = 0
ANNOUNCE = True
def boot():
display.create_sprite_group('effects_background_bottom')
display.create_sprite_group('effects_background')
display.create_sprite_group('items')
display.create_sprite_group('ships')
display.create_sprite_group('effects_foreground')
display.create_text_group('bot_center')
entities.create_entity_group('items')
entities.create_entity_group('players')
entities.create_entity_group('enemies')
entities.create_entity_group('hazards')
entities.create_entity_group('effects')
entities.create_entity_group('bullets')
entities.create_entity_group('weapons')
entities.create_entity_group('planets')
entities.create_entity_group('cursor')
entities.create_entity_group('tiles_foreground')
display.create_sprite_group('tiles_foreground')
display.create_sprite_group('ui_foreground')
def clean():
global LEVEL
LEVEL = 1
for ship_id in entities.get_entity_group('players'):
entities.delete_entity(entities.ENTITIES[ship_id])
for ship_id in entities.get_entity_group('enemies'):
entities.delete_entity(entities.ENTITIES[ship_id])
for ship_id in entities.get_entity_group('hazards'):
entities.delete_entity(entities.ENTITIES[ship_id])
for ship_id in entities.get_entity_group('effects'):
entities.delete_entity(entities.ENTITIES[ship_id])
for ship_id in entities.get_entity_group('bullets'):
entities.delete_entity(entities.ENTITIES[ship_id])
for ship_id in entities.get_entity_group('weapons'):
entities.delete_entity(entities.ENTITIES[ship_id])
entities.reset()
def create(player=True):
global LEVEL
if player:
create_player()
LEVEL = 1
else:
LEVEL = 3
spawn_enemies()
def create_player():
_player = ships.create_energy_ship()
_player['player'] = True
player.register_entity(_player)
events.register_event('input', player.handle_input, _player['_id'])
events.register_event('camera', player.handle_camera, _player['_id'])
entities.register_event(_player, 'score', player.score)
entities.register_event(_player, 'delete', player.delete)
entities.register_event(_player, 'kill', lambda entity: events.unregister_event('input', player.handle_input))
entities.register_event(_player, 'kill', lambda entity: display.print_text(display.get_window_size()[0]/2,
display.get_window_size()[1]*.75,
'Awarded medal:',
color=(255, 0, 0, 50),
font_size=18,
show_for=3.5,
fade_in_speed=6,
center=True))
def spawn_enemies():
global TRANSITION_PAUSE, ANNOUNCE, LEVEL
if LEVEL == 5:
_boss = ships.create_ivan(x=random.randint(0, worlds.get_size()[0]), y=random.randint(0, worlds.get_size()[1]))
_details = ['<b>Stolovitzky, Ivan</b>',
'<i>Suicidal maniac</i>',
'Wanted for: <b>Intergalactic Manslaughter</b>']
display.camera_zoom(1.5)
display.camera_focus_on(_boss['position'])
display.clear_text_group('bot_center')
display.print_text(display.get_window_size()[0]/2,
display.get_window_size()[1]*.75,
'CRAZY IVAN',
font_size=42,
text_group='bot_center',
center=True,
color=(0, 240, 0, 50),
fade_in_speed=24,
show_for=3)
_i = 0
for detail_text in _details:
display.print_text(display.get_window_size()[0]*.6,
display.get_window_size()[1]*.65-(24*_i),
detail_text,
font_size=20,
text_group='bot_center',
color=(240, 240, 240, 0),
fade_in_speed=(len(_details)-_i)*2,
show_for=3)
_i += 1
clock.hang_for(180)
entities.register_event(_boss, 'kill', lambda entity: progress.unlock_chaingun())
TRANSITION_PAUSE = 240
ANNOUNCE = True
LEVEL += 1
return False
if not LEVEL % 4:
for i in range(1*(LEVEL-1)):
ships.create_flea(x=random.randint(0, worlds.get_size()[0]), y=random.randint(0, worlds.get_size()[1]))
TRANSITION_PAUSE = 120
ANNOUNCE = True
LEVEL += 1
return False
for i in range(1*(LEVEL-1)):
ships.create_flea(x=random.randint(0, worlds.get_size()[0]), y=random.randint(0, worlds.get_size()[1]))
_eyemine_spawn_point = (random.randint(worlds.get_size()[0]*.25, worlds.get_size()[0]*.75),
random.randint(worlds.get_size()[1]*.25, worlds.get_size()[1]*.75))
for i in range(random.randint(2, 4)*LEVEL):
_rand_distance = 350+(120*LEVEL)
_x_mod = random.randint(-_rand_distance, _rand_distance)
_y_mod = random.randint(-_rand_distance, _rand_distance)
ships.create_eyemine(x=_eyemine_spawn_point[0]+_x_mod, y=_eyemine_spawn_point[1]+_y_mod)
_move = random.randint(0, 1)
if _move:
_move_direction = random.randint(0, 359)
for i in range(random.randint(1, 2)*LEVEL):
_x, _y = random.randint(worlds.get_size()[0]*.25, worlds.get_size()[0]*.75), random.randint(worlds.get_size()[1]*.25, worlds.get_size()[1]*.75)
_turret = ships.create_missile_turret(x=_x, y=_y)
if _move:
entities.trigger_event(_turret, 'set_direction', direction=_move_direction)
entities.trigger_event(_turret, 'set_minimum_velocity', velocity=[-5, -5])
entities.trigger_event(_turret, 'set_maximum_velocity', velocity=[5, 5])
entities.trigger_event(_turret, 'thrust')
if LEVEL >= 3:
for i in range(random.randint(1, 2)*(int(round(LEVEL*.25)))):
_x, _y = random.randint(worlds.get_size()[0]*.25, worlds.get_size()[0]*.75), random.randint(worlds.get_size()[1]*.25, worlds.get_size()[1]*.75)
_turret = ships.create_gun_turret(x=_x, y=_y)
if _move:
entities.trigger_event(_turret, 'set_direction', direction=_move_direction)
entities.trigger_event(_turret, 'set_minimum_velocity', velocity=[-5, -5])
entities.trigger_event(_turret, 'set_maximum_velocity', velocity=[5, 5])
entities.trigger_event(_turret, 'thrust')
if 1*(LEVEL-1):
display.clear_text_group('bot_center')
display.print_text(display.get_window_size()[0]/2,
display.get_window_size()[1]*.95,
'ENEMY FIGHTERS INBOUND',
color=(0, 240, 0, 255),
text_group='bot_center',
show_for=1.5,
center=True)
LEVEL += 1
ANNOUNCE = True
TRANSITION_PAUSE = 120
def loop():
global TRANSITION_PAUSE, ANNOUNCE, NOTERIETY
if entities.get_entity_group('players') and not entities.get_entity_group('enemies') and not entities.get_entity_group('hazards'):
if TRANSITION_PAUSE:
if ANNOUNCE:
ANNOUNCE = False
display.print_text(display.get_window_size()[0]/2,
display.get_window_size()[1]*.95,
'WAVE CLEARED',
color=(200, 200, 200, 255),
text_group='bot_center',
show_for=2,
center=True)
TRANSITION_PAUSE -= 1
return False
NOTERIETY += LEVEL
spawn_enemies()
def loop_attract():
global TRANSITION_PAUSE, LEVEL
if not entities.get_entity_group('enemies') or not entities.get_entity_group('hazards'):
if TRANSITION_PAUSE:
TRANSITION_PAUSE -= 1
else:
TRANSITION_PAUSE = 80
clean()
LEVEL = 3
spawn_enemies()