improvement(levels): use Actor2D integrated sprite system
This commit is contained in:
parent
cd7e381672
commit
5241cb8d6e
|
@ -2,6 +2,8 @@ return {
|
||||||
metadata = {
|
metadata = {
|
||||||
width = 32,
|
width = 32,
|
||||||
height = 48,
|
height = 48,
|
||||||
|
ox = 16,
|
||||||
|
oy = 12,
|
||||||
defaultAnim = "idle"
|
defaultAnim = "idle"
|
||||||
},
|
},
|
||||||
animations = {
|
animations = {
|
||||||
|
|
|
@ -2,7 +2,9 @@ return {
|
||||||
metadata = {
|
metadata = {
|
||||||
width = 32,
|
width = 32,
|
||||||
height = 48,
|
height = 48,
|
||||||
defaultAnim = "walk"
|
ox = 16,
|
||||||
|
oy = 12,
|
||||||
|
defaultAnim = "idle"
|
||||||
},
|
},
|
||||||
animations = {
|
animations = {
|
||||||
["idle"] = {
|
["idle"] = {
|
||||||
|
|
|
@ -5,7 +5,7 @@ local Loot = Entity:extend()
|
||||||
function Loot:new(world, x, y, name)
|
function Loot:new(world, x, y, name)
|
||||||
Loot.super.new(self, world, "loot", x, y, 16, 16)
|
Loot.super.new(self, world, "loot", x, y, 16, 16)
|
||||||
self.type = "loot"
|
self.type = "loot"
|
||||||
self.sprite = name
|
self:setSprite(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Loot:takeLoot()
|
function Loot:takeLoot()
|
||||||
|
@ -20,8 +20,4 @@ function Loot:update(dt)
|
||||||
Loot.super.update(self, dt)
|
Loot.super.update(self, dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Loot:draw()
|
|
||||||
self.scene.assets.sprites[self.sprite]:drawAnimation(self.x, self.y)
|
|
||||||
end
|
|
||||||
|
|
||||||
return Loot
|
return Loot
|
||||||
|
|
|
@ -88,8 +88,4 @@ function Entity:isInsideView()
|
||||||
return self.camera:isInsideView(self.x, self.y, self.w, self.h)
|
return self.camera:isInsideView(self.x, self.y, self.w, self.h)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Entity:draw()
|
|
||||||
-- Cette fonction en contient rien par défaut
|
|
||||||
end
|
|
||||||
|
|
||||||
return Entity
|
return Entity
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
local Entity = require "scenes.levels.entities.parent"
|
local Entity = require "scenes.levels.entities.parent"
|
||||||
|
|
||||||
local Player = Entity:extend()
|
local Player = Entity:extend()
|
||||||
|
local PLAYER_W, PLAYER_H = 32, 24
|
||||||
|
|
||||||
-- INIT functions
|
-- INIT functions
|
||||||
-- Initialize the player
|
-- Initialize the player
|
||||||
|
|
||||||
function Player:new(world, x, y, playerID)
|
function Player:new(world, x, y, playerID)
|
||||||
|
|
||||||
local w, h = 32, 24
|
|
||||||
self.direction = 1
|
self.direction = 1
|
||||||
|
|
||||||
self.startx, self.starty = x, y
|
self.startx, self.starty = x, y
|
||||||
|
|
||||||
Player.super.new(self, world, "player", x - (w / 2), y - (h / 2), w, h)
|
Player.super.new(self, world, "player", x, y, PLAYER_W, PLAYER_H)
|
||||||
|
|
||||||
self.manager = self.scene.playermanager
|
self.manager = self.scene.playermanager
|
||||||
|
|
||||||
self.center = {
|
self.center = {
|
||||||
|
@ -29,6 +29,7 @@ function Player:new(world, x, y, playerID)
|
||||||
self.currentWeapon = 1
|
self.currentWeapon = 1
|
||||||
|
|
||||||
self:setDebugColor(0,255,0)
|
self:setDebugColor(0,255,0)
|
||||||
|
self:setSprite(self.stats.race, PLAYER_W/2, -PLAYER_H/2)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:getStats(playerID)
|
function Player:getStats(playerID)
|
||||||
|
@ -65,7 +66,7 @@ end
|
||||||
|
|
||||||
function Player:update(dt)
|
function Player:update(dt)
|
||||||
self.keys = self.scene.sources[1].keys
|
self.keys = self.scene.sources[1].keys
|
||||||
self.scene.assets.sprites[self.stats.race]:setCustomSpeed(math.abs(self.xsp / 60))
|
self:setCustomSpeed(math.abs(self.xsp / 60))
|
||||||
self:actionMove(dt)
|
self:actionMove(dt)
|
||||||
|
|
||||||
self:shoot(dt)
|
self:shoot(dt)
|
||||||
|
@ -86,6 +87,8 @@ function Player:update(dt)
|
||||||
if self.y >= (height + 64) then
|
if self.y >= (height + 64) then
|
||||||
self:die()
|
self:die()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:setAnimation()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:setFilter()
|
function Player:setFilter()
|
||||||
|
@ -199,41 +202,29 @@ end
|
||||||
|
|
||||||
-- DRAW functions
|
-- DRAW functions
|
||||||
|
|
||||||
function Player:getAnimation()
|
function Player:setAnimation()
|
||||||
local animation = "idle"
|
local animation = "idle"
|
||||||
|
self:setSpriteScallingX(self.direction)
|
||||||
|
|
||||||
|
|
||||||
if (self.onGround) then
|
if (self.onGround) then
|
||||||
if (self.xsp == 0) then
|
if (self.xsp == 0) then
|
||||||
animation = "idle"
|
self:changeAnimation("idle", false)
|
||||||
else
|
else
|
||||||
if (self.keys["left"].isDown and (self.xsp > 0)) or
|
if (self.keys["left"].isDown and (self.xsp > 0)) or
|
||||||
(self.keys["right"].isDown and (self.xsp < 0)) then
|
(self.keys["right"].isDown and (self.xsp < 0)) then
|
||||||
animation = "brake"
|
self:changeAnimation("brake", true)
|
||||||
else
|
else
|
||||||
animation = "walk"
|
self:changeAnimation("walk", false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if (self.ysp < 0) and (self.isJumping) then
|
if (self.ysp < 0) and (self.isJumping) then
|
||||||
animation = "jump"
|
self:changeAnimation("jump", true)
|
||||||
else
|
else
|
||||||
animation = "fall"
|
self:changeAnimation("fall", true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not (self.scene.assets.sprites[self.stats.race]:animationExist(animation)) then
|
|
||||||
animation = "idle"
|
|
||||||
end
|
|
||||||
|
|
||||||
self.scene.assets.sprites[self.stats.race]:changeAnimation(animation, false)
|
|
||||||
|
|
||||||
return animation
|
|
||||||
end
|
|
||||||
|
|
||||||
function Player:draw(dt)
|
|
||||||
local drawx, drawy = utils.math.floorCoord(self.center.x, self.center.y)
|
|
||||||
local animation = self:getAnimation()
|
|
||||||
self.scene.assets.sprites[self.stats.race]:drawAnimation(drawx, drawy, 0, self.direction, 1, 16, 36)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- DEATH and HIT functions
|
-- DEATH and HIT functions
|
||||||
|
|
Loading…
Reference in New Issue