Ejemplo n.º 1
0
def load_map(name):
	_map = {}
	
	with open('%s.dat' % name, 'r') as _file:
		_x = 0
		_y = 0
		
		for line in _file.readlines():
			_x = 0
			
			for tile in [int(c) for c in line if not c == '\n']:
				_map['%s,%s' % (_x*100, _y*100)] = {'solid': False}
				
				if tile == 1:
					_map['%s,%s' % (_x*100, _y*100)]['solid'] = True
					_tile = entities.create_entity('tiles_foreground')
					_map['%s,%s' % (_x*100, _y*100)]['tile'] = _tile['_id']
					_sprite = effects.create_image(_x*100, _y*100, 'wall_full.png')
					_id = _sprite['_id']
					
					entities.register_event(_tile, 'delete', lambda _entity: entities.delete_entity_via_id(_id))
					
					_sprite['sprite'].image.anchor_x = 0
					_sprite['sprite'].image.anchor_y = 0
				
				_x += 1
			_y += 1
	
	return _map
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
0
def create_gravity_well(x=0, y=0, kill_engines=True, strength=0.1, min_distance=3000):
	_entity = entities.create_entity(group='items')
	_entity['position'] = (x, y)
	_entity['min_distance'] = min_distance
	_entity['strength'] = strength
	_entity['kill_engines'] = kill_engines
	
	entities.register_event(_entity, 'tick', _gravity_well)
Ejemplo n.º 6
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
Ejemplo n.º 7
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
Ejemplo n.º 8
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']
Ejemplo n.º 9
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
Ejemplo n.º 10
0
import entities as ent
import transform as trf
import graphics as gfx
import character as char
import nmath as nm

for i in range(5):
	e = ent.create_entity()
	
	e.register_component("Transform")
	e.register_component("Graphics")
	e.register_component("Character")

	trf.set_world_transform(e, nm.Matrix44.translation(nm.Point(i * -2, 0, i * -2)))
	
	gfx.set_resource_uri(e, "mdl:Units/Unit_Footman.n3")
	gfx.set_tag(e, "Examples")
	gfx.set_visibility_type(e, 0)
	gfx.setup(e)
	
	char.set_skeleton_uri(e, "ske:Units/Unit_Footman.nsk3")
	char.set_animation_uri(e, "ani:Units/Unit_Footman.nax3")
	char.set_tag(e, "Examples")
	char.setup(e)
	char.play(e, 0, 0)
Ejemplo n.º 11
0
def cursor():
	global CURSOR
	
	CURSOR = entities.create_entity(group='cursor')
	movement.register_entity(CURSOR, x=0, y=0)
	sprites.register_entity(CURSOR, 'ui_foreground', 'crosshair.png')