epervier-framework/examples/scenes/gameplay/moveplayer3D/actors/player.lua

79 lines
1.7 KiB
Lua
Raw Normal View History

2024-11-02 09:10:08 +01:00
local Player = actor {
type = "player",
dimensions = { w = 16, h = 16, d = 24 },
friction = { x = 480 * 3, y = 480 * 3 },
gravity = { axis = "z", value = -480 },
isSolid = true,
visuals = {
mode = "sprite",
assetName = "monkey_lad",
clone = true,
origin = {
x = 8,
y = 12
},
getHitboxes = true
},
}
2024-11-02 09:10:08 +01:00
function Player:onInit()
self.coin = 0
end
2024-11-02 09:10:08 +01:00
function Player:update(dt)
if love.keyboard.isDown("up") then
self.speed.y = -120
end
2024-11-02 09:10:08 +01:00
if love.keyboard.isDown("down") then
self.speed.y = 120
end
2024-11-02 09:10:08 +01:00
if love.keyboard.isDown("left") then
self.speed.x = -120
end
2024-11-02 09:10:08 +01:00
if love.keyboard.isDown("right") then
self.speed.x = 120
end
2024-11-02 09:10:08 +01:00
if love.keyboard.isDown("a") and (self.onGround) then
self.speed.z = 280
end
self:setAnimation()
2024-11-02 09:10:08 +01:00
print(self.position.z, self.onGround, self.gravity.z)
end
function Player:setAnimation()
2024-11-02 09:10:08 +01:00
local gsp = utils.math.pointDistance(0, 0, self.speed.x, self.speed.y)
self.visual:setCustomSpeed(math.abs(gsp) / 12)
self:setDirection(self.speed.x)
if (self.isPunching) then
2024-11-02 09:10:08 +01:00
self.visual:changeAnimation("punch", false)
else
2024-11-02 09:10:08 +01:00
if (self.onGround) then
if (math.abs(self.speed.x) > 0) or (math.abs(self.speed.y) > 0) then
self.visual:changeAnimation("walk", false)
else
self.visual:changeAnimation("idle", true)
end
else
2024-11-02 09:10:08 +01:00
self.visual:changeAnimation("jump", true)
end
end
end
function Player:setDirection(direction)
direction = direction or 0
if direction ~= 0 then
direction = utils.math.sign(direction)
self.direction = direction
2024-11-02 09:10:08 +01:00
self.visual:setScalling({ x = direction, y = nil })
end
end
2024-11-02 09:10:08 +01:00
function Player:drawHUD()
assets:print("medium", "Coins : " .. self.coin, 8, 8)
end
return Player