from vgengine import game
from vgengine.game import graphics, physics, control

scene = game.Scene(
	physics.Physics2DGrid(),
	graphics.Graphics2D((400, 400)),
	control.Control()
)

scene.graphics.camera.size = (400, 400)

class Keyboard(control.Controller):
	def update(self):
		keyboard_pressed = graphics._pygame.key.get_pressed()
		self.set_pressed(control.UP, keyboard_pressed[graphics.K_UP])
		self.set_pressed(control.LEFT, keyboard_pressed[graphics.K_LEFT])
		self.set_pressed(control.RIGHT, keyboard_pressed[graphics.K_RIGHT])
		self.set_pressed(control.DOWN, keyboard_pressed[graphics.K_DOWN])

def quit(scene, event):
	print 'quiting scene'
	scene.game.quit()

scene.add_event_handler('quit', quit)
def move(x, y):
	def action(go):
		go.body.velocity = (x, y)
		# print go.velocity
		# print go.position
	return control.Action(action, False)

action_set = control.ActionSet({
	(control.LEFT, ) : move(-1, 0),
	(control.RIGHT, ): move(1, 0),
	(control.UP, )   : move(0, 1),
	(control.DOWN, ) : move(0, -1),
	None : move(0, 0)
})

box = game.GameObject()
box.add(physics.Body2DGrid(), 
	graphics.RectSprite2DGrid(),
	Keyboard(),
	action_set)

scene.room.add(box)

basic_game = game.Game(scene)

basic_game.run(60)