Пример #1
0
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)
Пример #2
0
def destroy(entity):
	entity['hp'] = 0
	
	if entity['death_timer'] == -1:
		entity['death_timer'] = entity['death_timer_max']
	
	if entity['death_timer']:
		entity['death_timer'] -= 1
	else:
		entities.trigger_event(entity, 'explode')
		_effect = effects.create_particle(entity['position'][0]+random.randint(-20, 20),
		                                  entity['position'][1]+random.randint(-20, 20),
		                                  'shockwave.png',
		                                  background=True,
		                                  scale=0,
		                                  scale_min=-.1,
		                                  scale_max=8,
		                                  scale_rate=1.1)
		entities.delete_entity(entity)
	
	if random.randint(0, 3):
		_effect = effects.create_particle(entity['position'][0]+random.randint(-20, 20),
		                                  entity['position'][1]+random.randint(-20, 20),
		                                  'explosion.png',
		                                  background=False,
		                                  scale=random.uniform(.5, 1.3),
		                                  flashes=random.randint(10, 15),
		                                  flash_chance=0.85,
		                                  direction=entity['direction']+random.randint(-90, 90),
		                                  speed=entity['current_speed']*.9)
Пример #3
0
def tick_track(entity):
	#_target_id = find_target(entity)
	_target_id = entity['current_target']
	
	if 'in_space' in entity and entity['in_space']:
		return False
	
	if entity['hp']<=0 or not _target_id in entities.ENTITIES:
		entity['current_target'] = None
		entities.unregister_event(entity, 'tick', tick_track)
		
		return False
	
	if not _target_id:
		entities.trigger_event(entity, 'accelerate', velocity=(0, 0))
		
		return False
	
	_target = entities.get_entity(_target_id)
	_direction_to = numbers.direction_to(entity['position'], _target['position'])
	_degrees_to = abs(entity['direction']-_direction_to)
	
	if _degrees_to>=180:
		_direction_to += 360
	
	_new_direction = numbers.interp(entity['direction'], _direction_to, entity['turn_rate'])
	_direction_difference = abs(entity['direction']-_new_direction)
	entity['direction'] = _new_direction
	entities.trigger_event(entity, 'thrust')
Пример #4
0
def tick_track(entity):
    #_target_id = find_target(entity)
    _target_id = entity['current_target']

    if 'in_space' in entity and entity['in_space']:
        return False

    if entity['hp'] <= 0 or not _target_id in entities.ENTITIES:
        entity['current_target'] = None
        entities.unregister_event(entity, 'tick', tick_track)

        return False

    if not _target_id:
        entities.trigger_event(entity, 'accelerate', velocity=(0, 0))

        return False

    _target = entities.get_entity(_target_id)
    _direction_to = numbers.direction_to(entity['position'],
                                         _target['position'])
    _degrees_to = abs(entity['direction'] - _direction_to)

    if _degrees_to >= 180:
        _direction_to += 360

    _new_direction = numbers.interp(entity['direction'], _direction_to,
                                    entity['turn_rate'])
    _direction_difference = abs(entity['direction'] - _new_direction)
    entity['direction'] = _new_direction
    entities.trigger_event(entity, 'thrust')
Пример #5
0
def tick(entity):
	entity['recoil_time'] -= 1
	
	if not entity['owner_id'] in entities.ENTITIES:
		entities.unregister_event(entity, 'tick', tick)
		
		return False
	
	if entity['recoil_time']>0:
		return False
	elif not entity['rounds']:
		if entity['reload_time']:
			if entity['owner_id'] in entities.ENTITIES and 'player' in entities.get_entity(entity['owner_id']) and entity['reload_time'] == entity['reload_time_max']:
				display.print_text(0, 0, 'RELOADING', show_for=(entity['reload_time']/display.get_tps())*2, fade_out_speed=255)
				
			entity['reload_time'] -= 1
		else:
			entity['reload_time'] = entity['reload_time_max']
			entity['recoil_time'] = 1
			entity['rounds'] = entity['max_rounds']
			entity['firing'] = False
			entities.unregister_event(entity, 'tick', tick)
		
		return False
	
	_owner = entities.get_entity(entity['owner_id'])
	
	if 'shoot_direction' in entity:
		_direction = entity['shoot_direction']
	elif 'shoot_direction' in _owner:
		_direction = _owner['shoot_direction']
	else:
		_direction = _owner['direction']
	
	if entity['kickback']:
		entities.trigger_event(entities.get_entity(entity['owner_id']), 'push', velocity=numbers.velocity(_direction+180, entity['kickback']))
	
	if entity['missile']:
		bullet.create_missile(_owner['position'][0],
		                      _owner['position'][1],
		                      _direction,
		                      entity['speed'],
		                      'bullet.png',
		                      entity['owner_id'],
		                      turn_rate=entity['turn_rate'],
		                      tracking=entity['tracking'],
		                      radius=entity['damage_radius'])
	
	if entity['bullet']:
		bullet.create_bullet(_owner['position'][0],
		                     _owner['position'][1],
		                     _direction+random.randint(-entity['spray'], entity['spray']),
		                     entity['speed'],
		                     'bullet.png',
		                     entity['owner_id'],
		                     scale=.6,
		                     radius=entity['damage_radius'])
	
	entity['recoil_time'] = entity['recoil_time_max']
	entity['rounds'] -= 1
Пример #6
0
def create_laser(x, y, direction, owner_id, damage=12, length=20):
	_vel = numbers.velocity(direction, length)
	
	for i in range(length):
		_vel = numbers.velocity(direction, 3*(length*i))
		_bullet = create(x+_vel[0], y+_vel[1], direction, 0, 'laser.png', owner_id, damage=damage, life=10)
		entities.trigger_event(_bullet, 'set_rotation', degrees=direction)
		entities.register_event(_bullet, 'hit', hit_laser)
Пример #7
0
def tick(entity):
	if entity['hp']<=0:
		if not '_dead' in entity:
			entities.trigger_event(entity, 'kill')
			
			entity['_dead'] = True
		
		entities.trigger_event(entity, 'dying')
Пример #8
0
def tick_particle(particle):
	if particle['spin']:
		entities.trigger_event(particle, 'rotate_by', degrees=particle['spin'])
	
	if particle['fade_rate']:
		entities.trigger_event(particle, 'fade_by', amount=particle['fade_rate'])
	
	particle['sprite'].visible = True
	
	if particle['swerve_rate']:
		particle['direction'] += (random.randint(int(round(particle['swerve_rate']*.25)), particle['swerve_rate'])*particle['swerve_speed']/float(particle['swerve_speed_max']))*random.choice([-1, 1])
		particle['velocity'] = numbers.velocity(particle['direction'], particle['swerve_speed'])
		particle['swerve_speed'] -= 1
		
		if particle['swerve_speed']<=0:
			entities.delete_entity(particle)
				
			return False
	
	if particle['flashes']>-1:
		if random.uniform(0, 1)>1-particle['flash_chance']:
			particle['sprite'].visible = False
			particle['flashes'] -= 1
		
			if not particle['flashes']:
				entities.delete_entity(particle)
				
				return False
	
	if particle['streamer'] and random.uniform(0, 1)>1-particle['streamer_chance']:
		if particle['swerve_rate']:
			_image = 'streamer.png'
		else:
			_image = particle['sprite_name']
		
		_effect = create_particle(particle['position'][0],
		                          particle['position'][1],
		                          _image,
		                          background=particle['background'],
		                          direction=particle['direction'],
		                          rotation=particle['direction'],
		                          scale=particle['sprite'].scale,
		                          scale_min=particle['scale_min'],
		                          scale_rate=particle['scale_rate'])
		
		if particle['swerve_rate']:
			entities.trigger_event(_effect, 'set_rotation', degrees=particle['direction'])
			entities.trigger_event(_effect, 'set_scale', scale=particle['swerve_speed']/float(particle['swerve_speed_max']))
			_effect['sprite'].opacity = 255*particle['swerve_speed']/float(particle['swerve_speed_max'])
	
	if not particle['scale_rate'] == 1:
		if particle['sprite'].scale < particle['scale_min']:
			entities.delete_entity(particle)
		elif particle['sprite'].scale > particle['scale_max']:
			entities.delete_entity(particle)
		else:
			entities.trigger_event(particle, 'set_scale', scale=particle['sprite'].scale*particle['scale_rate'])
Пример #9
0
def flag_sub(entity, flag, value):
    entity['flags'][flag]['last_value'] = entity['flags'][flag]['value']
    entity['flags'][flag]['value'] -= value

    entities.trigger_event(entity,
                           'flag_changed',
                           flag=flag,
                           value=entity['flags'][flag]['value'],
                           last_value=entity['flags'][flag]['last_value'])
Пример #10
0
def flag_sub(entity, flag, value):
	entity['flags'][flag]['last_value'] = entity['flags'][flag]['value']
	entity['flags'][flag]['value'] -= value
	
	entities.trigger_event(entity,
						   'flag_changed',
						   flag=flag,
						   value=entity['flags'][flag]['value'],
						   last_value=entity['flags'][flag]['last_value'])
Пример #11
0
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))
Пример #12
0
def create_bullet(x, y, direction, speed, sprite_name, owner_id, damage=3, life=3000, scale=.2, radius=50):
	_bullet = create(x, y, direction, speed, sprite_name, owner_id, damage=damage, life=life)
	_owner = entities.get_entity(_bullet['owner_id'])
	_bullet['sprite'].anchor_x = 0
	_bullet['sprite'].anchor_y = sprites.get_size(_bullet['sprite'])[1]/2
	
	entities.trigger_event(_bullet, 'set_scale', scale=scale)
	entities.trigger_event(_bullet, 'set_rotation', degrees=_bullet['direction'])
	
	return _bullet
Пример #13
0
def create_ivan_large(x=0, y=0):
	_entity = create(sprite_name='boss3.png', group='hazards', scale=2.0, x=x, y=y, acceleration=.4, speed=0, max_velocity=0, turn_rate=0.8, death_time=40, hp=1000)
	_entity['current_target'] = None
	_entity['fire_rate'] = 0
	_entity['fire_rate_max'] = 20
	_entity['collision_radius'] = 1000
	_entity['cycle'] = 'shoot'
	_entity['shoot_cycle_max'] = 3
	_entity['shoot_cycle'] = 3
	_entity['spawn_cycle_max'] = 5
	_entity['spawn_cycle'] = 5
	_entity['warmup_cycles'] = 1
	
	_entity['weapon_id'] = weapons.create(_entity['_id'],
	                                      rounds=25,
	                                      recoil_time=1,
	                                      reload_time=30,
	                                      damage_radius=40,
	                                      speed=140,
	                                      missile=False,
	                                      bullet=True)['_id']
	timers.register_entity(_entity)
	effects.create_image(_entity['position'][0],
	                     _entity['position'][1],
	                     'boss3_core.png',
	                     scale=2.0,
	                     parent_entity=_entity,
	                     background=False)
	effects.create_image(_entity['position'][0],
	                     _entity['position'][1],
	                     'boss3_shield1.png',
	                     scale=2.0,
	                     rotate_by=-1,
	                     parent_entity=_entity,
	                     background=False)
	effects.create_image(_entity['position'][0],
	                     _entity['position'][1],
	                     'boss3_shield2.png',
	                     scale=2.0,
	                     rotate_by=0.5,
	                     parent_entity=_entity,
	                     background=False)
	entities.trigger_event(_entity,
	                       'create_timer',
	                       repeat=-1,
	                       time=100,
	                       repeat_callback=lambda entity: entities.trigger_event(_entity, 'shoot'))
	entities.register_event(_entity, 'moved', set_direction)
	entities.register_event(_entity, 'kill', boss_victory)
	entities.register_event(_entity, 'dying', boss_dying)
	entities.register_event(_entity, 'explode', boss_explode)
	entities.register_event(_entity, 'shoot', ivan_cycles)
	
	return _entity
Пример #14
0
def set_flag(entity, flag, value):
	if flag in entity['flags']:
		entities.trigger_event(entity,
		                       'flag_changed',
		                       flag=flag,
		                       value=value,
		                       last_value=entity['flags'][flag]['last_value'])
	
	entity['flags'][flag] = {'value': value,
							 'last_value': value,
							 'start_value': value}
Пример #15
0
def set_flag(entity, flag, value):
    if flag in entity['flags']:
        entities.trigger_event(entity,
                               'flag_changed',
                               flag=flag,
                               value=value,
                               last_value=entity['flags'][flag]['last_value'])

    entity['flags'][flag] = {
        'value': value,
        'last_value': value,
        'start_value': value
    }
Пример #16
0
def tick_track(bullet):
	if bullet['target_id']:
		_target = entities.get_entity(bullet['target_id'])
		_current_direction = bullet['direction']
		_direction_to = numbers.direction_to(bullet['position'], _target['position'])
		_degrees_to = _current_direction-_direction_to
		
		if (_degrees_to > 0 and abs(_degrees_to) <= 180) or (_degrees_to < 0 and abs(_degrees_to) > 180):
			bullet['direction'] -= 12
		elif (_degrees_to > 0 and abs(_degrees_to) > 180) or (_degrees_to < 0 and abs(_degrees_to) <= 180):
			bullet['direction'] += 12
		
		entities.trigger_event(bullet, 'thrust')
Пример #17
0
def create(sprite_name, x=0, y=0, group=None, speed=10, scale=1, turn_rate=0.1, acceleration=0.5, max_velocity=15, death_time=10, hp=10):
	_soldier = entities.create_entity()
	_soldier['hp'] = hp
	_soldier['death_timer'] = -1
	_soldier['death_timer_max'] = death_time
	_soldier['speed'] = speed
	_soldier['turn_rate'] = turn_rate
	_soldier['collision_radius'] = 0
	
	if group:
		entities.add_entity_to_group(group, _soldier)
	else:
		print 'WARNING: Entity has no group!'
	
	movement.register_entity(_soldier, x=x, y=y)
	sprites.register_entity(_soldier, 'ships', sprite_name, scale=scale)
	entities.create_event(_soldier, 'shoot')
	entities.create_event(_soldier, 'shoot_alt')
	entities.create_event(_soldier, 'hit')
	entities.create_event(_soldier, 'kill')
	entities.create_event(_soldier, 'score')
	entities.create_event(_soldier, 'dying')
	entities.create_event(_soldier, 'explode')
	entities.register_event(_soldier, 'tick', tick)
	entities.register_event(_soldier, 'dying', destroy)
	entities.register_event(_soldier, 'explode', explode)
	entities.register_event(_soldier, 'hit', damage)
	entities.trigger_event(_soldier, 'set_minimum_velocity', velocity=[-max_velocity, -max_velocity])
	entities.trigger_event(_soldier, 'set_maximum_velocity', velocity=[max_velocity, max_velocity])
	entities.trigger_event(_soldier, 'set_acceleration', acceleration=acceleration)
	entities.trigger_event(_soldier, 'set_friction', friction=0)
	
	return _soldier
Пример #18
0
def tick_guard(entity):
	if 'in_space' in entity and entity['in_space']:
		return False
	
	if entity['hp']<=0:
		entities.unregister_event(entity, 'tick', tick_guard)
		
		return False
	
	if not entity['current_target']:
		_target_id = find_target(entity, max_distance=350)
		
		if _target_id:
			entities.trigger_event(entity, 'set_direction', direction=numbers.direction_to(entity['position'], entities.get_entity(_target_id)['position']))
			track_target(entity, _target_id)
Пример #19
0
def hit_laser(bullet, target_id):
	for i in range(random.randint(2, 3)):
		_effect = effects.create_particle(bullet['position'][0]+random.randint(-6, 6),
		                                  bullet['position'][1]+random.randint(-6, 6),
		                                  'explosion.png',
		                                  background=False,
		                                  scale=random.uniform(.4, .8),
		                                  flashes=random.randint(15, 25),
		                                  flash_chance=0.7)
		
		_effect['velocity'] = numbers.interp_velocity(bullet['velocity'], entities.get_entity(target_id)['velocity'], .1)
		_effect['velocity'][0] = numbers.clip(_effect['velocity'][0], -6, 6)
		_effect['velocity'][1] = numbers.clip(_effect['velocity'][1], -6, 6)
	
	entities.trigger_event(entities.get_entity(target_id), 'accelerate', velocity=numbers.interp_velocity(entities.get_entity(target_id)['velocity'], bullet['velocity'], .4))
Пример #20
0
def create_eyemine(x=0, y=0, max_explode_velocity=40):
	_entity = create(x=x, y=y, group='hazards', sprite_name='eyemine_body.png', speed=35, acceleration=0.1, max_velocity=35)
	_entity['max_explode_velocity'] = max_explode_velocity
	
	effects.create_image(_entity['position'][0],
	                     _entity['position'][1],
	                     'eyemine_subbody.png',
	                     parent_entity=_entity,
	                     rotate_by=3,
	                     background=True)
	effects.create_image(_entity['position'][0],
	                     _entity['position'][1],
	                     'eyemine_eye1.png',
	                     parent_entity=_entity,
	                     background=False)
	effects.create_image(_entity['position'][0],
	                     _entity['position'][1],
	                     'eyemine_eye2.png',
	                     parent_entity=_entity,
	                     rotate_with_parent=True,
	                     background=False)
	entities.register_event(_entity, 'tick', tick_eyemine)
	entities.register_event(_entity,
	                        'hit',
	                        lambda _entity, target_id, **kwargs: target_id in entities.ENTITIES and entities.trigger_event(_entity,
	                                                                                                                       'set_direction',
	                                                                                                                       direction=numbers.direction_to(_entity['position'],
	                                                                                                                                                      entities.get_entity(target_id)['position'])))
	entities.register_event(_entity, 'hit', lambda _entity, target_id, **kwargs: ai.track_target(_entity, target_id))
	entities.register_event(_entity, 'hit_edge', lambda entity: entities.trigger_event(entity, 'kill'))
	ai.guard(_entity)
	
	return _entity
Пример #21
0
def create_flea(x=0, y=0, hazard=False):
	if hazard:
		_group = 'hazards'
	else:
		_group = 'enemies'
	
	_entity = create(sprite_name='diamond_body.png', group=_group, x=x, y=y, acceleration=.4, speed=30, max_velocity=30, turn_rate=0.8)
	_entity['current_target'] = None
	_entity['fire_rate'] = 0
	_entity['fire_rate_max'] = 20
	_entity['weapon_id'] = weapons.create(_entity['_id'], rounds=3, recoil_time=15, speed=30, tracking=False)['_id']
	
	effects.create_image(_entity['position'][0],
	                     _entity['position'][1],
	                     'diamond_turret.png',
	                     parent_entity=_entity)
	effects.create_image(_entity['position'][0],
	                     _entity['position'][1],
	                     'diamond_drive.png',
	                     parent_entity=_entity,
	                     rotate_by=3)
	
	entities.register_event(_entity, 'moved', set_direction)
	entities.register_event(_entity, 'tick', tick_energy_ship)
	entities.register_event(_entity, 'tick', tick_flea)
	entities.register_event(_entity, 'tick', tick_turret)
	entities.register_event(_entity, 'shoot', lambda entity: entities.trigger_event(entities.get_entity(_entity['weapon_id']), 'shoot'))
	
	return _entity
Пример #22
0
def create_missile_turret(x=0, y=0):
	_entity = create(x=x, y=y, group='hazards', sprite_name='eyemine_body.png', speed=5, acceleration=1, max_velocity=5)
	_entity['weapon_id'] = weapons.create(_entity['_id'], rounds=3, recoil_time=20, tracking=True, turn_rate=.02)['_id']
	
	entities.register_event(_entity, 'shoot', lambda entity: entities.trigger_event(entities.get_entity(_entity['weapon_id']), 'shoot'))
	entities.register_event(_entity, 'tick', tick_turret)
	
	return _entity
Пример #23
0
def _gravity_well(entity):
	_moving_groups = [name for name in entities.GROUPS if not name in entity['_groups'] and not name in entities.IGNORE_ENTITY_GROUPS]
	
	for entity_id in entities.get_sprite_groups(_moving_groups):
		_entity = entities.get_entity(entity_id)
		
		if numbers.distance(entity['position'], _entity['position'])<entity['min_distance']:
			_entity['in_space'] = False
			
			continue
		
		if entity['kill_engines']:
			_entity['in_space'] = True
		
		_velocity = numbers.velocity(numbers.direction_to(_entity['position'], entity['position']), entity['strength'])
		
		entities.trigger_event(_entity, 'push', velocity=_velocity)
Пример #24
0
def tick_missile(bullet):
	if not random.randint(0, 3):
		_displace = (random.randint(-2, 2),
		             random.randint(-2, 2))
		
		effects.create_particle(bullet['position'][0]+_displace[0],
		                        bullet['position'][1]+_displace[1],
		                        'explosion.png',
		                        scale=0.2,
		                        scale_rate=.95,
		                        fade_rate=.7)
	
	bullet['engine_power'] -= 1
	
	if not bullet['engine_power']:
		entities.trigger_event(bullet, 'destroy')
	
	entities.trigger_event(bullet, 'set_rotation', degrees=bullet['direction'])
Пример #25
0
def tick_guard(entity):
    if 'in_space' in entity and entity['in_space']:
        return False

    if entity['hp'] <= 0:
        entities.unregister_event(entity, 'tick', tick_guard)

        return False

    if not entity['current_target']:
        _target_id = find_target(entity, max_distance=350)

        if _target_id:
            entities.trigger_event(
                entity,
                'set_direction',
                direction=numbers.direction_to(
                    entity['position'],
                    entities.get_entity(_target_id)['position']))
            track_target(entity, _target_id)
Пример #26
0
def create_energy_ship(x=0, y=0):
	_entity = create(x=x, y=y, group='players', sprite_name='ball.png', speed=19, acceleration=.3, max_velocity=30, turn_rate=0.5, death_time=35, hp=60)
	_entity['weapon_id'] = weapons.create(_entity['_id'],
	                                      rounds=35,
	                                      recoil_time=0,
	                                      reload_time=48,
	                                      kickback=3,
	                                      damage_radius=65,
	                                      spray=3,
	                                      speed=200,
	                                      missile=False,
	                                      bullet=True)['_id']
	_entity['alt_weapon_id'] = weapons.create(_entity['_id'], rounds=6, recoil_time=5, reload_time=28, speed=60, tracking=True)['_id']
	
	timers.register_entity(_entity)
	entities.register_event(_entity, 'tick', tick_energy_ship)
	entities.register_event(_entity, 'shoot', lambda entity, direction=0: entities.trigger_event(entities.get_entity(_entity['weapon_id']), 'shoot', direction=direction))
	entities.register_event(_entity, 'shoot_alt', lambda entity: entities.trigger_event(entities.get_entity(_entity['alt_weapon_id']), 'shoot'))
	
	return _entity
Пример #27
0
def create_missile(x, y, direction, speed, sprite_name, owner_id, life=3000, scale=.2, turn_rate=.15, tracking=True, drunk=True, radius=50):
	_bullet = create(x, y, direction, speed, sprite_name, owner_id, life=life, turn_rate=turn_rate, radius=radius)
	_owner = entities.get_entity(_bullet['owner_id'])
	_bullet['sprite'].anchor_x = 0
	_bullet['sprite'].anchor_y = sprites.get_size(_bullet['sprite'])[1]/2
	
	entities.trigger_event(_bullet, 'set_scale', scale=scale)
	entities.register_event(_bullet, 'tick', tick_missile)
	entities.register_event(_bullet, 'hit', hit_missile)
	
	if drunk:
		entities.register_event(_bullet, 'tick', tick_drunk)
	
	if tracking:
		_bullet['target_id'] = ai.find_target(_owner, max_distance=1600)
		
		if _bullet['target_id']:
			_target = entities.get_entity(_bullet['target_id'])
			
			entities.register_event(_bullet, 'tick', tick_track)
			entities.register_event(_target,
			                        'delete',
			                        lambda target: _bullet['_id'] in entities.ENTITIES and entities.unregister_event(_bullet,
			                                                                                                         'tick',
			                                                                                                         tick_track))
			
			if 'player' in _owner and _owner['player']:
				effects.create_particle(_target['position'][0],
					                    _target['position'][1],
					                    'crosshair.png',
					                    background=False,
					                    scale_rate=.95,
					                    fade_rate=.98,
					                    spin=random.choice([-3, -6, 3, 6]))
	else:
		_bullet['target_id'] = None
	
	_bullet['engine_power'] = 100
	
	return _bullet
Пример #28
0
def create(x, y, direction, speed, sprite_name, owner_id, damage=3, life=30, turn_rate=.15, radius=50):
	_entity = entities.create_entity()
	
	movement.register_entity(_entity, x=x, y=y, direction=direction, speed=speed, turn_rate=turn_rate)
	sprites.register_entity(_entity, 'effects_foreground', sprite_name)
	entities.create_event(_entity, 'hit')
	entities.create_event(_entity, 'destroy')
	entities.register_event(_entity, 'tick', tick)
	entities.register_event(_entity, 'tick', tick_bullet)
	entities.register_event(_entity, 'destroy', destroy)
	entities.register_event(_entity, 'hit_edge', lambda entity: entities.trigger_event(entity, 'destroy'))
	entities.trigger_event(_entity, 'set_friction', friction=0)
	entities.trigger_event(_entity, 'thrust')
	entities.add_entity_to_group('bullets', _entity)
	
	_entity['life'] = life
	_entity['owner_id'] = owner_id
	_entity['damage'] = damage
	_entity['damage_radius'] = radius
	_entity['enemy_sprite_groups'] = [name for name in entities.GROUPS if not name in entities.get_entity(_entity['owner_id'])['_groups'] and not name in entities.IGNORE_ENTITY_GROUPS]
	
	return _entity
Пример #29
0
def tick(bullet):
	for soldier_id in entities.get_sprite_groups(bullet['enemy_sprite_groups']):
		if bullet['owner_id'] == soldier_id:
			continue
		
		_entity = entities.get_entity(soldier_id)
		
		if numbers.distance(bullet['position'], _entity['position'], old=True)-_entity['collision_radius']>bullet['damage_radius']:
			continue
		
		if bullet['owner_id'] in entities.ENTITIES and 'player' in entities.get_entity(bullet['owner_id']):
			effects.create_particle(bullet['position'][0],
				                   bullet['position'][1],
				                   'hitmarker.png',
				                   direction=random.randint(0, 359),
				                   speed=random.randint(25, 30),
				                   background=False,
				                   fade_rate=0.8,
			                        scale_rate=1.02)
		
		entities.trigger_event(bullet, 'hit', target_id=soldier_id)
		entities.trigger_event(_entity, 'hit', damage=bullet['damage'], target_id=bullet['owner_id'])
		entities.delete_entity(bullet)
Пример #30
0
def tick_image(image):
	if image['parent_entity']:
		_parent_entity = entities.get_entity(image['parent_entity'])
		entities.trigger_event(image, 'set_position', x=_parent_entity['position'][0], y=_parent_entity['position'][1])
		
		if image['rotate_with_parent']:
			entities.trigger_event(image, 'set_rotation', degrees=_parent_entity['direction'])
		elif image['rotate_by']:
			entities.trigger_event(image, 'rotate_by', degrees=image['rotate_by'])
Пример #31
0
def ivan_cycles(entity):
	if entity['warmup_cycles']:
		entity['warmup_cycles'] -= 1
		
		return False
	
	if entity['cycle'] == 'shoot':
		#if entity['shoot_cycle'] == entity['shoot_cycle_max']:
		#	for i in range(8):
		#		bullet.create_laser(entity['position'][0], entity['position'][0], 45*(i+1), entity['_id'], damage=30, length=90)
		
		entity['shoot_cycle'] -= 1
		
		if not entity['shoot_cycle']:
			entity['shoot_cycle'] = entity['shoot_cycle_max']
			entity['cycle'] = 'spawn'
		
		for direction in range(0, 360, 15):
			for i in range(4):
				bullet.create_bullet(entity['position'][0],
					                entity['position'][1],
					                direction+4*i,
					                60+(i*10),
					                'boss3_core.png',
					                entity['_id'],
					                damage=15)
	else:
		entity['spawn_cycle'] -= 1
		
		if not entity['spawn_cycle']:
			entity['spawn_cycle'] = entity['shoot_cycle_max']
			entity['cycle'] = 'shoot'
		
		for i in range(5):
			_mine = create_eyemine(x=entity['position'][0], y=entity['position'][1], max_explode_velocity=90)
			entities.trigger_event(_mine, 'push', velocity=numbers.velocity(random.randint(0, 359), 65))
Пример #32
0
def create_gun_turret(x=0, y=0):
	_entity = create(x=x, y=y, group='hazards', sprite_name='eyemine_body.png', speed=5, acceleration=1, max_velocity=5)
	_entity['weapon_id'] = weapons.create(_entity['_id'],
	                                      rounds=10,
	                                      recoil_time=2,
	                                      reload_time=40,
	                                      damage_radius=40,
	                                      speed=140,
	                                      missile=False,
	                                      bullet=True)['_id']
	
	entities.register_event(_entity, 'shoot', lambda entity: entities.trigger_event(entities.get_entity(_entity['weapon_id']), 'shoot'))
	entities.register_event(_entity, 'tick', tick_turret)
	
	return _entity
Пример #33
0
def create_ivan(x=0, y=0):
	_entity = create(sprite_name='boss1.png', group='enemies', x=x, y=y, acceleration=.4, speed=3, max_velocity=3, turn_rate=0.8, death_time=40, hp=100)
	_entity['current_target'] = None
	_entity['fire_rate'] = 0
	_entity['fire_rate_max'] = 20
	_entity['weapon_id'] = weapons.create(_entity['_id'],
	                                      rounds=25,
	                                      recoil_time=1,
	                                      reload_time=30,
	                                      damage_radius=40,
	                                      speed=140,
	                                      missile=False,
	                                      bullet=True)['_id']
	
	entities.register_event(_entity, 'moved', set_direction)
	entities.register_event(_entity, 'tick', tick_energy_ship)
	entities.register_event(_entity, 'tick', tick_flea)
	entities.register_event(_entity, 'tick', tick_turret)
	entities.register_event(_entity, 'kill', boss_victory)
	entities.register_event(_entity, 'dying', boss_dying)
	entities.register_event(_entity, 'explode', boss_explode)
	entities.register_event(_entity, 'shoot', lambda entity: entities.trigger_event(entities.get_entity(_entity['weapon_id']), 'shoot'))
	
	return _entity
Пример #34
0
def damage(entity, damage, target_id=None):
	entity['hp'] -= damage
	
	if entity['hp']<=0 and entity['death_timer'] == -1:
		entities.trigger_event(entity, 'set_friction', friction=0.05)
		
		if target_id in entities.ENTITIES:
			entities.trigger_event(entities.get_entity(target_id),
			                       'score',
			                       target_id=entity['_id'],
			                       amount=5,
			                       text='Kill')
	elif entity['hp']<0:
		_text = 'Overkill'
		
		if target_id in entities.ENTITIES:
			entities.trigger_event(entities.get_entity(target_id),
			                       'score',
			                       target_id=entity['_id'],
			                       amount=2*abs(entity['hp']),
			                       text=_text)
Пример #35
0
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