/
planet.py
228 lines (180 loc) · 7.19 KB
/
planet.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
import movement
import entities
import display
import sprites
import numbers
import effects
import player
import events
import worlds
import ships
import clock
import items
import maps
import random
LEVEL = 1
WAVE = 1
NOTERIETY = 0
TRANSITION_PAUSE = 0
CHANGE_WAVE = False
CHANGE_WAVE_FIRE = False
ANNOUNCE = True
WAVE_TIMER_MAX = 30*45
WAVE_TIMER = 240
def create():
global WAVE_TIMER_MAX, WAVE_TIMER, WAVE, LEVEL
LEVEL = 2
WAVE = 1
WAVE_TIMER = 240
WAVE_TIMER_MAX = 30*45
worlds.create('planet', width=12000, height=12000)
events.register_event('tick', tick)
create_player()
display.clear_grid()
create_planet()
def clean():
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(x=0, y=0):
_player = ships.create_energy_ship(x=x, y=y)
_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'], min_zoom=5, max_zoom=14, max_enemy_distance=10000, center_distance=5000)
entities.register_event(_player, 'delete', player.delete)
entities.register_event(_player, 'hit_edge', lambda entity: entities.trigger_event(entity, 'hit', damage=100))
entities.trigger_event(_player, 'push', velocity=(30, 30))
def create_planet():
for entity_id in entities.get_sprite_groups(['items', 'planets']):
entities.delete_entity(entities.ENTITIES[entity_id])
if LEVEL == 1:
_planet = entities.create_entity(group='planets')
sprites.register_entity(_planet, 'effects_foreground', 'planet.png', scale=1.0)
movement.register_entity(_planet, x=worlds.get_size()[0]/2, y=worlds.get_size()[1]/2, speed=0)
effects.create_image(_planet['position'][0], _planet['position'][1], 'ring.png', background=2, scale=2, parent_entity=_planet)
items.create_gravity_well(x=worlds.get_size()[0]/2, y=worlds.get_size()[1]/2, strength=0.25)
elif LEVEL == 2:
ships.create_ivan_large(x=worlds.get_size()[0]/2, y=worlds.get_size()[1]/2)
items.create_gravity_well(x=worlds.get_size()[0]/2, y=worlds.get_size()[1]/2, min_distance=1000, kill_engines=False, strength=0.75)
return True
def spawn_enemies():
global TRANSITION_PAUSE, CHANGE_WAVE_FIRE, CHANGE_WAVE, ANNOUNCE, WAVE
_i = random.choice([0, 1, 2, 3])
if WAVE == 3:
TRANSITION_PAUSE = 30*30
CHANGE_WAVE = True
CHANGE_WAVE_FIRE = False
return False
if LEVEL == 2:
return False
if _i == 1:
_xrange = random.choice([(100, worlds.get_size()[0]*.25),
(worlds.get_size()[0]*.25, worlds.get_size()[0]*.5),
(worlds.get_size()[0]*.5, worlds.get_size()[0]*.75),
(worlds.get_size()[0]*.75, worlds.get_size()[0]-100)])
_y = 100
elif _i == 2:
_x = worlds.get_size()[0]-100
_y = random.choice([(100, worlds.get_size()[1]*.25),
(worlds.get_size()[1]*.25, worlds.get_size()[1]*.5),
(worlds.get_size()[1]*.5, worlds.get_size()[1]*.75),
(worlds.get_size()[1]*.75, worlds.get_size()[1]-100)])
elif _i == 3:
_x = 100
_y = random.randint(100, worlds.get_size()[1]-100)
else:
_x = random.randint(100, worlds.get_size()[0]-100)
_y = worlds.get_size()[1]-100
_missile_turrets = int(round(10*((WAVE+1)/5.0)))
_gun_turrets = int(round(10*(WAVE/5.0)))
_fleas = int(round(5*(WAVE/5.0)))
for i in range(_fleas):
if _i == 1:
_x = random.randint(100, worlds.get_size()[0]-100)
_y = 100
elif _i == 2:
_x = worlds.get_size()[0]-100
_y = random.randint(100, worlds.get_size()[1]-100)
elif _i == 3:
_x = 100
_y = random.randint(100, worlds.get_size()[1]-100)
else:
_x = random.randint(100, worlds.get_size()[0]-100)
_y = worlds.get_size()[1]-100
_entity = ships.create_flea(x=_x, y=_y, hazard=True)
_move_direction = numbers.direction_to((_x, _y,), (worlds.get_size()[0]/2, worlds.get_size()[1]/2))
entities.trigger_event(_entity, 'push', velocity=numbers.velocity(_move_direction, 20))
for i in range(_gun_turrets):
if _i == 1:
_x = random.randint(200, worlds.get_size()[0]-200)
_y = 200
elif _i == 2:
_x = worlds.get_size()[0]-200
_y = random.randint(200, worlds.get_size()[1]-200)
elif _i == 3:
_x = 200
_y = random.randint(200, worlds.get_size()[1]-200)
else:
_x = random.randint(200, worlds.get_size()[0]-200)
_y = worlds.get_size()[1]-200
_entity = ships.create_gun_turret(x=_x, y=_y)
_move_direction = numbers.direction_to((_x, _y,), (worlds.get_size()[0]/2, worlds.get_size()[1]/2))
entities.trigger_event(_entity, 'push', velocity=numbers.velocity(_move_direction, 20))
for i in range(_missile_turrets):
if _i == 1:
_x = random.randint(100, worlds.get_size()[0]-100)
_y = 100
elif _i == 2:
_x = worlds.get_size()[0]-100
_y = random.randint(100, worlds.get_size()[1]-100)
elif _i == 3:
_x = 100
_y = random.randint(100, worlds.get_size()[1]-100)
else:
_x = random.randint(100, worlds.get_size()[0]-100)
_y = worlds.get_size()[1]-100
_entity = ships.create_missile_turret(x=_x, y=_y)
_move_direction = numbers.direction_to((_x, _y,), (worlds.get_size()[0]/2, worlds.get_size()[1]/2))
entities.trigger_event(_entity, 'push', velocity=numbers.velocity(_move_direction, 20))
WAVE += 1
ANNOUNCE = True
def tick():
global WAVE_TIMER
if WAVE_TIMER:
WAVE_TIMER -= 1
def loop():
global CHANGE_WAVE_FIRE, TRANSITION_PAUSE, CHANGE_WAVE, WAVE_TIMER, LEVEL, WAVE
if TRANSITION_PAUSE and CHANGE_WAVE:
_player = entities.get_entity(entities.get_entity_group('players')[0])
if not CHANGE_WAVE_FIRE:
entities.trigger_event(_player,
'create_timer',
time=120,
enter_callback=lambda entity: events.unregister_event('input', player.handle_input),
callback=lambda entity: entities.trigger_event(entity, 'push', velocity=(6, 6)),
exit_callback=lambda entity: display.camera_snap((-4000, -4000)) and entities.trigger_event(entity, 'set_position', x=-4000, y=-4000) and events.register_event('input', player.handle_input, _player['_id']) and create_planet())
LEVEL += 1
_player['NO_BOUNCE'] = True
CHANGE_WAVE_FIRE = True
if TRANSITION_PAUSE:
TRANSITION_PAUSE -= 1
return False
if CHANGE_WAVE:
WAVE = 1
CHANGE_WAVE = False
if not entities.get_entity_group('enemies') and not entities.get_entity_group('hazards') and WAVE_TIMER:
WAVE_TIMER -= 4
if entities.get_entity_group('players') and WAVE_TIMER<=0 or (LEVEL == 2 and not entities.get_entity_group('enemies')):
spawn_enemies()
WAVE_TIMER = WAVE_TIMER_MAX+(60*WAVE)