summaryrefslogtreecommitdiff
path: root/src/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'src/controllers')
-rw-r--r--src/controllers/mouse_keyboard.moon55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/controllers/mouse_keyboard.moon b/src/controllers/mouse_keyboard.moon
new file mode 100644
index 0000000..b0b63b6
--- /dev/null
+++ b/src/controllers/mouse_keyboard.moon
@@ -0,0 +1,55 @@
+ecs = require("ecs")
+win = require("window")
+world = require("world")
+controller = {}
+
+class MouseKeyboardControllerComponent extends ecs.Component
+ new: (id, properties) =>
+ @text_size = 1
+ super(id, properties)
+ join: (ent) =>
+ graphic = ent\get("graphic")
+ @node = am.group!
+ graphic.properties.node\append(@node)
+ net_component = ent\get("net")
+ pred_component = ent\get("pred")
+ bind_node = graphic.properties.node("bind")
+ @node\action(() =>
+ x,y = 0,0
+ accel = {x:0,y:0} -- x,y
+ if win\key_down("w")
+ y += 0.001
+ if win\key_down("s")
+ y -= 0.001
+ if win\key_down("a")
+ x -= 0.001
+ if win\key_down("d")
+ x += 0.001
+ mouse_loc = win\mouse_position!
+ angle = -math.atan(mouse_loc.x / mouse_loc.y)
+ if mouse_loc.y > 0
+ angle = angle + math.pi
+ graphic\face(angle)
+ --print("angle is:", angle)
+ should_update = false
+ -- Need to update net component somehow
+ final_accel = vec2(x, y)
+ if net_component.properties.accel ~= final_accel
+ net_component.properties.accel = final_accel
+ net_component.properties.last_update = am.current_time!
+ --net_component.properties.vel = vec2(0,0)
+ --should_update = true
+ --print("Mouse keyboard action")
+ pred_loc = pred_component.properties.pos
+ world.world_x = pred_loc.x
+ world.world_y = pred_loc.y
+ bind_node.world_x = pred_loc.x
+ bind_node.world_y = pred_loc.y
+
+ )
+
+controller.text_size = 1
+controller.Controller = MouseKeyboardControllerComponent
+
+controller
+