scenes/levels: create coin objects

This commit is contained in:
Kazhnuz 2019-03-03 12:52:24 +01:00
parent ea9bdca58a
commit b83a5da0bb
6 changed files with 44 additions and 7 deletions

View File

@ -38,7 +38,7 @@ end
function Level:addEntityByName(name, x, y)
if name == "coin" then
Loot(self, x, y, "coin", 1)
Coin(self, x, y)
end
if name == "block" then
Block(self, x, y, 0)

View File

@ -4,7 +4,9 @@ local Obj = {}
Obj.Collision = require "scenes.levels.entities.collision"
Obj.Block = require "scenes.levels.entities.block"
Obj.Bullet = require "scenes.levels.entities.bullet"
Obj.Loot = require "scenes.levels.entities.loot"
Obj.Coin = require "scenes.levels.entities.loot.coin"
Obj.Coin5 = require "scenes.levels.entities.loot.coin5"
Obj.Coin10 = require "scenes.levels.entities.loot.coin10"
Obj.Weapon = require "scenes.levels.entities.weapon"
Obj.GFX = require "scenes.levels.entities.gfx"
Obj.Debris = require "scenes.levels.entities.debris"

View File

@ -0,0 +1,18 @@
local Loot = require "scenes.levels.entities.loot.parent"
Coin = Loot:extend()
function Coin:new(level, x, y, anim, value)
self.value = value or 1
self.anim = anim or 1
Coin.super.new(self, level, x, y, "coin", self.anim)
end
function Coin:takeLoot()
GFX(self.level, self.x+8, self.y+8, "sparkle", 1)
self:destroy()
self.level.gold = self.level.gold + self.value
assets:playSFX("collectcoin")
end
return Coin

View File

@ -0,0 +1,9 @@
local Coin = require "scenes.levels.entities.loot.coin"
Coin5 = Coin:extend()
function Coin5:new(level, x, y)
Coin5.super.new(self, level, x, y, 3, 10)
end
return Coin5

View File

@ -0,0 +1,9 @@
local Coin = require "scenes.levels.entities.loot.coin"
Coin5 = Coin:extend()
function Coin5:new(level, x, y)
Coin5.super.new(self, level, x, y, 2, 5)
end
return Coin5

View File

@ -1,14 +1,13 @@
local Entity = require "scenes.levels.entities.parent"
Loot = Entity:extend()
Coin = Loot:extend()
WeaponLoot = Loot:extend()
function Loot:new(level, x, y, name, value)
function Loot:new(level, x, y, name, anim)
Loot.super.new(self, level, "loot", x, y, 16, 16)
self.value = value
self.collType = "loot"
self.name = name
self.sprite = name
self.anim = anim
end
function Loot:takeLoot()
@ -24,7 +23,7 @@ end
function Loot:draw()
--local localx, localy = currentLevel.camera:cameraCoords(self.x, self.y)
assets.sprites[self.name]:draw(2, self.x, self.y)
assets.sprites[self.sprite]:draw(self.anim, self.x, self.y)
end
return Loot