Exemple #1
0
def hit_laser(bullet, target_id):
	for i in range(random.randint(2, 3)):
		_effect = effects.create_particle(bullet['position'][0]+random.randint(-6, 6),
		                                  bullet['position'][1]+random.randint(-6, 6),
		                                  'explosion.png',
		                                  background=False,
		                                  scale=random.uniform(.4, .8),
		                                  flashes=random.randint(15, 25),
		                                  flash_chance=0.7)
		
		_effect['velocity'] = numbers.interp_velocity(bullet['velocity'], entities.get_entity(target_id)['velocity'], .1)
		_effect['velocity'][0] = numbers.clip(_effect['velocity'][0], -6, 6)
		_effect['velocity'][1] = numbers.clip(_effect['velocity'][1], -6, 6)
	
	entities.trigger_event(entities.get_entity(target_id), 'accelerate', velocity=numbers.interp_velocity(entities.get_entity(target_id)['velocity'], bullet['velocity'], .4))
Exemple #2
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()
Exemple #3
0
def handle_input():
	global MOUSE_POS, LAST_MOUSE_POS
	
	_mouse = tcod.mouse_get_status()
	_event = tcod.sys_check_for_event(tcod.EVENT_ANY, KEY, MOUSE)
	
	if KEY.c:
		_key_code = KEY.c
	else:
		_key_code = KEY.vk
	
	if _event == tcod.KEY_PRESSED:
		if not _key_code in INPUT:
			INPUT[_key_code] = 1
		else:
			INPUT[_key_code] += 1

		if '--keyout' in sys.argv and INPUT[_key_code] == 1:
			print KEY.c, KEY.vk, INPUT[_key_code]

	elif _event == tcod.KEY_RELEASED:
		INPUT[_key_code] = 0
	
	LAST_MOUSE_POS = MOUSE_POS[:]
	MOUSE_POS = [int(round(i)) for i in numbers.interp_velocity(LAST_MOUSE_POS, (_mouse.cx, _mouse.cy), .8)]
	
	if not MOUSE_POS == LAST_MOUSE_POS:
		events.trigger_event('mouse_moved',
		                     x=MOUSE_POS[0],
		                     y=MOUSE_POS[1],
		                     dx=MOUSE_POS[0]-LAST_MOUSE_POS[0],
		                     dy=MOUSE_POS[1]-LAST_MOUSE_POS[1])
	
	if _mouse.lbutton_pressed:
		events.trigger_event('mouse_pressed', x=MOUSE_POS[0], y=MOUSE_POS[1], button=1)
	
	if _mouse.rbutton_pressed:
		events.trigger_event('mouse_pressed', x=MOUSE_POS[0], y=MOUSE_POS[1], button=2)
	
	if _mouse.lbutton:
		events.trigger_event('mouse_held', x=MOUSE_POS[0], y=MOUSE_POS[1], button=1)
	
	if _mouse.rbutton:
		events.trigger_event('mouse_held', x=MOUSE_POS[0], y=MOUSE_POS[1], button=2)
Exemple #4
0
def on_draw():
	_window_width, _window_height = get_window_size()
	
	if RABBYT:
		lib2d.clear(100)
	else:
		gl.glClearColor(36/255.0, 33/255.0, 30/255.0, 1)
	
	WINDOW.clear()
	glMatrixMode(GL_PROJECTION)
	glLoadIdentity()
	glPushMatrix()
	events.trigger_event('camera')
	
	CAMERA['center_on'] = numbers.interp_velocity(CAMERA['center_on'], CAMERA['next_center_on'], CAMERA['camera_move_speed'])
	CAMERA['next_zoom'] = numbers.clip(CAMERA['next_zoom'], .4, 40)
	CAMERA['zoom'] = numbers.interp(CAMERA['zoom'], CAMERA['next_zoom'], CAMERA['zoom_speed'])
	
	glOrtho(CAMERA['center_on'][0]-(_window_width*(.5*CAMERA['zoom'])),
	        CAMERA['center_on'][0]+(_window_width*(.5*CAMERA['zoom'])),
	        CAMERA['center_on'][1]+(_window_height*(.5*CAMERA['zoom']))+_window_height,
	        CAMERA['center_on'][1]-(_window_height*(.5*CAMERA['zoom']))+_window_height, 0.0, 1.0)
	
	pyglet.graphics.draw(len(LEVEL_GRID)/2, GL_LINES,
	                     ('v2f', LEVEL_GRID),
	                     ('c4f', (.07, .07, .07, 1.0) * (len(LEVEL_GRID)/2)))
	
	if RABBYT:
		lib2d.render()
	else:
		events.trigger_event('draw')
	
	glPopMatrix()
	glPushMatrix()
	glOrtho(0, _window_width, 0, _window_height, 0.0, 1.0)
	
	for label in LABELS.values():
		label.draw()
	
	glPopMatrix()