Esempio n. 1
0
def loop(entity):
	if not entity['smooth_draw']:
		entity['sprite'].set_position_and_rotate_and_scale(entity['position'][0],
		                                                   display.get_window_size()[1]+entity['position'][1],
		                                                   entity['next_rotation'],
		                                                   entity['next_scale'])
		
		if not entity['last_scale'] and not entity['next_scale']:
			entities.unregister_event(entity, 'loop', loop)
		else:
			_dt = worlds.get_interp()
			img = entity['sprite']._texture
			_scale = numbers.interp(entity['last_scale'], entity['next_scale'], _dt)
			x1 = int(entity['sprite']._x - img.anchor_x * _scale)
			y1 = int(entity['sprite']._y - img.anchor_y * _scale)
			x2 = int(x1 + img.width * _scale)
			y2 = int(y1 + img.height * _scale)
			entity['sprite']._scale = _scale
			
			if not entity['sprite']._visible:
				entity['sprite']._vertex_list.vertices[:] = [0, 0, 0, 0, 0, 0, 0, 0]
			else:
				entity['sprite']._vertex_list.vertices[:] = [x1, y1, x2, y1, x2, y2, x1, y2]
		
		return False
	
	_dt = worlds.get_interp()
	_rot = numbers.interp(entity['last_rotation'], entity['next_rotation'], _dt)

	entity['sprite'].set_position_and_rotate_and_scale(int(round(numbers.interp(entity['last_position'][0], entity['position'][0], _dt))),
	                                                   numbers.interp(display.get_window_size()[1]+entity['last_position'][1],
	                                                                  display.get_window_size()[1]+entity['position'][1],
	                                                                  _dt),
	                                                   _rot,
	                                                   numbers.interp(entity['last_scale'], entity['next_scale'], _dt))
Esempio n. 2
0
def tick_track(entity):
    #_target_id = find_target(entity)
    _target_id = entity['current_target']

    if 'in_space' in entity and entity['in_space']:
        return False

    if entity['hp'] <= 0 or not _target_id in entities.ENTITIES:
        entity['current_target'] = None
        entities.unregister_event(entity, 'tick', tick_track)

        return False

    if not _target_id:
        entities.trigger_event(entity, 'accelerate', velocity=(0, 0))

        return False

    _target = entities.get_entity(_target_id)
    _direction_to = numbers.direction_to(entity['position'],
                                         _target['position'])
    _degrees_to = abs(entity['direction'] - _direction_to)

    if _degrees_to >= 180:
        _direction_to += 360

    _new_direction = numbers.interp(entity['direction'], _direction_to,
                                    entity['turn_rate'])
    _direction_difference = abs(entity['direction'] - _new_direction)
    entity['direction'] = _new_direction
    entities.trigger_event(entity, 'thrust')
Esempio n. 3
0
def tick_track(entity):
	#_target_id = find_target(entity)
	_target_id = entity['current_target']
	
	if 'in_space' in entity and entity['in_space']:
		return False
	
	if entity['hp']<=0 or not _target_id in entities.ENTITIES:
		entity['current_target'] = None
		entities.unregister_event(entity, 'tick', tick_track)
		
		return False
	
	if not _target_id:
		entities.trigger_event(entity, 'accelerate', velocity=(0, 0))
		
		return False
	
	_target = entities.get_entity(_target_id)
	_direction_to = numbers.direction_to(entity['position'], _target['position'])
	_degrees_to = abs(entity['direction']-_direction_to)
	
	if _degrees_to>=180:
		_direction_to += 360
	
	_new_direction = numbers.interp(entity['direction'], _direction_to, entity['turn_rate'])
	_direction_difference = abs(entity['direction']-_new_direction)
	entity['direction'] = _new_direction
	entities.trigger_event(entity, 'thrust')
Esempio n. 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()
Esempio n. 5
0
def on_mouse_scroll(x, y, scroll_x, scroll_y):
	display.CAMERA['next_zoom'] += .4*scroll_y
	
	display.CAMERA['next_center_on'][0] = numbers.interp(display.CAMERA['next_center_on'][0], CURSOR['position'][0], .5)
	display.CAMERA['next_center_on'][1] = numbers.interp(display.CAMERA['next_center_on'][1], CURSOR['position'][1], .5)