So I'm using hump's class system, and everything is going swimmingly so far. Or was, until I added another class. Which to me means I screwed something up in the code for the new class. I've made classes before and it went fine, which has me pulling my hair out trying to figure this one out.
When I launch the game, I get:
gamestates/gameLevel1.lua:19: attempt to call upvalue 'Explosion' (a nil value)
Here's the code for gameLevel1.lua:
(line 19 is: exp = Explosion(0,0) as you may have guessed)
Code: Select all
Gamestate = require 'libs.hump.gamestate'
local Entities = require 'entities.Entities'
local Entity = require 'entities.Entity'
local gameLevel1 = {}
local Player = require 'entities.player'
local Bg = require 'entities.background'
local Enemy = require 'entities.enemy'
local Explosion require 'entities.explosion'
function gameLevel1:enter()
Entities:enter()
background = Bg(0,0)
enemy = Enemy(200,200)
exp = Explosion(0,0)
player = Player(100, 50, exp)
Entities:addMany({background, exp, player, enemy})
end
function gameLevel1:update(dt)
Entities:update(dt)
end
function gameLevel1:draw()
Entities:draw()
end
return gameLevel1
Code: Select all
local Class = require 'libs.hump.class'
local Entity = require 'entities.Entity'
local explosion = Class{
__includes = Entity
}
function explosion:init(x, y)
local img = love.graphics.newImage("assets/explosion04.png")
self.explosion = love.graphics.newParticleSystem(img, 32)
self.explosion:setParticleLifetime(1,2)
self.explosion:setSpeed(50,75)
self.explosion:setRotation(0,3)
self.explosion:setSizes(0.01,0.05)
self.explosion:setColors(255,255,255,255,255,255,255,0)
-- self.explosion:setDirection(3)
self.explosion:setParticleLifetime( 0.25, 0.5 )
-- Init Class
Entity.init(self, x, y, 1,1)
end
function explosion:update(dt)
self.explosion:update(dt)
end
function explosion:boom(x,y)
self.explosion:moveTo(x,y)
self.explosion:emit(10)
end
function explosion:draw()
love.graphics.draw(self.explosion)
end
return explosion