Started 'stages' framework
This commit is contained in:
@@ -95,7 +95,7 @@ function Game.new(core, mazeWidth, mazeHeight)
|
||||
return self
|
||||
end
|
||||
|
||||
function Game:enter()
|
||||
function Game:enter(level, startTime)
|
||||
-- Init environment
|
||||
self.world = bump.newWorld(TILE_SIZE)
|
||||
self.env.walls, self.env.maze, self.env.entrance, self.env.exits = initMaze(
|
||||
@@ -109,6 +109,8 @@ function Game:enter()
|
||||
|
||||
self.env.nodes = mazeutils.getNodeTiles(self.env.maze)
|
||||
|
||||
self.maxLevel = 3
|
||||
self.level = level or 1
|
||||
self.enemies = {
|
||||
Siren.new(self),
|
||||
Worm.new(self),
|
||||
@@ -121,8 +123,8 @@ function Game:enter()
|
||||
enemy:enter()
|
||||
end
|
||||
|
||||
self.startTime = love.timer.getTime()
|
||||
self.gameTime = '0:00'
|
||||
self.startTime = startTime or love.timer.getTime()
|
||||
self.gameTime = ''
|
||||
end
|
||||
|
||||
function Game:update(dt)
|
||||
@@ -182,7 +184,8 @@ function Game:draw()
|
||||
|
||||
-- Draw HUD view
|
||||
|
||||
love.graphics.print(self.gameTime, 8, 8)
|
||||
love.graphics.print('Level ' .. self.level, 8, 8)
|
||||
love.graphics.print(self.gameTime, 8, 24)
|
||||
end
|
||||
|
||||
function Game:exit()
|
||||
@@ -200,7 +203,11 @@ function Game:failLevel()
|
||||
end
|
||||
|
||||
function Game:nextLevel()
|
||||
self.core:switchState(self.core.states.game)
|
||||
if self.level == self.maxLevel then
|
||||
self.core:switchState(self.core.states.victory)
|
||||
else
|
||||
self.core:switchState(self.core.states.game, self.level + 1, self.startTime)
|
||||
end
|
||||
end
|
||||
|
||||
return Game
|
||||
|
||||
@@ -30,7 +30,7 @@ local wormQuads = {
|
||||
}
|
||||
local spriteBatch = love.graphics.newSpriteBatch(atlas)
|
||||
|
||||
function Worm.new(game)
|
||||
function Worm.new(game, length)
|
||||
setmetatable(Worm, { __index = LoveNode })
|
||||
local self = setmetatable(LoveNode.new(), Worm)
|
||||
self.game = game
|
||||
@@ -38,7 +38,7 @@ function Worm.new(game)
|
||||
self.stats = {
|
||||
spawnDistanceFromPlayer = 5 * TILE_SIZE,
|
||||
moveDelay = 1, -- Seconds between movement steps
|
||||
tailLength = 7
|
||||
tailLength = length or 7
|
||||
}
|
||||
|
||||
self.size = {}
|
||||
|
||||
Reference in New Issue
Block a user