feat: port action3D

This commit is contained in:
Kazhnuz 2024-11-05 21:04:14 +01:00
parent ced3ae0993
commit 3e5e49a8f6
8 changed files with 84 additions and 155 deletions

View file

@ -1,10 +1,9 @@
local Base = require "framework.scenes.world.actors.actor3D"
local Box = Base:extend()
function Box:new(world, x, y, z)
Box.super.new(self, world, "box", x, y, z, 16, 16, 16, true)
self:setDebugColor(0,0,0)
self.boxes.Textured(self, 16, 16, 16, "boxtop", "box")
end
return Box
return actor {
type = "box",
dimensions = {w = 16, h = 16, d = 16},
visuals = {
mode = "box3D",
texture = {top = "boxtop", bottom = "box"}
},
isSolid = true
}

View file

@ -1,14 +1,21 @@
local Base = require "framework.scenes.world.actors.actor3D"
local Coin = Base:extend()
local Coin = actor {
type = "coin",
dimensions = { w = 16, h = 16, d = 16},
isSolid = false,
visuals = {
mode = "sprite",
assetName = "coin"
},
onPlayerCollision = function (self, player)
self:destroy()
assets:playSFX("gameplay.collectcoin")
self.world:showGFX("gfx.sparkle", self.position)
player.coin = player.coin + 1
end
}
function Coin:new(world, x, y, z)
Coin.super.new(self, world, "coin", x, y, z + 16, 16, 16, 16, false)
self:setSprite("coin")
end
function Coin:takeCoin(other)
self.obj.GFX(self.world, self.x + 8, self.y + 8, self.z + 8, "sparkle")
self:destroy( )
function Coin:onInit()
self.position.z = self.position.z + 16
end
return Coin

View file

@ -1,13 +0,0 @@
return {
["idle"] = {
{
{"main", {0, 0, 0, 16, 16, 24}, true}
}
},
["punch"] = {
{
{"main", {0, 0, 0, 16, 16, 24}, true},
{"punch", {16, 2, 6, 12, 12, 12}, false}
}
}
}

View file

@ -1,18 +0,0 @@
local Obj = {}
-- On charge toutes les différentes types d'acteurs
local cwd = (...):gsub('%.init$', '') .. "."
Obj.Player = require(cwd .. "player")
Obj.Box = require(cwd .. "box")
Obj.Coin = require(cwd .. "coin")
Obj.GFX = require("framework.scenes.world.actors.gfx3D")
Obj.index = {}
Obj.index["player"] = Obj.Player
Obj.index["box"] = Obj.Box
Obj.index["coin"] = Obj.Coin
Obj.collisions = {}
Obj.collisions["wall"] = require(cwd .. "wall")
return Obj

View file

@ -1,13 +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)
end
return Parent

View file

@ -1,67 +1,69 @@
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)
self:setHitboxFile("scenes.gameplay.action3D.actors.hitboxes.player")
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") and (not self.isPunching) then
self.speed.y = -120
end
if self.keys["down"].isDown then
self.ysp = 120
if love.keyboard.isDown("down") and (not self.isPunching) then
self.speed.y = 120
end
if self.keys["left"].isDown then
self.xsp = -120
if love.keyboard.isDown("left") and (not self.isPunching) then
self.speed.x = -120
end
if self.keys["right"].isDown then
self.xsp = 120
if love.keyboard.isDown("right") and (not self.isPunching) 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
assets:playSFX("gameplay.jump")
end
if self.keys["B"].isDown then
if love.keyboard.isDown("z") then
self.isPunching = true
else
self.isPunching = false
end
if (self.isPunching) then
self:checkHitboxesCollisions()
end
end
function Player:updateEnd(dt)
self:setAnimation()
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
@ -70,28 +72,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:collisionResponse(collision)
if collision.other.type == "coin" then
collision.other.owner:takeCoin(self)
end
end
function Player:hitboxResponse(name, type, collision)
if (collision.other.type == "coin") and (type == "punch") then
collision.other.owner:takeCoin(self)
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.Mapped(self, x, y, z, 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.action3D.actors", "datas/maps/action3D/map.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.action3D.actors",
defaultMap = "datas/maps/action3D/map.lua",
type = "3D",
collisions = {
wall = {isSolid = true, type = "wall", mapTexture = true}
},
-- 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}}
}
}