diff options
| author | Alexander M Pickering <alex@cogarr.net> | 2025-01-21 16:02:51 -0600 |
|---|---|---|
| committer | Alexander M Pickering <alex@cogarr.net> | 2025-01-21 16:02:51 -0600 |
| commit | 0370d64b3bd7914be55358817e52bbc8a529a7d3 (patch) | |
| tree | a717bb9582f8a4c8dc7caf0d455e25113c7b8704 /src/controllers | |
| parent | da9dd31f504d30f33922cdf362a7c01673a6b927 (diff) | |
| download | ggj25-0370d64b3bd7914be55358817e52bbc8a529a7d3.tar.gz ggj25-0370d64b3bd7914be55358817e52bbc8a529a7d3.tar.bz2 ggj25-0370d64b3bd7914be55358817e52bbc8a529a7d3.zip | |
work
Diffstat (limited to 'src/controllers')
| -rw-r--r-- | src/controllers/mouse_keyboard.moon | 55 |
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 + |
