Exemple #1
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
Exemple #2
0
def create_particle(x, y, sprite_name, background=True, scale=1, rotation=0, friction=0, scale_min=0.15, scale_max=5, direction=0, speed=0, scale_rate=1.0, fade_rate=1.0, spin=0, flashes=-1, flash_chance=0, streamer=False, streamer_chance=0.3, swerve_rate=0, swerve_speed=25, force_smooth_draw=False):
	_entity = entities.create_entity()
	_entity['scale_rate'] = scale_rate
	_entity['scale_min'] = scale_min
	_entity['scale_max'] = scale_max
	_entity['fade_rate'] = fade_rate
	_entity['flash_chance'] = flash_chance
	_entity['flashes'] = flashes
	_entity['spin'] = spin
	_entity['streamer'] = streamer
	_entity['swerve_rate'] = swerve_rate
	_entity['swerve_speed'] = swerve_speed
	_entity['swerve_speed_max'] = swerve_speed
	_entity['NO_BOUNCE'] = True
	
	if streamer:
		_entity['sprite_name'] = sprite_name
		_entity['background'] = background
		_entity['streamer_chance'] = streamer_chance
	
	movement.register_entity(_entity, x=x, y=y)
	entities.add_entity_to_group('effects', _entity)
	entities.trigger_event(_entity, 'set_direction', direction=direction)
	entities.trigger_event(_entity, 'set_speed', speed=speed)
	entities.trigger_event(_entity, 'thrust')
	
	if _entity['speed'] or force_smooth_draw:
		_smooth_draw = True
	else:
		_smooth_draw = False
		entities.register_event(_entity, 'moved', lambda entity, **kwargs: entities.trigger_event(entity, 'redraw'))
		
		#TODO: Hack
		entities.register_event(_entity, 'moved', lambda entity, **kwargs: entities.unregister_event(entity, 'tick', movement.tick))
	
	if background:
		sprites.register_entity(_entity, 'effects_background', sprite_name, scale=scale, smooth_draw=_smooth_draw)
	else:
		sprites.register_entity(_entity, 'effects_foreground', sprite_name, scale=scale, smooth_draw=_smooth_draw)
	
	if swerve_rate:
		_entity['sprite'].opacity = 0
	
	entities.register_event(_entity, 'tick', tick_particle)
	entities.trigger_event(_entity, 'set_friction', friction=friction)
	entities.trigger_event(_entity, 'set_rotation', degrees=rotation)
	
	return _entity
Exemple #3
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
Exemple #4
0
def register_entity(entity):
	entities.add_entity_to_group('players', entity)
	
	return entity