Esempio n. 1
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)
Esempio n. 2
0
def tick_eyemine(entity):
	if 'max_explode_velocity' in entity and entity['current_speed']>=entity['max_explode_velocity']:
		entities.trigger_event(entity, 'kill')
		entities.trigger_event(entity, 'explode')
		
		return entities.delete_entity(entity)
	
	if entity['current_target'] and entity['current_target'] in entities.ENTITIES:
		_target_object = entities.get_entity(entity['current_target'])
	else:
		_target_object = None
	
	for soldier_id in entities.get_sprite_groups(['enemies', 'players']):
		if entity['_id'] == soldier_id:
			continue
		
		if numbers.distance(entity['position'], entities.get_entity(soldier_id)['position'], old=True)>50:
			continue
		
		if _target_object and not entity['current_target'] == soldier_id and 'player' in _target_object:
			entities.trigger_event(_target_object,
			                       'score',
			                       target_id=entity['_id'],
			                       amount=10,
			                       text='Creative Escape')
		
		entities.trigger_event(entities.get_entity(soldier_id), 'hit', damage=6, target_id=entity['_id'])
		entities.trigger_event(entity, 'kill')
		entities.trigger_event(entity, 'explode')
		entities.delete_entity(entity)
		
		break
Esempio n. 3
0
def create_image(x, y, sprite_name, parent_entity=None, rotate_by=0, rotate_with_parent=False, background=False, scale=1):
	_entity = entities.create_entity(group='effects')
	
	if parent_entity:
		_entity['parent_entity'] = parent_entity['_id']
	else:
		_entity['parent_entity'] = None
	
	_entity['rotate_by'] = rotate_by
	_entity['rotate_with_parent'] = rotate_with_parent
	
	movement.register_entity(_entity, x=x, y=y, no_tick=True)
	entities.register_event(_entity, 'loop', tick_image)
	
	if parent_entity:
		entities.register_event(parent_entity, 'delete', lambda parent_entity: entities.delete_entity(_entity))
	
	if background == 1:
		sprites.register_entity(_entity, 'effects_background', sprite_name, scale=scale)
	elif background == 2:
		sprites.register_entity(_entity, 'effects_background_bottom', sprite_name, scale=scale)
	else:
		sprites.register_entity(_entity, 'effects_foreground', sprite_name, scale=scale)
	
	return _entity
Esempio n. 4
0
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
Esempio n. 5
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'])
Esempio n. 6
0
def on_mouse_press(x, y, button, modifiers):
	_x, _y = int(round(CURSOR['position'][0])), int(round(CURSOR['position'][1]))
	_chunk_key = get_chunk_key_at(int(round(CURSOR['position'][0])), int(round(CURSOR['position'][1])))
	
	MOUSE_BUTTONS[button] = 1
	
	if button == 1 and not MAP[_chunk_key]['solid']:
		_tile = entities.create_entity(group='tiles_foreground')
		sprites.register_entity(_tile, 'tiles_foreground', 'wall_full.png')
		movement.register_entity(_tile, x=(_x/100)*100, y=(_y/100)*100)
		_tile['sprite'].image.anchor_x = 0
		_tile['sprite'].image.anchor_y = 0
		
		MAP[_chunk_key]['solid'] = True
		MAP[_chunk_key]['tile'] = _tile['_id']
	elif button == 4 and MAP[_chunk_key]['solid']:
		MAP[_chunk_key]['solid'] = False
		entities.delete_entity(entities.get_entity(MAP[_chunk_key]['tile']))
		del MAP[_chunk_key]['tile']
Esempio n. 7
0
def destroy(bullet):
	for i in range(random.randint(2, 3)):
		_effect = effects.create_particle(bullet['position'][0]+random.randint(-2, 2),
		                                  bullet['position'][1]+random.randint(-2, 2),
		                                  'explosion.png',
		                                  background=False,
		                                  scale=random.uniform(.4, .8),
		                                  flashes=random.randint(5, 7),
		                                  flash_chance=0.7,
		                                  direction=bullet['direction']+random.randint(-45, 45),
		                                  speed=bullet['current_speed']*.5)
	
	return entities.delete_entity(bullet)
Esempio n. 8
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)
Esempio n. 9
0
def tick_bullet(bullet):
	if bullet['life']>0:
		bullet['life'] -= 1
	else:
		entities.delete_entity(bullet)
Esempio n. 10
0
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()
Esempio n. 11
0
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()
Esempio n. 12
0
def create(owner_id, rounds=1, recoil_time=16, reload_time=35, kickback=0, spray=8, turn_rate=.15, speed=30, bullet=False, missile=True, hitscan=False, tracking=False, damage_radius=50):
	_entity = entities.create_entity(group='weapons')
	_entity['owner_id'] = owner_id
	_entity['rounds'] = rounds
	_entity['max_rounds'] = rounds
	_entity['recoil_time'] = 1
	_entity['recoil_time_max'] = recoil_time
	_entity['reload_time'] = reload_time
	_entity['reload_time_max'] = reload_time
	_entity['bullet'] = bullet
	_entity['missile'] = missile
	_entity['hitscan'] = hitscan
	_entity['tracking'] = tracking
	_entity['firing'] = False
	_entity['turn_rate'] = turn_rate
	_entity['speed'] = speed
	_entity['damage_radius'] = damage_radius
	_entity['kickback'] = kickback
	_entity['spray'] = spray
	
	entities.create_event(_entity, 'shoot')
	entities.register_event(_entity, 'shoot', shoot)
	entities.register_event(entities.get_entity(owner_id), 'delete', lambda owner_entity: entities.delete_entity(_entity))
	
	return _entity