Example #1
0
def create_grid():
	global LEVEL_GRID
	
	LEVEL_GRID = []
	
	for i in range((worlds.get_size()[0]/100)+1):
		LEVEL_GRID.extend((100*i, (100*7), 100*i, (100*7)+worlds.get_size()[1]))
	
	for i in range((worlds.get_size()[1]/100)+1):
		LEVEL_GRID.extend((0, (100*7)+100*i, worlds.get_size()[1], (100*7)+100*i))
Example #2
0
def action_camera():
	global CAMERA_TIME, CAMERA_MODE
	
	if CAMERA_MODE == 'hover':
		display.CAMERA['next_center_on'] = numpy.array([worlds.get_size()[0]/2, worlds.get_size()[1]/2])
		display.CAMERA['next_zoom'] = 5.0
	
	elif CAMERA_MODE == 'follow':
		_focus_on = entities.get_entity_group('enemies')
		
		if not _focus_on:
			_focus_on = entities.get_entity_group('hazards')
		
		display.CAMERA['next_center_on'] = entities.get_entity(_focus_on[0])['position'].copy()
		display.CAMERA['next_zoom'] = 2.5
	
	CAMERA_TIME -= 1
	
	if not CAMERA_TIME:
		CAMERA_MODE = random.choice(CAMERA_MODES)
		CAMERA_TIME = random.randint(120, 200)
Example #3
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
Example #4
0
def handle_camera(entity_id, min_zoom=3.5, max_zoom=14.5, max_enemy_distance=2400, center_distance=600.0):
	if not entity_id in entities.ENTITIES:
		display.CAMERA['zoom_speed'] = .005
		display.CAMERA['next_zoom'] = 4.5
		
		return False
	
	if not clock.is_ticking():
		return False
	
	_player = entities.get_entity(entity_id)
	_center_pos = _player['position'].copy()
	_median_distance = []
	
	if 'in_space' in _player and _player['in_space']:
		_distance_to_center = numbers.distance(_player['position'], (worlds.get_size()[0]/2, worlds.get_size()[1]/2))
		
		_min_zoom = 2.0
		_max_zoom = max_zoom
		display.CAMERA['next_zoom'] = numbers.clip(_max_zoom*((_distance_to_center/3000.0)-1), _min_zoom, _max_zoom)
	
	elif _player['death_timer'] == -1:
		for enemy_id in entities.get_sprite_groups(['enemies', 'hazards']):
			_enemy = entities.get_entity(enemy_id)
			
			if 'player' in _enemy:
				continue
			
			_dist = numbers.distance(_player['position'], _enemy['position'])
			if _dist>=max_enemy_distance:
				continue
			
			_median_distance.append(_dist)
			_center_pos = numbers.interp_velocity(_center_pos, _enemy['position'], 0.5)
		
		if not _median_distance:
			_median_distance = [0]
		
		_distance_to_nearest_enemy = sum(_median_distance)/len(_median_distance)
		_min_zoom = min_zoom
		_max_zoom = max_zoom
		display.CAMERA['next_zoom'] = numbers.clip(_max_zoom*(_distance_to_nearest_enemy/float(center_distance)), _min_zoom, _max_zoom)
	else:
		display.CAMERA['zoom_speed'] = .05
		display.CAMERA['next_zoom'] = 1.5
	
	if display.CAMERA['next_zoom'] < 5:
		display.CAMERA['next_center_on'] = _center_pos
	else:
		display.CAMERA['next_center_on'] = _player['position'].copy()
Example #5
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
Example #6
0
def spawn_enemies():
	global TRANSITION_PAUSE, CHANGE_WAVE_FIRE, CHANGE_WAVE, ANNOUNCE, WAVE
	
	_i = random.choice([0, 1, 2, 3])
	
	if WAVE == 3:
		TRANSITION_PAUSE = 30*30
		CHANGE_WAVE = True
		CHANGE_WAVE_FIRE = False
		
		return False
	
	if LEVEL == 2:
		return False
	
	if _i == 1:
		_xrange = random.choice([(100, worlds.get_size()[0]*.25),
		                         (worlds.get_size()[0]*.25, worlds.get_size()[0]*.5),
		                         (worlds.get_size()[0]*.5, worlds.get_size()[0]*.75),
		                         (worlds.get_size()[0]*.75, worlds.get_size()[0]-100)])
		_y = 100
	elif _i == 2:
		_x = worlds.get_size()[0]-100
		_y = random.choice([(100, worlds.get_size()[1]*.25),
		                         (worlds.get_size()[1]*.25, worlds.get_size()[1]*.5),
		                         (worlds.get_size()[1]*.5, worlds.get_size()[1]*.75),
		                         (worlds.get_size()[1]*.75, worlds.get_size()[1]-100)])
	elif _i == 3:
		_x = 100
		_y = random.randint(100, worlds.get_size()[1]-100)
	else:
		_x = random.randint(100, worlds.get_size()[0]-100)
		_y = worlds.get_size()[1]-100
	
	_missile_turrets = int(round(10*((WAVE+1)/5.0)))
	_gun_turrets = int(round(10*(WAVE/5.0)))
	_fleas = int(round(5*(WAVE/5.0)))
	
	for i in range(_fleas):
		if _i == 1:
			_x = random.randint(100, worlds.get_size()[0]-100)
			_y = 100
		elif _i == 2:
			_x = worlds.get_size()[0]-100
			_y = random.randint(100, worlds.get_size()[1]-100)
		elif _i == 3:
			_x = 100
			_y = random.randint(100, worlds.get_size()[1]-100)
		else:
			_x = random.randint(100, worlds.get_size()[0]-100)
			_y = worlds.get_size()[1]-100
		
		_entity = ships.create_flea(x=_x, y=_y, hazard=True)
		_move_direction = numbers.direction_to((_x, _y,), (worlds.get_size()[0]/2, worlds.get_size()[1]/2))
		
		entities.trigger_event(_entity, 'push', velocity=numbers.velocity(_move_direction, 20))
	
	for i in range(_gun_turrets):
		if _i == 1:
			_x = random.randint(200, worlds.get_size()[0]-200)
			_y = 200
		elif _i == 2:
			_x = worlds.get_size()[0]-200
			_y = random.randint(200, worlds.get_size()[1]-200)
		elif _i == 3:
			_x = 200
			_y = random.randint(200, worlds.get_size()[1]-200)
		else:
			_x = random.randint(200, worlds.get_size()[0]-200)
			_y = worlds.get_size()[1]-200
		
		_entity = ships.create_gun_turret(x=_x, y=_y)
		_move_direction = numbers.direction_to((_x, _y,), (worlds.get_size()[0]/2, worlds.get_size()[1]/2))
		
		entities.trigger_event(_entity, 'push', velocity=numbers.velocity(_move_direction, 20))
	
	for i in range(_missile_turrets):
		if _i == 1:
			_x = random.randint(100, worlds.get_size()[0]-100)
			_y = 100
		elif _i == 2:
			_x = worlds.get_size()[0]-100
			_y = random.randint(100, worlds.get_size()[1]-100)
		elif _i == 3:
			_x = 100
			_y = random.randint(100, worlds.get_size()[1]-100)
		else:
			_x = random.randint(100, worlds.get_size()[0]-100)
			_y = worlds.get_size()[1]-100
		
		_entity = ships.create_missile_turret(x=_x, y=_y)
		_move_direction = numbers.direction_to((_x, _y,), (worlds.get_size()[0]/2, worlds.get_size()[1]/2))
		
		entities.trigger_event(_entity, 'push', velocity=numbers.velocity(_move_direction, 20))
	
	WAVE += 1
	ANNOUNCE = True
Example #7
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