­ ”function init(self) msg.post(".", "acquire_input_focus") self.direction = vmath.vector3(0, 0, 0) self.speed = 250 self.gravity = -1500 self.jump_velocity = 500 self.velocity = vmath.vector3(0, 0, 0) self.grounded = false self.on_ladder = false self.climbing = false end function update(self, dt) self.velocity.x = self.direction.x * self.speed if self.climbing then self.velocity.y = 150 elseif self.on_ladder then self.velocity.y = 0 elseif not self.grounded then self.velocity.y = self.velocity.y + self.gravity * dt end local pos = go.get_position() pos = pos + self.velocity * dt go.set_position(pos) end function on_message(self, message_id, message, sender) if message_id == hash("contact_point_response") then local normal = message.normal if normal.y > 0.7 then self.grounded = true self.velocity.y = 0 end elseif message_id == hash("trigger_response") then if message.other_group == hash("ladder") then self.on_ladder = true end elseif message_id == hash("trigger_exit_response") then if message.other_group == hash("ladder") then self.on_ladder = false self.climbing = false end end end function on_input(self, action_id, action) if action_id == hash("left") then if action.pressed then sprite.play_flipbook("#sprite", hash("run_left")) self.direction.x = -1 elseif action.released then sprite.play_flipbook("#sprite", hash("still_left")) self.direction.x = 0 end elseif action_id == hash("right") then if action.pressed then sprite.play_flipbook("#sprite", hash("run_right")) self.direction.x = 1 elseif action.released then sprite.play_flipbook("#sprite", hash("still_right")) self.direction.x = 0 end elseif action_id == hash("jump") and action.pressed and (self.grounded or self.on_ladder) then self.velocity.y = self.jump_velocity self.grounded = false self.climbing = false elseif action_id == hash("up") then if action.pressed and self.on_ladder then self.climbing = true sprite.play_flipbook("#sprite", hash("climbing")) elseif action.released and self.climbing then self.climbing = false sprite.play_flipbook("#sprite", hash("still")) end end end @main/player2.script"