Exemplo n.º 1
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
Exemplo n.º 2
0
def update(dt):
    for entity_id, state in launchers.iteritems():
        hot = state.hot
        if hot:
            hot -= min(hot, dt)
        elif trigger.is_down(entity_id):
            hot = state.cooldown
            offset = state.offset
            player_only = state.player_only
            pos_x, pos_y, angle = spatial.get_position_and_angle(entity_id)
            bullet.create_missile((pos_x + offset, pos_y), angle, SPEED, IMAGE,
                                  entity_id, player_only=player_only)
            state.offset = -offset
        state.hot = hot
        state.trigger = False