diff --git a/defold_game/.editor_settings b/defold_game/.editor_settings index d62211c..abdccd1 100644 --- a/defold_game/.editor_settings +++ b/defold_game/.editor_settings @@ -49,10 +49,6 @@ "/main/player.sprite" :text ] - [ - "/main/main.atlas" - :scene - ] [ "/main/player.tilesource" :scene @@ -61,14 +57,6 @@ "/game.project" :cljfx-form-view ] - [ - "/input/game.input_binding" - :cljfx-form-view - ] - [ - "/main/main.collection" - :scene - ] [ "/main/player.sprite" :scene @@ -77,6 +65,18 @@ "/main/main.script" :code ] + [ + "/input/game.input_binding" + :cljfx-form-view + ] + [ + "/main/main.atlas" + :scene + ] + [ + "/main/main.collection" + :scene + ] [ "/main/player.script" :code diff --git a/defold_game/input/game.input_binding b/defold_game/input/game.input_binding index 45a27f2..d789024 100644 --- a/defold_game/input/game.input_binding +++ b/defold_game/input/game.input_binding @@ -1,18 +1,18 @@ -key_trigger { - input: KEY_W - action: "up" -} key_trigger { input: KEY_A - action: "left" + action: "left_wheel_fwd" } key_trigger { - input: KEY_S - action: "down" + input: KEY_Q + action: "left_wheel_bwk" } key_trigger { input: KEY_D - action: "right" + action: "right_wheel_fwd" +} +key_trigger { + input: KEY_E + action: "right_wheel_bwk" } mouse_trigger { input: MOUSE_BUTTON_LEFT diff --git a/defold_game/main/main.collection b/defold_game/main/main.collection index a908b83..b5548d1 100644 --- a/defold_game/main/main.collection +++ b/defold_game/main/main.collection @@ -61,10 +61,6 @@ embedded_instances { data: "components {\n" " id: \"body\"\n" " component: \"/main/player.sprite\"\n" - " position {\n" - " x: 109.0\n" - " y: 90.0\n" - " }\n" " scale {\n" " x: 2.0\n" " y: 2.0\n" @@ -76,4 +72,8 @@ embedded_instances { " component: \"/main/player.script\"\n" "}\n" "" + position { + x: 189.0 + y: 164.0 + } } diff --git a/defold_game/main/player.script b/defold_game/main/player.script index 5a36a35..9caa1d5 100644 --- a/defold_game/main/player.script +++ b/defold_game/main/player.script @@ -1,30 +1,54 @@ +go.property("speed", 100) +go.property("rotation_speed", 3) + function init(self) - msg.post(".", "acquire_input_focus") -- <1> - self.vel = vmath.vector3() -- <2> + msg.post(".", "acquire_input_focus") + self.rotation = 0 + self.rotating_left = false + self.rotating_right = false + self.moving_forward = false end function update(self, dt) - local pos = go.get_position() -- <3> - pos = pos + self.vel * dt -- <4> - go.set_position(pos) -- <5> + if self.rotating_left then + self.rotation = self.rotation + self.rotation_speed * dt + 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> - self.vel.y = 0 + local pos = go.get_position() + 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 + function on_input(self, action_id, action) - if action_id == hash("up") then - self.vel.y = 150 -- <7> - elseif action_id == hash("down") then - self.vel.y = -150 - elseif action_id == hash("left") then - self.vel.x = -150 -- <8> - elseif action_id == hash("right") then - self.vel.x = 150 + -- Rotate with A/D keys + if action_id == hash("left_wheel_fwd") and action.pressed then + self.rotating_left = true + elseif action_id == hash("left_wheel_fwd") and action.released then + self.rotating_left = false + end + + 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