various improvements
- console temporarily enabled DO NOT RELEASE - game is bigger (a bit more difficult) and in 19x6 resolution now - fullscreen explicitly false to prevent fullscreen happening when setting resolution to monitor size - time limit added, with game over screen (needs work) - code adjusted to work with any resolution (assuming in 20 px intervals)
This commit is contained in:
@@ -2,13 +2,15 @@ function love.conf(t)
|
|||||||
t.identity = "rgb"
|
t.identity = "rgb"
|
||||||
t.version = "0.9.1"
|
t.version = "0.9.1"
|
||||||
--t.author = "Guard13007"
|
--t.author = "Guard13007"
|
||||||
--t.console = true
|
t.console = true
|
||||||
|
|
||||||
t.window = {}
|
t.window = {}
|
||||||
t.window.title = "RGB - The Color Chooser"
|
t.window.title = "RGB - The Color Chooser"
|
||||||
t.window.width = 800
|
t.window.width = 960 --800
|
||||||
t.window.height = 460
|
t.window.height = 540 --460
|
||||||
|
t.window.fullscreen = false
|
||||||
t.window.borderless = true
|
t.window.borderless = true
|
||||||
|
t.window.resizable = false
|
||||||
|
|
||||||
--t.modules = {}
|
--t.modules = {}
|
||||||
t.modules.joystick = false
|
t.modules.joystick = false
|
||||||
|
123
src/game.lua
123
src/game.lua
@@ -1,34 +1,42 @@
|
|||||||
love.math.setRandomSeed(os.time())
|
love.math.setRandomSeed(os.time())
|
||||||
|
|
||||||
local Gamestate = require "lib.gamestate"
|
-- Gamestates
|
||||||
|
--local won = require "won" --TODO MAKE THIS
|
||||||
|
local lost = require "lost"
|
||||||
|
|
||||||
|
-- This Gamestate
|
||||||
local game = {}
|
local game = {}
|
||||||
|
|
||||||
|
-- Locals
|
||||||
local boxes = {}
|
local boxes = {}
|
||||||
local boxSize = 20
|
local score, totalScore = 0, 0
|
||||||
local wAmount = math.floor(love.graphics.getWidth() / boxSize) - 1
|
local level, time, startingTime = 0, 0, 0
|
||||||
local hAmount = math.floor(love.graphics.getHeight() / boxSize) - 5
|
local previousState
|
||||||
|
--these are defined on each entry to this gamestate
|
||||||
local level = 0
|
local screenWidth, screenHeight --defines where things are rendered
|
||||||
local score = 0
|
local boxColumns, boxRows --defines how many boxes
|
||||||
local totalScore = 0
|
--these are loaded from values passed on entry to this gamestate
|
||||||
local time = 0
|
--TODO ACTUALLY HAVE THESE LOAD INSTEAD OF DEFINE HERE
|
||||||
local colorStep = 80 -- difficulty setting
|
local boxSize, colorStep, timeLimit = 20, 80, 10--60
|
||||||
|
|
||||||
local function nextLevel()
|
local function nextLevel()
|
||||||
totalScore = totalScore + score
|
totalScore = totalScore + score
|
||||||
level = level + 1
|
|
||||||
score = 0
|
score = 0
|
||||||
time = 0
|
level = level + 1
|
||||||
|
time = time + timeLimit --your remaining time is added on to the next level
|
||||||
|
startingTime = time --save where you started on this level for scoring
|
||||||
|
|
||||||
-- initial black boxes
|
-- (re)create black boxes
|
||||||
for i=0,wAmount do
|
boxes = {}
|
||||||
|
for i=0,boxColumns do
|
||||||
boxes[i] = {}
|
boxes[i] = {}
|
||||||
for j=0,hAmount do
|
for j=0,boxRows do
|
||||||
boxes[i][j] = {0, 0, 0}
|
boxes[i][j] = {0, 0, 0}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i=1,math.floor(level * 1.2 + 2) do
|
|
||||||
|
-- assign a random set of boxes random colors
|
||||||
|
for i=1,math.floor(level * 1.5 + 2) do
|
||||||
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?
|
||||||
@@ -37,7 +45,7 @@ local function nextLevel()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function equalColor(A, B)
|
local function colorsEqual(A, B)
|
||||||
if A[1] == B[1] and A[2] == B[2] and A[3] == B[3] then
|
if A[1] == B[1] and A[2] == B[2] and A[3] == B[3] then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@@ -48,12 +56,35 @@ local function copyColor(A)
|
|||||||
return {A[1], A[2], A[3]}
|
return {A[1], A[2], A[3]}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function game:enter(previous, settings)
|
||||||
|
-- save the state we came from
|
||||||
|
previousState = previous
|
||||||
|
-- set locals based on screen size
|
||||||
|
screenWidth = love.graphics.getWidth()
|
||||||
|
screenHeight = love.graphics.getHeight()
|
||||||
|
boxColumns = math.floor(screenWidth / boxSize) - 1
|
||||||
|
boxRows = math.floor(screenHeight / boxSize) - 5
|
||||||
|
-- set how to play the game based on settings
|
||||||
|
boxSize = settings.boxSize
|
||||||
|
colorStep = settings.colorStep
|
||||||
|
timeLimit = settings.timeLimit
|
||||||
|
-- set the font we're going to use
|
||||||
|
love.graphics.setNewFont(28)
|
||||||
|
-- this is nextLevel shit
|
||||||
|
nextLevel()
|
||||||
|
end
|
||||||
|
|
||||||
|
function game:resume(previous)
|
||||||
|
game:enter(previousState) --we want to keep the old values
|
||||||
|
totalScore = 0 --this should have happened in game:leave() but does not for an unknown reason
|
||||||
|
end
|
||||||
|
|
||||||
function game:update(dt)
|
function game:update(dt)
|
||||||
-- check if level complete
|
-- check if level complete
|
||||||
local coloredBoxes = {}
|
local coloredBoxes = {}
|
||||||
for i=0,#boxes do
|
for i=0,#boxes do
|
||||||
for j=0,#boxes[i] do
|
for j=0,#boxes[i] do
|
||||||
if not equalColor(boxes[i][j], {0, 0, 0}) then
|
if not colorsEqual(boxes[i][j], {0, 0, 0}) then
|
||||||
table.insert(coloredBoxes, boxes[i][j])
|
table.insert(coloredBoxes, boxes[i][j])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -63,19 +94,27 @@ function game:update(dt)
|
|||||||
won = true
|
won = true
|
||||||
color = copyColor(coloredBoxes[1])
|
color = copyColor(coloredBoxes[1])
|
||||||
for i=2,#coloredBoxes do
|
for i=2,#coloredBoxes do
|
||||||
if not equalColor(color, coloredBoxes[i]) then
|
if not colorsEqual(color, coloredBoxes[i]) then
|
||||||
won = false
|
won = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if won then
|
if won then
|
||||||
|
-- TODO we need a brief push/pop of gamestate to display a winning message
|
||||||
nextLevel()
|
nextLevel()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- else increment time
|
-- else decrement time, and check if out of time
|
||||||
time = time + dt
|
time = time - dt
|
||||||
|
if time <= 0 then
|
||||||
|
-- TODO we need to pass an image of the screen and data about time of losing
|
||||||
|
Gamestate.push(lost, love.graphics.newScreenshot())
|
||||||
|
-- call leave to clean up the gamestate
|
||||||
|
game:leave()
|
||||||
|
end
|
||||||
|
|
||||||
score = #coloredBoxes / math.pow(time, 0.02) * colorStep --difficulty
|
-- update the current score
|
||||||
|
score = #coloredBoxes / math.pow(startingTime - time, 0.02) * colorStep
|
||||||
end
|
end
|
||||||
|
|
||||||
function game:draw()
|
function game:draw()
|
||||||
@@ -90,39 +129,47 @@ function game:draw()
|
|||||||
--lines
|
--lines
|
||||||
-- vertical
|
-- vertical
|
||||||
love.graphics.setColor(255, 255, 255)
|
love.graphics.setColor(255, 255, 255)
|
||||||
for i=0,wAmount+1 do
|
for i=0,boxColumns+1 do
|
||||||
love.graphics.line(i * boxSize, 0 + boxSize * 2, i * boxSize, love.graphics.getHeight() - boxSize * 2)
|
love.graphics.line(i * boxSize, 0 + boxSize * 2, i * boxSize, screenHeight - boxSize * 2)
|
||||||
|
|
||||||
end
|
end
|
||||||
-- horizontal
|
-- horizontal
|
||||||
for j=0,hAmount+1 do
|
for j=0,boxRows+1 do
|
||||||
love.graphics.line(0, j * boxSize + boxSize * 2, love.graphics.getWidth(), j * boxSize + boxSize * 2)
|
love.graphics.line(0, j * boxSize + boxSize * 2, screenWidth, j * boxSize + boxSize * 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
--time elapsed
|
-- Info Overlays
|
||||||
love.graphics.setNewFont(28)
|
--love.graphics.setNewFont(28) --purposely stays same no matter screen res
|
||||||
love.graphics.setColor(255, 255, 255)
|
love.graphics.setColor(255, 255, 255)
|
||||||
love.graphics.printf(string.format("Total Score: %.1f", totalScore), 0, 3, 400, "center")
|
-- top of screen stuff
|
||||||
--love.graphics.printf(string.format("Best Score: %.1f", bestScore), 400, 3, 400, "center")
|
love.graphics.printf(string.format("Total Score: %.1f", totalScore), 0, 3, screenWidth / 2, "center")
|
||||||
love.graphics.printf(string.format("Time: %.1f", time), 0, 425, 400, "center")
|
--love.graphics.printf(string.format("Best Score: %.1f", bestScore), screenWidth / 2, 3, screenWidth / 2, "center")
|
||||||
love.graphics.printf(string.format("Level: %i", level), 0, 425, 800, "center")
|
|
||||||
love.graphics.printf(string.format("Score: %.1f", score), 400, 425, 400, "center")
|
-- bottom of screen stuff
|
||||||
|
love.graphics.printf(string.format("Time: %.1f", time), 0, screenWidth / 2 + 25, screenWidth / 2, "center")
|
||||||
|
love.graphics.printf("Level: "..level, 0, screenWidth / 2 + 25, screenWidth, "center")
|
||||||
|
love.graphics.printf(string.format("Current Score: %.1f", score), screenWidth / 2, screenWidth / 2 + 25, screenWidth / 2, "center")
|
||||||
end
|
end
|
||||||
|
|
||||||
function game:mousepressed(x, y, button)
|
function game:mousepressed(x, y, button)
|
||||||
|
-- new x/y adjusted for where boxes actually are
|
||||||
local nx = math.floor(x / boxSize)
|
local nx = math.floor(x / boxSize)
|
||||||
local ny = math.floor((y - boxSize * 2) / boxSize)
|
local ny = math.floor((y - boxSize * 2) / boxSize)
|
||||||
|
-- check if we are actually over a box first
|
||||||
if boxes[nx][ny] then
|
if boxes[nx][ny] then
|
||||||
|
-- left, red
|
||||||
if button == "l" then
|
if button == "l" then
|
||||||
boxes[nx][ny][1] = boxes[nx][ny][1] + colorStep
|
boxes[nx][ny][1] = boxes[nx][ny][1] + colorStep
|
||||||
if boxes[nx][ny][1] > 255 then
|
if boxes[nx][ny][1] > 255 then
|
||||||
boxes[nx][ny][1] = 0
|
boxes[nx][ny][1] = 0
|
||||||
end
|
end
|
||||||
|
-- middle, green
|
||||||
elseif button == "m" or button == "wu" or button == "wd" then
|
elseif button == "m" or button == "wu" or button == "wd" then
|
||||||
boxes[nx][ny][2] = boxes[nx][ny][2] + colorStep
|
boxes[nx][ny][2] = boxes[nx][ny][2] + colorStep
|
||||||
if boxes[nx][ny][2] > 255 then
|
if boxes[nx][ny][2] > 255 then
|
||||||
boxes[nx][ny][2] = 0
|
boxes[nx][ny][2] = 0
|
||||||
end
|
end
|
||||||
|
-- right, blue
|
||||||
elseif button == "r" then
|
elseif button == "r" then
|
||||||
boxes[nx][ny][3] = boxes[nx][ny][3] + colorStep
|
boxes[nx][ny][3] = boxes[nx][ny][3] + colorStep
|
||||||
if boxes[nx][ny][3] > 255 then
|
if boxes[nx][ny][3] > 255 then
|
||||||
@@ -132,13 +179,8 @@ function game:mousepressed(x, y, button)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local menuState
|
|
||||||
function game:enter(previous)
|
|
||||||
menuState = previous
|
|
||||||
nextLevel()
|
|
||||||
end
|
|
||||||
|
|
||||||
function game:leave()
|
function game:leave()
|
||||||
|
--double check the correctness of this
|
||||||
level = 0
|
level = 0
|
||||||
score = 0
|
score = 0
|
||||||
totalScore = 0
|
totalScore = 0
|
||||||
@@ -147,8 +189,7 @@ end
|
|||||||
|
|
||||||
function game:keypressed(key, unicode)
|
function game:keypressed(key, unicode)
|
||||||
if key == "escape" then
|
if key == "escape" then
|
||||||
--love.event.quit()
|
Gamestate.switch(previousState)
|
||||||
Gamestate.switch(menuState)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
39
src/lost.lua
Normal file
39
src/lost.lua
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
local lost = {}
|
||||||
|
|
||||||
|
local previousState, screenshot
|
||||||
|
|
||||||
|
function lost:enter(previous, screenImageData)
|
||||||
|
previousState = previous
|
||||||
|
screenshot = love.graphics.newImage(screenImageData)
|
||||||
|
love.graphics.setNewFont(40)
|
||||||
|
end
|
||||||
|
|
||||||
|
function lost:draw()
|
||||||
|
-- draw the screenshot
|
||||||
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
love.graphics.draw(screenshot)
|
||||||
|
-- draw a partial transparency black to fade out the screenshot
|
||||||
|
love.graphics.setColor(0, 0, 0, 200)
|
||||||
|
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
||||||
|
-- print info
|
||||||
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
love.graphics.printf("Game Over", 0, love.graphics.getHeight() / 2, love.graphics.getWidth(), "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")
|
||||||
|
|
||||||
|
-- bottom of screen stuff
|
||||||
|
love.graphics.printf(string.format("Time: %.1f", time), 0, screenWidth / 2 + 25, screenWidth / 2, "center")
|
||||||
|
love.graphics.printf("Level: "..level, 0, screenWidth / 2 + 25, screenWidth, "center")
|
||||||
|
love.graphics.printf(string.format("Current Score: %.1f", score), screenWidth / 2, screenWidth / 2 + 25, screenWidth / 2, "center")
|
||||||
|
]]
|
||||||
|
end
|
||||||
|
|
||||||
|
function lost:mousepressed(x, y, button)
|
||||||
|
if button == "l" then
|
||||||
|
Gamestate.pop()
|
||||||
|
--Gamestate.switch(previousState)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return lost
|
@@ -1,10 +1,14 @@
|
|||||||
local Gamestate = require "lib.gamestate"
|
Gamestate = require "lib.gamestate"
|
||||||
|
|
||||||
local menu = require "menu"
|
local menu = require "menu"
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
local icon = love.image.newImageData("icon.png")
|
local icon = love.image.newImageData("icon.png")
|
||||||
love.window.setIcon(icon)
|
love.window.setIcon(icon)
|
||||||
|
|
||||||
|
-- load settings and change if needed
|
||||||
|
--love.window.setMode(800, 460, {borderless = true}) --temporary
|
||||||
|
|
||||||
Gamestate.registerEvents()
|
Gamestate.registerEvents()
|
||||||
Gamestate.switch(menu)
|
Gamestate.switch(menu)
|
||||||
end
|
end
|
||||||
|
26
src/menu.lua
26
src/menu.lua
@@ -3,20 +3,28 @@ local game = require "game"
|
|||||||
|
|
||||||
local menu = {}
|
local menu = {}
|
||||||
|
|
||||||
|
local screenWidth, screenHeight
|
||||||
|
|
||||||
|
function menu:enter()
|
||||||
|
screenWidth = love.graphics.getWidth()
|
||||||
|
screenHeight = love.graphics.getHeight()
|
||||||
|
end
|
||||||
|
|
||||||
function menu:draw()
|
function menu:draw()
|
||||||
love.graphics.setNewFont(30)
|
love.graphics.setNewFont(30 * screenWidth / 800)
|
||||||
love.graphics.printf("RGB - The Color Chooser", 0, 100, 800, "center")
|
love.graphics.printf("RGB - The Color Chooser", 0, screenHeight / 7, screenWidth, "center")
|
||||||
love.graphics.setNewFont(16)
|
love.graphics.setNewFont(16 * screenWidth / 800)
|
||||||
love.graphics.printf("1. Left click to cycle red.\n2. Middle click or scroll to cycle green.\n3. Right click to cycle blue.", 0, 200, 800, "center")
|
love.graphics.printf("1. Left click to cycle red.\n2. Middle click or scroll to cycle green.\n3. Right click to cycle blue.", 0, screenHeight / 3, screenWidth, "center")
|
||||||
love.graphics.printf("Your goal is to get every panel that is not black to be the same color.", 0, 300, 800, "center")
|
love.graphics.printf("Your goal is to get every panel that is not black to be the same color.", 0, screenHeight / 1.75, screenWidth, "center")
|
||||||
love.graphics.printf("Click to begin.", 0, 350, 800, "center")
|
love.graphics.printf("Click to begin.", 0, screenHeight / 1.3, screenWidth, "center")
|
||||||
love.graphics.setNewFont(12)
|
love.graphics.setNewFont(12 * screenWidth / 800)
|
||||||
love.graphics.printf("(Esc exits the game.)", 0, 440, 800, "center")
|
love.graphics.printf("(Esc exits the game.)", 0, screenHeight - 20 * screenHeight / 400, screenWidth, "center")
|
||||||
end
|
end
|
||||||
|
|
||||||
function menu:mousepressed(x, y, button)
|
function menu:mousepressed(x, y, button)
|
||||||
if button == "l" then
|
if button == "l" then
|
||||||
Gamestate.switch(game)
|
-- TODO replace constructed settings object with actual loaded settings
|
||||||
|
Gamestate.switch(game, {boxSize = 20, colorStep = 80, timeLimit = 10})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user