This commit is contained in:
Paul Liverman
2015-02-06 22:48:33 -08:00
commit 5e86090bf1
14 changed files with 424 additions and 0 deletions

54
LICENSE Normal file
View File

@@ -0,0 +1,54 @@
Copyright (c) 2015 Paul Liverman III
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
Except as contained in this notice, the name(s) of the above copyright holders
shall not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Additionally, this work uses content by Matthias Richter, specifically
hump.gamestate, for more information about hump.gamestate, see
https://vrld.github.io/hump/#hump.gamestate
Below is the license for hump.gamestate:
Copyright (c) 2010-2013 Matthias Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
Except as contained in this notice, the name(s) of the above copyright holders
shall not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

2
run src.bat Normal file
View File

@@ -0,0 +1,2 @@
@ECHO OFF
"C:\Program Files\LOVE\love.exe" "%cd%/src"

BIN
screenshots/FINALLY.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

16
src/conf.lua Normal file
View File

@@ -0,0 +1,16 @@
function love.conf(t)
t.identity = "RGB"
t.version = "0.9.1"
--t.author = "Guard13007"
t.console = true
t.window = {}
t.window.title = "RGB - The Color Chooser"
t.window.width = 800
t.window.height = 460
t.window.borderless = true
--t.modules = {}
t.modules.joystick = false
t.modules.physics = false
end

157
src/game.lua Normal file
View File

@@ -0,0 +1,157 @@
love.math.setRandomSeed(os.time())
local Gamestate = require "lib.gamestate"
local game = {}
local boxes = {}
local boxSize = 20
local wAmount = math.floor(love.graphics.getWidth() / boxSize) - 1
local hAmount = math.floor(love.graphics.getHeight() / boxSize) - 5
local level = 0
local score = 0
local totalScore = 0
local time = 0
local colorStep = 80 -- difficulty setting
local function nextLevel()
totalScore = totalScore + score
level = level + 1
score = 0
time = 0
-- initial black boxes
for i=0,wAmount do
boxes[i] = {}
for j=0,hAmount do
boxes[i][j] = {0, 0, 0}
end
end
for i=1,math.floor(level * 1.2 + 2) do
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][1] = boxes[x][y][1] - boxes[x][y][1] % colorStep --is this right?
boxes[x][y][2] = boxes[x][y][2] - boxes[x][y][2] % colorStep
boxes[x][y][3] = boxes[x][y][3] - boxes[x][y][3] % colorStep
end
end
local function equalColor(A, B)
if A[1] == B[1] and A[2] == B[2] and A[3] == B[3] then
return true
end
return false
end
local function copyColor(A)
return {A[1], A[2], A[3]}
end
function game:update(dt)
print(os.time())
-- check if level complete
local coloredBoxes = {}
for i=0,#boxes do
for j=0,#boxes[i] do
if not equalColor(boxes[i][j], {0, 0, 0}) then
table.insert(coloredBoxes, boxes[i][j])
end
end
end
local won, color
if #coloredBoxes >= 2 then
won = true
color = copyColor(coloredBoxes[1])
for i=2,#coloredBoxes do
if not equalColor(color, coloredBoxes[i]) then
won = false
end
end
end
if won then
nextLevel()
end
-- else increment time
time = time + dt
score = #coloredBoxes / math.pow(time, 0.02) * colorStep --difficulty
end
function game:draw()
--boxes
for i=0,#boxes do
for j=0,#boxes[i] do
love.graphics.setColor(boxes[i][j])
love.graphics.rectangle("fill", i * boxSize, j * boxSize + boxSize * 2, boxSize, boxSize)
end
end
--lines
-- vertical
love.graphics.setColor(255, 255, 255)
for i=0,wAmount+1 do
love.graphics.line(i * boxSize, 0 + boxSize * 2, i * boxSize, love.graphics.getHeight() - boxSize * 2)
end
-- horizontal
for j=0,hAmount+1 do
love.graphics.line(0, j * boxSize + boxSize * 2, love.graphics.getWidth(), j * boxSize + boxSize * 2)
end
--time elapsed
love.graphics.setNewFont(28)
love.graphics.setColor(255, 255, 255)
love.graphics.printf(string.format("Total Score: %.1f", totalScore), 0, 3, 400, "center")
--love.graphics.printf(string.format("Best Score: %.1f", bestScore), 400, 3, 400, "center")
love.graphics.printf(string.format("Time: %.1f", time), 0, 425, 400, "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")
end
function game:mousepressed(x, y, button)
print(button) --debug
local nx = math.floor(x / boxSize)
local ny = math.floor((y - boxSize * 2) / boxSize)
if boxes[nx][ny] then
if button == "l" then
boxes[nx][ny][1] = boxes[nx][ny][1] + colorStep
if boxes[nx][ny][1] > 255 then
boxes[nx][ny][1] = 0
end
elseif button == "m" or button == "wu" or button == "wd" then
boxes[nx][ny][2] = boxes[nx][ny][2] + colorStep
if boxes[nx][ny][2] > 255 then
boxes[nx][ny][2] = 0
end
elseif button == "r" then
boxes[nx][ny][3] = boxes[nx][ny][3] + colorStep
if boxes[nx][ny][3] > 255 then
boxes[nx][ny][3] = 0
end
end
end
end
local menuState
function game:enter(previous)
menuState = previous
nextLevel()
end
function game:leave()
level = 0
score = 0
totalScore = 0
time = 0
end
function game:keypressed(key, unicode)
if key == "escape" then
--love.event.quit()
Gamestate.switch(menuState)
end
end
return game

97
src/lib/gamestate.lua Normal file
View File

@@ -0,0 +1,97 @@
--[[
Copyright (c) 2010-2013 Matthias Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
Except as contained in this notice, the name(s) of the above copyright holders
shall not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
]]--
local function __NULL__() end
-- default gamestate produces error on every callback
local state_init = setmetatable({leave = __NULL__},
{__index = function() error("Gamestate not initialized. Use Gamestate.switch()") end})
local stack = {state_init}
local GS = {}
function GS.new(t) return t or {} end -- constructor - deprecated!
function GS.switch(to, ...)
assert(to, "Missing argument: Gamestate to switch to")
assert(to ~= GS, "Can't call switch with colon operator")
local pre = stack[#stack]
;(pre.leave or __NULL__)(pre)
;(to.init or __NULL__)(to)
to.init = nil
stack[#stack] = to
return (to.enter or __NULL__)(to, pre, ...)
end
function GS.push(to, ...)
assert(to, "Missing argument: Gamestate to switch to")
assert(to ~= GS, "Can't call push with colon operator")
local pre = stack[#stack]
;(to.init or __NULL__)(to)
to.init = nil
stack[#stack+1] = to
return (to.enter or __NULL__)(to, pre, ...)
end
function GS.pop(...)
assert(#stack > 1, "No more states to pop!")
local pre, to = stack[#stack], stack[#stack-1]
stack[#stack] = nil
;(pre.leave or __NULL__)(pre)
return (to.resume or __NULL__)(to, pre, ...)
end
function GS.current()
return stack[#stack]
end
local all_callbacks = {
'draw', 'errhand', 'focus', 'keypressed', 'keyreleased', 'mousefocus',
'mousepressed', 'mousereleased', 'quit', 'resize', 'textinput',
'threaderror', 'update', 'visible', 'gamepadaxis', 'gamepadpressed',
'gamepadreleased', 'joystickadded', 'joystickaxis', 'joystickhat',
'joystickpressed', 'joystickreleased', 'joystickremoved'
}
function GS.registerEvents(callbacks)
local registry = {}
callbacks = callbacks or all_callbacks
for _, f in ipairs(callbacks) do
registry[f] = love[f] or __NULL__
love[f] = function(...)
registry[f](...)
return GS[f](...)
end
end
end
-- forward any undefined functions
setmetatable(GS, {__index = function(_, func)
return function(...)
return (stack[#stack][func] or __NULL__)(stack[#stack], ...)
end
end})
return GS

7
src/main.lua Normal file
View File

@@ -0,0 +1,7 @@
local Gamestate = require "lib.gamestate"
local menu = require "menu"
function love.load()
Gamestate.registerEvents()
Gamestate.switch(menu)
end

29
src/menu.lua Normal file
View File

@@ -0,0 +1,29 @@
local Gamestate = require "lib.gamestate"
local game = require "game"
local menu = {}
function menu:draw()
love.graphics.setNewFont(30)
love.graphics.printf("RGB - The Color Chooser", 0, 100, 800, "center")
love.graphics.setNewFont(16)
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("Your goal is to get every panel that is not black to be the same color.", 0, 300, 800, "center")
love.graphics.printf("Click to begin.", 0, 350, 800, "center")
love.graphics.setNewFont(12)
love.graphics.printf("(Esc exits the game.)", 0, 440, 800, "center")
end
function menu:mousepressed(x, y, button)
if button == "l" then
Gamestate.switch(game)
end
end
function menu:keypressed(key, unicode)
if key == "escape" then
love.event.quit()
end
end
return menu

62
src/original.lua Normal file
View File

@@ -0,0 +1,62 @@
local game = {}
local boxes = {}
local boxSize = 20
local wAmount = math.floor(love.graphics.getWidth() / boxSize)
local hAmount = math.floor(love.graphics.getHeight() / boxSize)
-- initial black boxes
for i=0,wAmount do
boxes[i] = {}
for j=0,hAmount do
boxes[i][j] = {0, 0, 0}
end
end
function game:draw()
--boxes
for i=0,#boxes do
for j=0,#boxes[i] do
love.graphics.setColor(boxes[i][j])
love.graphics.rectangle("fill", i * boxSize, j * boxSize, boxSize, boxSize)
end
end
--lines
love.graphics.setColor(255, 255, 255)
for i=0,wAmount do
love.graphics.line(i * boxSize, 0, i * boxSize, love.graphics.getHeight())
end
for j=0,hAmount do
love.graphics.line(0, j * boxSize, love.graphics.getWidth(), j * boxSize)
end
end
function game:mousepressed(x, y, button)
print(button) --debug
if button == "l" then
boxes[math.floor(x / boxSize)][math.floor(y / boxSize)][1] = boxes[math.floor(x / boxSize)][math.floor(y / boxSize)][1] + 40
if boxes[math.floor(x / boxSize)][math.floor(y / boxSize)][1] > 255 then
boxes[math.floor(x / boxSize)][math.floor(y / boxSize)][1] = 0
end
elseif button == "m" or button == "wu" or button == "wd" then
boxes[math.floor(x / boxSize)][math.floor(y / boxSize)][2] = boxes[math.floor(x / boxSize)][math.floor(y / boxSize)][2] + 40
if boxes[math.floor(x / boxSize)][math.floor(y / boxSize)][2] > 255 then
boxes[math.floor(x / boxSize)][math.floor(y / boxSize)][2] = 0
end
elseif button == "r" then
boxes[math.floor(x / boxSize)][math.floor(y / boxSize)][3] = boxes[math.floor(x / boxSize)][math.floor(y / boxSize)][3] + 40
if boxes[math.floor(x / boxSize)][math.floor(y / boxSize)][3] > 255 then
boxes[math.floor(x / boxSize)][math.floor(y / boxSize)][3] = 0
end
end
end
function game:keypressed(key, unicode)
if key == "escape" then
love.event.quit()
end
end
return game