feat(examples): add sprite support in moveplayer3D

This commit is contained in:
Kazhnuz 2019-06-30 22:05:02 +02:00
parent 5f5b4da9c5
commit 1ee0b77b50
3 changed files with 28 additions and 2 deletions

View file

@ -7,6 +7,7 @@ function Parent:new(world, type, x, y, z, w, h, d, isSolid)
end
function Parent:draw()
Parent.super.draw(self)
self:drawMainHitbox()
end

View file

@ -5,6 +5,9 @@ local Player = Parent:extend()
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", 8, 12)
self:cloneSprite()
end
function Player:updateStart(dt)
@ -23,11 +26,33 @@ function Player:updateStart(dt)
self.xsp = 120
end
if self.keys["A"].isDown then
if self.keys["A"].isDown and (self.onGround) then
self.zsp = 280
end
end
function Player:updateEnd(dt)
self:setAnimation()
end
function Player:setAnimation()
self:setCustomSpeed(math.abs(self.xsp) / 12)
if (self.isPunching) then
self:changeAnimation("punch", false)
else
if (self.onGround) then
if (math.abs(self.xsp) > 0) or (math.abs(self.ysp) > 0) then
self:changeAnimation("walk", false)
else
self:changeAnimation("idle", true)
end
else
self:changeAnimation("jump", true)
end
end
end
function Player:draw()
Player.super.draw(self)
end

View file

@ -28,9 +28,9 @@ local World = require "gamecore.modules.world.world3D"
function MovePlayer:new()
MovePlayer.super.new(self)
self.assets:batchImport("examples.gameplay.plateform.assets")
World(self, "examples.gameplay.moveplayer3D.actors", "examples/gameplay/moveplayer3D/assets/arena.lua")
self.world:setPlayerNumber(1)
self.world:loadMap()