Here the code:
Code: Select all
function Player:jump(x, y)
local x1, y1 = self.body:getLinearVelocity()
self.body:applyLinearImpulse(x, y)
end
function Player:slide(x, y)
self.body:setLinearVelocity(x, y)
end
function Player:update(dt)
--print(self.is_mouse_released)
--some code
if (self.is_mouse_released == true) and (self.is_collisioned == true) then --self.is_collisioned is true only when player touchs something
if self.is_sliding == true then
self:jump(15*self.impulse_koff_x, 30*self.impulse_koff_y)
self.is_sliding = false
end
self:jump(15*self.impulse_koff_x, 30*self.impulse_koff_y)
self.is_mouse_released = false
end
if self.is_sliding == true then
self:slide(0, 70)
end
if self.is_mouse_released == true then -- mouse is released only for 1 frame
self.is_mouse_released = false
end
end
-- mouse events
function Player:mouse_klicked()
self.is_mouse_pressed = true
self.is_mouse_released = false
end
function Player:mouse_released()
--self:jump(15*self.impulse_koff_x, 30*self.impulse_koff_y)
self.is_mouse_released = true
self.is_mouse_pressed = false
end