feat(exemples): port movePlayer3D

This commit is contained in:
Kazhnuz 2024-11-02 09:10:08 +01:00
parent b882471c1d
commit b64cf3103d
5 changed files with 58 additions and 99 deletions

View file

@ -1,13 +0,0 @@
local Obj = {}
-- On charge toutes les différentes types d'acteurs
local cwd = (...):gsub('%.init$', '') .. "."
Obj.Player = require(cwd .. "player")
Obj.index = {}
Obj.index["player"] = Obj.Player
Obj.collisions = {}
Obj.collisions["wall"] = require(cwd .. "wall")
return Obj

View file

@ -1,14 +0,0 @@
local Base = require "framework.scenes.world.actors.actor3D"
local Parent = Base:extend()
function Parent:new(world, type, x, y, z, w, h, d, isSolid)
self.scene = world.scene
Parent.super.new(self, world, type, x, y, z, w, h, d, isSolid)
end
function Parent:draw()
Parent.super.draw(self)
self:drawMainHitbox()
end
return Parent

View file

@ -1,54 +1,63 @@
local cwd = (...):gsub('%.player$', '') .. "."
local Parent = require(cwd .. "parent")
local Player = Parent:extend()
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
},
}
function Player:new(world, x, y, z, id)
Player.super.new(self, world, "player", x, y, 0, 16, 16, 24, true)
self:setGravity(480)
self:setSprite("player", true, 8, 12)
function Player:onInit()
self.coin = 0
end
function Player:updateStart(dt)
self.xfrc, self.yfrc = 480*3, 480*3
if self.keys["up"].isDown then
self.ysp = -120
function Player:update(dt)
if love.keyboard.isDown("up") then
self.speed.y = -120
end
if self.keys["down"].isDown then
self.ysp = 120
if love.keyboard.isDown("down") then
self.speed.y = 120
end
if self.keys["left"].isDown then
self.xsp = -120
if love.keyboard.isDown("left") then
self.speed.x = -120
end
if self.keys["right"].isDown then
self.xsp = 120
if love.keyboard.isDown("right") then
self.speed.x = 120
end
if self.keys["A"].isDown and (self.onGround) then
self.zsp = 280
end
if love.keyboard.isDown("a") and (self.onGround) then
self.speed.z = 280
end
function Player:updateEnd(dt)
self:setAnimation()
print(self.position.z, self.onGround, self.gravity.z)
end
function Player:setAnimation()
local gsp = utils.math.pointDistance(0, 0, self.xsp, self.ysp)
self.sprite:setCustomSpeed(math.abs(gsp) / 12)
self:setDirection(self.xsp)
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
self.sprite:changeAnimation("punch", false)
self.visual:changeAnimation("punch", false)
else
if (self.onGround) then
if (math.abs(self.xsp) > 0) or (math.abs(self.ysp) > 0) then
self.sprite:changeAnimation("walk", false)
if (math.abs(self.speed.x) > 0) or (math.abs(self.speed.y) > 0) then
self.visual:changeAnimation("walk", false)
else
self.sprite:changeAnimation("idle", true)
self.visual:changeAnimation("idle", true)
end
else
self.sprite:changeAnimation("jump", true)
self.visual:changeAnimation("jump", true)
end
end
end
@ -58,16 +67,12 @@ function Player:setDirection(direction)
if direction ~= 0 then
direction = utils.math.sign(direction)
self.direction = direction
self.sprite:setScalling(direction, nil)
self.visual:setScalling({ x = direction, y = nil })
end
end
function Player:draw()
Player.super.draw(self)
end
function Player:drawHUD(id)
love.graphics.print(id .. " test", 4, 4)
function Player:drawHUD()
assets:print("medium", "Coins : " .. self.coin, 8, 8)
end
return Player

View file

@ -1,10 +0,0 @@
local Base = require "framework.scenes.world.actors.actor3D"
local Wall = Base:extend()
function Wall:new(world, x, y, z, w, h, d)
Wall.super.new(self, world, "wall", x, y, z, w, h, d, true)
self:setDebugColor(0,0,0)
self.boxes.Base(self, w, h, d)
end
return Wall

View file

@ -21,24 +21,15 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
local Scene = require "framework.scenes"
local MovePlayer = Scene:extend()
local World = require "framework.scenes.world.world3D"
function MovePlayer:new(playerNumber, cameraMode)
local playerNumber = playerNumber or 1
local cameraMode = cameraMode or "split"
MovePlayer.super.new(self)
World(self, "scenes.gameplay.moveplayer3D.actors", "datas/maps/topdown/arena.lua")
self.world:setPlayerNumber(playerNumber)
self.world.cameras:setMode(cameraMode)
self.world:loadMap()
self.world.obj.collisions["wall"](self.world, 0,0,-16,1000, 1000, 16)
end
return MovePlayer
return world {
actorPath = "scenes.gameplay.moveplayer3D.actors",
defaultMap = "datas/maps/topdown/arena.lua",
type = "3D",
collisions = {
wall = {isSolid = true, type = "wall"}
},
-- DEBUG, will be handled with tile collision later
createCollisions = {
{type = "wall", position = {x = 0, y = 0, z = -16}, dimensions = {w = 1000, h = 1000, d = 16}}
}
}