From b64cf3103d58d60275f7d754537deb79afba8589 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 2 Nov 2024 09:10:08 +0100 Subject: [PATCH] feat(exemples): port movePlayer3D --- .../gameplay/moveplayer3D/actors/init.lua | 13 --- .../gameplay/moveplayer3D/actors/parent.lua | 14 --- .../gameplay/moveplayer3D/actors/player.lua | 87 ++++++++++--------- .../gameplay/moveplayer3D/actors/wall.lua | 10 --- .../scenes/gameplay/moveplayer3D/init.lua | 33 +++---- 5 files changed, 58 insertions(+), 99 deletions(-) delete mode 100644 examples/scenes/gameplay/moveplayer3D/actors/init.lua delete mode 100644 examples/scenes/gameplay/moveplayer3D/actors/parent.lua delete mode 100644 examples/scenes/gameplay/moveplayer3D/actors/wall.lua diff --git a/examples/scenes/gameplay/moveplayer3D/actors/init.lua b/examples/scenes/gameplay/moveplayer3D/actors/init.lua deleted file mode 100644 index 9d67a55..0000000 --- a/examples/scenes/gameplay/moveplayer3D/actors/init.lua +++ /dev/null @@ -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 diff --git a/examples/scenes/gameplay/moveplayer3D/actors/parent.lua b/examples/scenes/gameplay/moveplayer3D/actors/parent.lua deleted file mode 100644 index 456450d..0000000 --- a/examples/scenes/gameplay/moveplayer3D/actors/parent.lua +++ /dev/null @@ -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 diff --git a/examples/scenes/gameplay/moveplayer3D/actors/player.lua b/examples/scenes/gameplay/moveplayer3D/actors/player.lua index cd021ce..27107fc 100644 --- a/examples/scenes/gameplay/moveplayer3D/actors/player.lua +++ b/examples/scenes/gameplay/moveplayer3D/actors/player.lua @@ -1,55 +1,64 @@ -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 + if love.keyboard.isDown("a") and (self.onGround) then + self.speed.z = 280 end -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 (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 - self.sprite:changeAnimation("idle", true) + self.visual:changeAnimation("jump", true) end - else - self.sprite: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 diff --git a/examples/scenes/gameplay/moveplayer3D/actors/wall.lua b/examples/scenes/gameplay/moveplayer3D/actors/wall.lua deleted file mode 100644 index 137540a..0000000 --- a/examples/scenes/gameplay/moveplayer3D/actors/wall.lua +++ /dev/null @@ -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 diff --git a/examples/scenes/gameplay/moveplayer3D/init.lua b/examples/scenes/gameplay/moveplayer3D/init.lua index 8803359..ed8ccc8 100644 --- a/examples/scenes/gameplay/moveplayer3D/init.lua +++ b/examples/scenes/gameplay/moveplayer3D/init.lua @@ -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}} + } +}