feat(exemples): port movePlayer3D
This commit is contained in:
parent
b882471c1d
commit
b64cf3103d
5 changed files with 58 additions and 99 deletions
|
@ -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
|
|
|
@ -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
|
|
|
@ -1,54 +1,63 @@
|
||||||
local cwd = (...):gsub('%.player$', '') .. "."
|
local Player = actor {
|
||||||
local Parent = require(cwd .. "parent")
|
type = "player",
|
||||||
local Player = Parent:extend()
|
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)
|
function Player:onInit()
|
||||||
Player.super.new(self, world, "player", x, y, 0, 16, 16, 24, true)
|
self.coin = 0
|
||||||
self:setGravity(480)
|
|
||||||
|
|
||||||
self:setSprite("player", true, 8, 12)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:updateStart(dt)
|
function Player:update(dt)
|
||||||
self.xfrc, self.yfrc = 480*3, 480*3
|
if love.keyboard.isDown("up") then
|
||||||
|
self.speed.y = -120
|
||||||
if self.keys["up"].isDown then
|
|
||||||
self.ysp = -120
|
|
||||||
end
|
end
|
||||||
if self.keys["down"].isDown then
|
if love.keyboard.isDown("down") then
|
||||||
self.ysp = 120
|
self.speed.y = 120
|
||||||
end
|
end
|
||||||
if self.keys["left"].isDown then
|
if love.keyboard.isDown("left") then
|
||||||
self.xsp = -120
|
self.speed.x = -120
|
||||||
end
|
end
|
||||||
if self.keys["right"].isDown then
|
if love.keyboard.isDown("right") then
|
||||||
self.xsp = 120
|
self.speed.x = 120
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.keys["A"].isDown and (self.onGround) then
|
if love.keyboard.isDown("a") and (self.onGround) then
|
||||||
self.zsp = 280
|
self.speed.z = 280
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
function Player:updateEnd(dt)
|
|
||||||
self:setAnimation()
|
self:setAnimation()
|
||||||
|
|
||||||
|
print(self.position.z, self.onGround, self.gravity.z)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:setAnimation()
|
function Player:setAnimation()
|
||||||
local gsp = utils.math.pointDistance(0, 0, self.xsp, self.ysp)
|
local gsp = utils.math.pointDistance(0, 0, self.speed.x, self.speed.y)
|
||||||
self.sprite:setCustomSpeed(math.abs(gsp) / 12)
|
self.visual:setCustomSpeed(math.abs(gsp) / 12)
|
||||||
self:setDirection(self.xsp)
|
self:setDirection(self.speed.x)
|
||||||
if (self.isPunching) then
|
if (self.isPunching) then
|
||||||
self.sprite:changeAnimation("punch", false)
|
self.visual:changeAnimation("punch", false)
|
||||||
else
|
else
|
||||||
if (self.onGround) then
|
if (self.onGround) then
|
||||||
if (math.abs(self.xsp) > 0) or (math.abs(self.ysp) > 0) then
|
if (math.abs(self.speed.x) > 0) or (math.abs(self.speed.y) > 0) then
|
||||||
self.sprite:changeAnimation("walk", false)
|
self.visual:changeAnimation("walk", false)
|
||||||
else
|
else
|
||||||
self.sprite:changeAnimation("idle", true)
|
self.visual:changeAnimation("idle", true)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
self.sprite:changeAnimation("jump", true)
|
self.visual:changeAnimation("jump", true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -58,16 +67,12 @@ function Player:setDirection(direction)
|
||||||
if direction ~= 0 then
|
if direction ~= 0 then
|
||||||
direction = utils.math.sign(direction)
|
direction = utils.math.sign(direction)
|
||||||
self.direction = direction
|
self.direction = direction
|
||||||
self.sprite:setScalling(direction, nil)
|
self.visual:setScalling({ x = direction, y = nil })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:draw()
|
function Player:drawHUD()
|
||||||
Player.super.draw(self)
|
assets:print("medium", "Coins : " .. self.coin, 8, 8)
|
||||||
end
|
|
||||||
|
|
||||||
function Player:drawHUD(id)
|
|
||||||
love.graphics.print(id .. " test", 4, 4)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return Player
|
return Player
|
||||||
|
|
|
@ -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
|
|
|
@ -21,24 +21,15 @@
|
||||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local Scene = require "framework.scenes"
|
return world {
|
||||||
local MovePlayer = Scene:extend()
|
actorPath = "scenes.gameplay.moveplayer3D.actors",
|
||||||
|
defaultMap = "datas/maps/topdown/arena.lua",
|
||||||
local World = require "framework.scenes.world.world3D"
|
type = "3D",
|
||||||
|
collisions = {
|
||||||
function MovePlayer:new(playerNumber, cameraMode)
|
wall = {isSolid = true, type = "wall"}
|
||||||
local playerNumber = playerNumber or 1
|
},
|
||||||
local cameraMode = cameraMode or "split"
|
-- DEBUG, will be handled with tile collision later
|
||||||
|
createCollisions = {
|
||||||
MovePlayer.super.new(self)
|
{type = "wall", position = {x = 0, y = 0, z = -16}, dimensions = {w = 1000, h = 1000, d = 16}}
|
||||||
|
}
|
||||||
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
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue