try and get player steering working

"
"
"
"
"
"
"
"
"
"
"
"
This commit is contained in:
Travis Shears 2026-05-13 22:34:44 +01:00
parent 26e88c8f03
commit 8e54b39b18
Signed by: travisshears
GPG key ID: CB9BF1910F3F7469
4 changed files with 66 additions and 42 deletions

View file

@ -49,10 +49,6 @@
"/main/player.sprite" "/main/player.sprite"
:text :text
] ]
[
"/main/main.atlas"
:scene
]
[ [
"/main/player.tilesource" "/main/player.tilesource"
:scene :scene
@ -61,14 +57,6 @@
"/game.project" "/game.project"
:cljfx-form-view :cljfx-form-view
] ]
[
"/input/game.input_binding"
:cljfx-form-view
]
[
"/main/main.collection"
:scene
]
[ [
"/main/player.sprite" "/main/player.sprite"
:scene :scene
@ -77,6 +65,18 @@
"/main/main.script" "/main/main.script"
:code :code
] ]
[
"/input/game.input_binding"
:cljfx-form-view
]
[
"/main/main.atlas"
:scene
]
[
"/main/main.collection"
:scene
]
[ [
"/main/player.script" "/main/player.script"
:code :code

View file

@ -1,18 +1,18 @@
key_trigger {
input: KEY_W
action: "up"
}
key_trigger { key_trigger {
input: KEY_A input: KEY_A
action: "left" action: "left_wheel_fwd"
} }
key_trigger { key_trigger {
input: KEY_S input: KEY_Q
action: "down" action: "left_wheel_bwk"
} }
key_trigger { key_trigger {
input: KEY_D input: KEY_D
action: "right" action: "right_wheel_fwd"
}
key_trigger {
input: KEY_E
action: "right_wheel_bwk"
} }
mouse_trigger { mouse_trigger {
input: MOUSE_BUTTON_LEFT input: MOUSE_BUTTON_LEFT

View file

@ -61,10 +61,6 @@ embedded_instances {
data: "components {\n" data: "components {\n"
" id: \"body\"\n" " id: \"body\"\n"
" component: \"/main/player.sprite\"\n" " component: \"/main/player.sprite\"\n"
" position {\n"
" x: 109.0\n"
" y: 90.0\n"
" }\n"
" scale {\n" " scale {\n"
" x: 2.0\n" " x: 2.0\n"
" y: 2.0\n" " y: 2.0\n"
@ -76,4 +72,8 @@ embedded_instances {
" component: \"/main/player.script\"\n" " component: \"/main/player.script\"\n"
"}\n" "}\n"
"" ""
position {
x: 189.0
y: 164.0
}
} }

View file

@ -1,30 +1,54 @@
go.property("speed", 100)
go.property("rotation_speed", 3)
function init(self) function init(self)
msg.post(".", "acquire_input_focus") -- <1> msg.post(".", "acquire_input_focus")
self.vel = vmath.vector3() -- <2> self.rotation = 0
self.rotating_left = false
self.rotating_right = false
self.moving_forward = false
end end
function update(self, dt) function update(self, dt)
local pos = go.get_position() -- <3> if self.rotating_left then
pos = pos + self.vel * dt -- <4> self.rotation = self.rotation + self.rotation_speed * dt
go.set_position(pos) -- <5> end
if self.rotating_right then
self.rotation = self.rotation - self.rotation_speed * dt
end
print("Rotation" .. self.rotation)
if self.moving_forward then
local vx = math.cos(self.rotation) * self.speed
local vy = math.sin(self.rotation) * self.speed
self.vel.x = 0 -- <6> local pos = go.get_position()
self.vel.y = 0 pos.x = pos.x + vx * dt
pos.y = pos.y + vy * dt
go.set_position(pos)
end
-- sprite.play_flipbook("#body", "s")
rot = go.get_rotation()
print(rot)
end end
function on_input(self, action_id, action) function on_input(self, action_id, action)
if action_id == hash("up") then -- Rotate with A/D keys
self.vel.y = 150 -- <7> if action_id == hash("left_wheel_fwd") and action.pressed then
elseif action_id == hash("down") then self.rotating_left = true
self.vel.y = -150 elseif action_id == hash("left_wheel_fwd") and action.released then
elseif action_id == hash("left") then self.rotating_left = false
self.vel.x = -150 -- <8> end
elseif action_id == hash("right") then
self.vel.x = 150 if action_id == hash("right_wheel_fwd") and action.pressed then
self.rotating_right = true
elseif action_id == hash("right_wheel_fwd") and action.released then
self.rotating_right = false
end
-- Move forward with W
if (action_id == hash("left_wheel_fwd") or action_id == hash("right_wheel_fwd")) and action.pressed then
self.moving_forward = true
elseif (action_id == hash("left_wheel_fwd") or action_id == hash("right_wheel_fwd")) and action.released then
self.moving_forward = false
end end
end end