changed level generation, fixed settings, score on game over page

This commit is contained in:
Paul Liverman
2015-02-09 20:22:30 -08:00
parent a96d307a8e
commit 64bbfc78a8
2 changed files with 19 additions and 12 deletions

View File

@@ -11,13 +11,12 @@ local game = {}
local boxes = {} local boxes = {}
local score, totalScore = 0, 0 local score, totalScore = 0, 0
local level, time, startingTime = 0, 0, 0 local level, time, startingTime = 0, 0, 0
local previousState local previousState, gameSettings
--these are defined on each entry to this gamestate --these are defined on each entry to this gamestate
local screenWidth, screenHeight --defines where things are rendered local screenWidth, screenHeight --defines where things are rendered
local boxColumns, boxRows --defines how many boxes local boxColumns, boxRows --defines how many boxes
--these are loaded from values passed on entry to this gamestate --these are loaded from values passed on entry to this gamestate
--TODO ACTUALLY HAVE THESE LOAD INSTEAD OF DEFINE HERE local boxSize, colorStep, timeLimit = 20, 80, 60 --default values just in case
local boxSize, colorStep, timeLimit = 20, 80, 10--60
local function nextLevel() local function nextLevel()
totalScore = totalScore + score totalScore = totalScore + score
@@ -36,7 +35,7 @@ local function nextLevel()
end end
-- assign a random set of boxes random colors -- assign a random set of boxes random colors
for i=1,math.floor(level * 1.5 + 2) do for i=1,math.floor(math.pow(level, 1.07) * 1.03 + 2) do --(level * 1.5 + 2)
local x, y = love.math.random(0, #boxes), love.math.random(0, #boxes[1]) local x, y = love.math.random(0, #boxes), love.math.random(0, #boxes[1])
boxes[x][y] = {love.math.random(0, 255), love.math.random(0, 255), love.math.random(0, 255)} boxes[x][y] = {love.math.random(0, 255), love.math.random(0, 255), love.math.random(0, 255)}
boxes[x][y][1] = boxes[x][y][1] - boxes[x][y][1] % colorStep --is this right? boxes[x][y][1] = boxes[x][y][1] - boxes[x][y][1] % colorStep --is this right?
@@ -64,10 +63,12 @@ function game:enter(previous, settings)
screenHeight = love.graphics.getHeight() screenHeight = love.graphics.getHeight()
boxColumns = math.floor(screenWidth / boxSize) - 1 boxColumns = math.floor(screenWidth / boxSize) - 1
boxRows = math.floor(screenHeight / boxSize) - 5 boxRows = math.floor(screenHeight / boxSize) - 5
-- save the settings for later use
gameSettings = settings or gameSettings
-- set how to play the game based on settings -- set how to play the game based on settings
boxSize = settings.boxSize boxSize = gameSettings.boxSize
colorStep = settings.colorStep colorStep = gameSettings.colorStep
timeLimit = settings.timeLimit timeLimit = gameSettings.timeLimit
-- set the font we're going to use -- set the font we're going to use
love.graphics.setNewFont(28) love.graphics.setNewFont(28)
-- this is nextLevel shit -- this is nextLevel shit
@@ -108,7 +109,7 @@ function game:update(dt)
time = time - dt time = time - dt
if time <= 0 then if time <= 0 then
-- TODO we need to pass an image of the screen and data about time of losing -- TODO we need to pass an image of the screen and data about time of losing
Gamestate.push(lost, love.graphics.newScreenshot()) Gamestate.push(lost, love.graphics.newScreenshot(), totalScore + score)
-- call leave to clean up the gamestate -- call leave to clean up the gamestate
game:leave() game:leave()
end end
@@ -185,6 +186,7 @@ function game:leave()
score = 0 score = 0
totalScore = 0 totalScore = 0
time = 0 time = 0
startingTime = 0
end end
function game:keypressed(key, unicode) function game:keypressed(key, unicode)

View File

@@ -1,11 +1,11 @@
local lost = {} local lost = {}
local previousState, screenshot local previousState, screenshot, score
function lost:enter(previous, screenImageData) function lost:enter(previous, screenImageData, totalScore)
previousState = previous previousState = previous
screenshot = love.graphics.newImage(screenImageData) screenshot = love.graphics.newImage(screenImageData)
love.graphics.setNewFont(40) score = totalScore
end end
function lost:draw() function lost:draw()
@@ -16,8 +16,13 @@ function lost:draw()
love.graphics.setColor(0, 0, 0, 200) love.graphics.setColor(0, 0, 0, 200)
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight()) love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
-- print info -- print info
love.graphics.setNewFont(40)
love.graphics.setColor(255, 255, 255) love.graphics.setColor(255, 255, 255)
love.graphics.printf("Game Over", 0, love.graphics.getHeight() / 2, love.graphics.getWidth(), "center") love.graphics.printf("Game Over", 0, love.graphics.getHeight() / 4 - 20, love.graphics.getWidth(), "center")
love.graphics.setNewFont(50)
love.graphics.printf(string.format("Final Score: %.1f", score), 0, love.graphics.getHeight() / 2 - 25, love.graphics.getWidth(), "center")
love.graphics.setNewFont(16)
love.graphics.printf("(Click to restart.)", 0, love.graphics.getHeight() * 3/4 - 8, love.graphics.getWidth(), "center")
--[[ --[[
love.graphics.printf(string.format("Total Score: %.1f", totalScore), 0, 3, screenWidth / 2, "center") love.graphics.printf(string.format("Total Score: %.1f", totalScore), 0, 3, screenWidth / 2, "center")
--love.graphics.printf(string.format("Best Score: %.1f", bestScore), screenWidth / 2, 3, screenWidth / 2, "center") --love.graphics.printf(string.format("Best Score: %.1f", bestScore), screenWidth / 2, 3, screenWidth / 2, "center")