blob: b0b63b65a6f202d6f6c17111ce54de8d3e6be936 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
|