chore(levels): rename Actor.level to Actor.scene

This commit is contained in:
Kazhnuz 2019-06-16 18:10:39 +02:00
parent 042a2397a1
commit 017ae1a49c
11 changed files with 35 additions and 32 deletions

View File

@ -23,6 +23,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- **levels:** World is now a gamecore World2D derivative - **levels:** World is now a gamecore World2D derivative
- **levels:** Actors use now gamecore naming scheme
### Removed ### Removed
- **main:** All functions already provided by gamecore have been removed. - **main:** All functions already provided by gamecore have been removed.

View File

@ -8,20 +8,20 @@ function Block:new(level, x , y, item)
end end
function Block:draw(dt) function Block:draw(dt)
self.level.assets.tileset["block"]:drawTile(1, self.x, self.y) self.scene.assets.tileset["block"]:drawTile(1, self.x, self.y)
end end
function Block:breakBlock() function Block:breakBlock()
local x, y = self:getCenter() local x, y = self:getCenter()
local spd = 250 local spd = 250
local dist = 0 local dist = 0
self.obj.Debris(self.level, x+dist, y-dist, spd, 270+45) self.obj.Debris(self.scene, x+dist, y-dist, spd, 270+45)
self.obj.Debris(self.level, x+dist, y+dist, spd, 45) self.obj.Debris(self.scene, x+dist, y+dist, spd, 45)
self.obj.Debris(self.level, x-dist, y+dist, spd, 180+45) self.obj.Debris(self.scene, x-dist, y+dist, spd, 180+45)
self.obj.Debris(self.level, x-dist, y-dist, spd, 180-45) self.obj.Debris(self.scene, x-dist, y-dist, spd, 180-45)
self.obj.GFX(self.level, self.x+8, self.y+8, "poof", 1) self.obj.GFX(self.scene, self.x+8, self.y+8, "poof", 1)
self.level.assets:playSFX("break") self.scene.assets:playSFX("break")
self.level.playermanager.score = self.level.playermanager.score + 10 self.scene.playermanager.score = self.scene.playermanager.score + 10
self:destroy() self:destroy()
end end

View File

@ -49,7 +49,7 @@ end
function Debris:draw(dt) function Debris:draw(dt)
local rotation = math.floor(self.rotation/45)*45 local rotation = math.floor(self.rotation/45)*45
drawx, drawy = self:getCenter() drawx, drawy = self:getCenter()
self.level.assets.images["debris"]:draw(drawx, drawy, rotation, 1, 1, 4, 4) self.scene.assets.images["debris"]:draw(drawx, drawy, rotation, 1, 1, 4, 4)
end end
return Debris return Debris

View File

@ -30,11 +30,11 @@ end
function Ennemy:getDamage(base_damage) function Ennemy:getDamage(base_damage)
local damage = math.max(base_damage - self.armor, 1) local damage = math.max(base_damage - self.armor, 1)
self.hp = math.max(0, self.hp - damage) self.hp = math.max(0, self.hp - damage)
self.obj.Numbers(self.level, self.x+8, self.y+8, damage, {1,0,0}) self.obj.Numbers(self.scene, self.x+8, self.y+8, damage, {1,0,0})
if (self.hp == 0) then if (self.hp == 0) then
self:destroy() self:destroy()
self.obj.GFX(self.level, self.x+8, self.y+8, "poof", 1) self.obj.GFX(self.scene, self.x+8, self.y+8, "poof", 1)
self.level.playermanager.score = self.level.playermanager.score + 100 self.scene.playermanager.score = self.scene.playermanager.score + 100
end end
end end

View File

@ -10,7 +10,7 @@ function GFX:new(level, x, y, spritename, animID)
width = 16 width = 16
height = 16 height = 16
GFX.super.new(self, level, "gfx", x - (width/2), y - (height/2), width, height) GFX.super.new(self, level, "gfx", x - (width/2), y - (height/2), width, height)
self.animation = self.level.assets.sprites[spritename]:clone() self.animation = self.scene.assets.sprites[spritename]:clone()
self.duration = self.animation:getAnimationDuration() self.duration = self.animation:getAnimationDuration()
self.timer = 0 self.timer = 0
end end

View File

@ -20,7 +20,7 @@ end
function NumberGFX:draw() function NumberGFX:draw()
love.graphics.setColor(self.color) love.graphics.setColor(self.color)
self.level.assets.fonts["medium"]:set() self.scene.assets.fonts["medium"]:set()
love.graphics.printf(self.number, self.x+8-40, self.y+8, 80, "center") love.graphics.printf(self.number, self.x+8-40, self.y+8, 80, "center")
utils.graphics.resetColor() utils.graphics.resetColor()
end end

View File

@ -9,11 +9,11 @@ function Coin:new(level, x, y, anim, value)
end end
function Coin:takeLoot() function Coin:takeLoot()
self.obj.GFX(self.level, self.x+8, self.y+8, "sparkle", 1) self.obj.GFX(self.scene, self.x+8, self.y+8, "sparkle", 1)
self:destroy() self:destroy()
self.level.playermanager.gold = self.level.playermanager.gold + self.value self.scene.playermanager.gold = self.scene.playermanager.gold + self.value
self.level.playermanager.score = self.level.playermanager.score + 10 self.scene.playermanager.score = self.scene.playermanager.score + 10
self.level.assets:playSFX("collectcoin") self.scene.assets:playSFX("collectcoin")
end end
return Coin return Coin

View File

@ -9,11 +9,11 @@ function Loot:new(level, x, y, name)
end end
function Loot:takeLoot() function Loot:takeLoot()
self.obj.GFX(self.level, self.x+8, self.y+8, "sparkle", 1) self.obj.GFX(self.scene, self.x+8, self.y+8, "sparkle", 1)
self:destroy() self:destroy()
self.level.playermanager.gold = self.level.playermanager.gold + 1 self.scene.playermanager.gold = self.scene.playermanager.gold + 1
self.level.playermanager.score = self.level.playermanager.score + 10 self.scene.playermanager.score = self.scene.playermanager.score + 10
self.level.assets:playSFX("collectcoin") self.scene.assets:playSFX("collectcoin")
end end
function Loot:update(dt) function Loot:update(dt)
@ -21,7 +21,7 @@ function Loot:update(dt)
end end
function Loot:draw() function Loot:draw()
self.level.assets.sprites[self.sprite]:drawAnimation(self.x, self.y) self.scene.assets.sprites[self.sprite]:drawAnimation(self.x, self.y)
end end
return Loot return Loot

View File

@ -8,7 +8,7 @@ function Entity:new(level, collType, x, y, w, h) -- On enregistre une nouvelle e
end end
function Entity:initPhysics(level, collType, x, y, w, h) function Entity:initPhysics(level, collType, x, y, w, h)
self.level = level self.scene = level
self.world = level.world self.world = level.world
self.camera = level.camera self.camera = level.camera
self.obj = self.world.obj self.obj = self.world.obj

View File

@ -65,8 +65,8 @@ end
-- Physics and function called every game update -- Physics and function called every game update
function Player:update(dt) function Player:update(dt)
self.keys = self.level.sources[1].keys self.keys = self.scene.sources[1].keys
self.level.assets.sprites[self.stats.race]:setCustomSpeed(math.abs(self.xsp / 60)) self.scene.assets.sprites[self.stats.race]:setCustomSpeed(math.abs(self.xsp / 60))
self:actionMove(dt) self:actionMove(dt)
self:shoot(dt) self:shoot(dt)
@ -174,7 +174,7 @@ function Player:actionMove(dt)
if ((self.onGround == true) or multijump) and self.keys["A"].isPressed then if ((self.onGround == true) or multijump) and self.keys["A"].isPressed then
self.ysp = self.jmp self.ysp = self.jmp
self.isJumping = true self.isJumping = true
self.level.assets:playSFX("jump") self.scene.assets:playSFX("jump")
end end
if (self.isJumping == true) and (self.ysp < (-4 * 60)) and (not (self.keys["A"].isDown)) then if (self.isJumping == true) and (self.ysp < (-4 * 60)) and (not (self.keys["A"].isDown)) then
@ -185,7 +185,7 @@ function Player:actionMove(dt)
end end
function Player:launchWeapon() function Player:launchWeapon()
self.obj.Weapon(self.level, self.center.x, self.center.y, self.weapon, 350 * utils.math.sign(self.direction)) self.obj.Weapon(self.scene, self.center.x, self.center.y, self.weapon, 350 * utils.math.sign(self.direction))
end end
function Player:changeWeapon(id) function Player:changeWeapon(id)
@ -222,11 +222,11 @@ local animation = "idle"
end end
end end
if not (self.level.assets.sprites[self.stats.race]:animationExist(animation)) then if not (self.scene.assets.sprites[self.stats.race]:animationExist(animation)) then
animation = "idle" animation = "idle"
end end
self.level.assets.sprites[self.stats.race]:changeAnimation(animation, false) self.scene.assets.sprites[self.stats.race]:changeAnimation(animation, false)
return animation return animation
end end
@ -234,7 +234,7 @@ end
function Player:draw(dt) function Player:draw(dt)
local drawx, drawy = utils.math.floorCoord(self.center.x, self.center.y) local drawx, drawy = utils.math.floorCoord(self.center.x, self.center.y)
local animation = self:getAnimation() local animation = self:getAnimation()
self.level.assets.sprites[self.stats.race]:drawAnimation(drawx, drawy, 0, self.direction, 1, 16, 36) 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

View File

@ -59,7 +59,7 @@ end
function Weapon:draw(dt) function Weapon:draw(dt)
local rotation = math.floor(self.rotation/45)*45 local rotation = math.floor(self.rotation/45)*45
drawx, drawy = self:getCenter() drawx, drawy = self:getCenter()
self.level.assets.tileset["weapon"]:drawTile(self.weaponid, drawx, drawy, self.scene.assets.tileset["weapon"]:drawTile(self.weaponid, drawx, drawy,
rotation, self.direction, 1, 8, 8) rotation, self.direction, 1, 8, 8)
end end