aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2014-04-16 22:59:56 +0200
committerpiernov <piernov@piernov.org>2014-04-16 22:59:56 +0200
commit7ae446b661c47b41ed38d7f88b8f54416575e47f (patch)
tree4e95b54230b5e468f16a22bbe3bc2174a1d622d8
parent8ce1e6f75a68f5d92fe4bf27263a861c16e71f35 (diff)
downloadMastermind-7ae446b661c47b41ed38d7f88b8f54416575e47f.tar.gz
Mastermind-7ae446b661c47b41ed38d7f88b8f54416575e47f.tar.bz2
Mastermind-7ae446b661c47b41ed38d7f88b8f54416575e47f.tar.xz
Mastermind-7ae446b661c47b41ed38d7f88b8f54416575e47f.zip
Split file + Working Solo mode :
Add hints + Disallow multiple identical colors in same line + Correctly randomize answer
-rw-r--r--GUI/Common.lua30
-rw-r--r--GUI/InGame.lua106
-rw-r--r--GUI/Menu.lua8
-rw-r--r--Gamestates/Init.lua4
-rw-r--r--Gamestates/Menu.lua21
-rw-r--r--Gamestates/Multiplayer.lua0
-rw-r--r--Gamestates/Solo.lua106
-rw-r--r--Utils.lua9
-rw-r--r--main.lua152
9 files changed, 292 insertions, 144 deletions
diff --git a/GUI/Common.lua b/GUI/Common.lua
new file mode 100644
index 0000000..5b62ed1
--- /dev/null
+++ b/GUI/Common.lua
@@ -0,0 +1,30 @@
+local GUI = {}
+
+function GUI.drawPolygon(polygon)
+ if polygon.Colors then
+ love.graphics.setColor(unpack(polygon.Colors))
+ end
+
+ if polygon.LineWidth then
+ love.graphics.setLineWidth(polygon.LineWidth*(Window.width+Window.height)/2)
+ end
+
+ if polygon.Type == "rectangle" then
+ love.graphics.rectangle(polygon.DrawMode, polygon.Position.x*Window.width, polygon.Position.y*Window.height,
+ polygon.Dimension.width*Window.width, polygon.Dimension.height*Window.height)
+
+ elseif polygon.Type == "polygon" then
+ love.graphics.polygon(polygon.DrawMode, polygon.Position.x1*Window.width, polygon.Position.y1*Window.height,
+ polygon.Position.x2*Window.width, polygon.Position.y2*Window.height,
+ polygon.Position.x3*Window.width, polygon.Position.y3*Window.height,
+ polygon.Position.x4*Window.width, polygon.Position.y4*Window.height)
+
+ elseif polygon.Type == "line" then
+ love.graphics.line(polygon.Position.x1*Window.width, polygon.Position.y1*Window.height,
+ polygon.Position.x2*Window.width, polygon.Position.y2*Window.height)
+ elseif polygon.Type == "print" then
+ love.graphics.print(polygon.Text, polygon.Position.x*Window.width, polygon.Position.y*Window.height)
+ end
+end
+
+return GUI
diff --git a/GUI/InGame.lua b/GUI/InGame.lua
new file mode 100644
index 0000000..1908894
--- /dev/null
+++ b/GUI/InGame.lua
@@ -0,0 +1,106 @@
+local InGame = {}
+
+InGame.Polygons = {}
+
+InGame.Colors = { {255, 0, 0, 255}, {255, 128, 0, 255}, {255, 255, 0, 255}, {0, 255, 0, 255}, {128, 128, 128, 255}, {255, 255, 255, 255} }
+
+function InGame.drawPolygon(polygon)
+ if polygon.Colors then
+ love.graphics.setColor(unpack(polygon.Colors))
+ end
+
+ if polygon.LineWidth then
+ love.graphics.setLineWidth(polygon.LineWidth*(Screen.width+Screen.height)/2)
+ end
+
+ if polygon.Type == "rectangle" then
+ love.graphics.rectangle(polygon.DrawMode, polygon.Position.x*Screen.width, polygon.Position.y*Screen.height,
+ polygon.Dimension.width*Screen.width, polygon.Dimension.height*Screen.height)
+
+ elseif polygon.Type == "polygon" then
+ love.graphics.polygon(polygon.DrawMode, polygon.Position.x1*Screen.width, polygon.Position.y1*Screen.height,
+ polygon.Position.x2*Screen.width, polygon.Position.y2*Screen.height,
+ polygon.Position.x3*Screen.width, polygon.Position.y3*Screen.height,
+ polygon.Position.x4*Screen.width, polygon.Position.y4*Screen.height)
+
+ elseif polygon.Type == "line" then
+ love.graphics.line(polygon.Position.x1*Screen.width, polygon.Position.y1*Screen.height,
+ polygon.Position.x2*Screen.width, polygon.Position.y2*Screen.height)
+ elseif polygon.Type == "print" then
+ love.graphics.print(polygon.Text, polygon.Position.x*Screen.width, polygon.Position.y*Screen.height)
+ end
+end
+
+function InGame.loadInterface()
+ love.graphics.setBackgroundColor(0, 0, 0)
+
+ -- Inner Window border
+ table.insert(InGame.Polygons, { Type = "rectangle", DrawMode = "line", LineWidth = 0.005, Position = { x = 0.005, y = 0.005}, Dimension = {width = 0.99, height = 0.99}, Colors = {0, 0, 171, 255} })
+
+ -- Background
+ for i = 0, 5 do
+ table.insert(InGame.Polygons, { Type = "polygon", DrawMode = "fill", Position = { x1 = 0.01, y1 = 0.02+0.02*i, x2 = 0.02+0.02*i, y2 = 0.01, x3 = 0.03+0.02*i, y3 = 0.01, x4 = 0.01, y4 = 0.03+0.02*i}, Colors = {0, 0, 171, 255} })
+ table.insert(InGame.Polygons, { Type = "polygon", DrawMode = "fill", Position = { x1 = 0.99, y1 = 0.98-0.02*i, x2 = 0.98-0.02*i, y2 = 0.99, x3 = 0.97-0.02*i, y3 = 0.99, x4 = 0.99, y4 = 0.97-0.02*i}, Colors = {0, 0, 171, 255} })
+ end
+
+ -- Left box
+ table.insert(InGame.Polygons, { Type = "rectangle", DrawMode = "fill", Position = { x = 0.05, y = 0.05}, Dimension = {width = 0.35, height = 0.90}, Colors = {0, 0, 0, 255} })
+ table.insert(InGame.Polygons, { Type = "rectangle", DrawMode = "line", Position = { x = 0.05, y = 0.05}, Dimension = {width = 0.35, height = 0.90}, Colors = {0, 0, 171, 255} })
+ table.insert(InGame.Polygons, { Type = "line", Position = { x1 = 0.05, y1 = 0.1, x2 = 0.4, y2 = 0.1}, Colors = {0, 0, 171, 255} })
+
+ -- Left box buttons
+ table.insert(InGame.Polygons, { Type = "rectangle", DrawMode = "line", Position = { x = 0.075, y = 0.875}, Dimension = {width = 0.125, height = 0.05}, Colors = {0, 0, 171, 255} })
+ table.insert(InGame.Polygons, { Type = "rectangle", DrawMode = "line", Position = { x = 0.25, y = 0.875}, Dimension = {width = 0.125, height = 0.05}, Colors = {0, 0, 171, 255} })
+
+ -- Left box content
+ table.insert(InGame.Polygons, { Type = "line", LineWidth = 0.01, Position = { x1 = 0.375, y1 = 0.15-0.005, x2 = 0.375, y2 = 0.75}, Colors = {0, 0, 171, 255} })
+
+ -- Right top box
+ table.insert(InGame.Polygons, { Type = "rectangle", LineWidth = 0.005, DrawMode = "line", Position = { x = 0.45, y = 0.05}, Dimension = {width = 0.50, height = 0.75}, Colors = {0, 0, 171, 255} })
+ table.insert(InGame.Polygons, { Type = "line", Position = { x1 = 0.45, y1 = 0.1, x2 = 0.95, y2 = 0.1}, Colors = {0, 0, 171, 255} })
+
+ -- Right top box content
+ table.insert(InGame.Polygons, { Type = "line", LineWidth = 0.01, Position = { x1 = 0.375-0.0025, y1 = 0.75, x2 = 0.52+5*0.075+0.0025, y2 = 0.75}, Colors = {0, 0, 171, 255} })
+ table.insert(InGame.Polygons, { Type = "line", LineWidth = 0.01, Position = { x1 = 0.475, y1 = 0.75, x2 = 0.475, y2 = 0.15-0.0025}, Colors = {0, 0, 171, 255} })
+ table.insert(InGame.Polygons, { Type = "line", LineWidth = 0.01, Position = { x1 = 0.9, y1 = 0.15-0.0025, x2 = 0.9, y2 = 0.7}, Colors = {0, 0, 171, 255} })
+ table.insert(InGame.Polygons, { Type = "line", LineWidth = 0.03, Position = { x1 = 0.795, y1 = 0.7-0.01, x2 = 0.9+0.005, y2 = 0.7-0.01}, Colors = {0, 0, 171, 255} })
+ table.insert(InGame.Polygons, { Type = "rectangle", LineWidth = 0.01, DrawMode = "line", Position = { x = 0.52, y = 0.66}, Dimension = {width = 0.275, height = 0.05}, Colors = {0, 0, 171, 255} })
+
+ for j = 0, 6 do
+ table.insert(InGame.Polygons, { Type = "line", LineWidth = 0.005, Position = { x1 = 0.77, y1 = 0.15+j*0.075, x2 = 0.785, y2 = 0.15+j*0.075}, Colors = {0, 0, 171, 255} })
+ table.insert(InGame.Polygons, { Type = "line", LineWidth = 0.005, Position = { x1 = 0.785, y1 = 0.1275+j*0.075-0.0005, x2 = 0.785, y2 = 0.1725+j*0.075+0.0005}, Colors = {0, 0, 171, 255} })
+ table.insert(InGame.Polygons, { Type = "line", LineWidth = 0.005, Position = { x1 = 0.86, y1 = 0.1275+j*0.075, x2 = 0.86, y2 = 0.1725+j*0.075}, Colors = {0, 0, 171, 255} })
+ table.insert(InGame.Polygons, { Type = "line", LineWidth = 0.005, Position = { x1 = 0.86, y1 = 0.15+j*0.075, x2 = 0.9, y2 = 0.15+j*0.075}, Colors = {0, 0, 171, 255} })
+
+ for i = 0, 3 do
+ table.insert(InGame.Polygons, { Type = "rectangle", LineWidth = 0.01, DrawMode = "line", Position = { x = 0.497+i*0.075, y = 0.12+j*0.075}, Dimension = {width = 0.045, height = 0.05}, Colors = {0, 0, 171, 255} })
+ table.insert(InGame.Polygons, { Type = "line", LineWidth = 0.01, Position = { x1 = 0.471+i*0.075, y1 = 0.15+j*0.075, x2 = 0.497+i*0.075, y2 = 0.15+j*0.075}, Colors = {0, 0, 171, 255} })
+ end
+
+ for k = 0, 1 do
+ for l = 0, 1 do
+ table.insert(InGame.Polygons, { Type = "rectangle", LineWidth = 0.0025, DrawMode = "line", Position = { x = 0.795+k*0.0325, y = 0.12+l*0.0325+j*0.075}, Dimension = {width = 0.0225, height = 0.025}, Colors = {0, 0, 171, 255} })
+ end
+
+ for m = 0, 2 do
+ table.insert(InGame.Polygons, { Type = "line", LineWidth = 0.0025, Position = { x1 = 0.785+m*0.0325, y1 = 0.1275+k*0.045+j*0.075, x2 = 0.795+m*0.0325, y2 = 0.1275+k*0.045+j*0.075}, Colors = {0, 0, 171, 255} })
+ end
+ end
+ end
+
+ -- Right bottom box
+ table.insert(InGame.Polygons, { Type = "rectangle", LineWidth = 0.005, DrawMode = "fill", Position = { x = 0.45, y = 0.85}, Dimension = {width = 0.50, height = 0.10}, Colors = {0, 0, 0, 255} })
+ table.insert(InGame.Polygons, { Type = "rectangle", DrawMode = "line", Position = { x = 0.45, y = 0.85}, Dimension = {width = 0.50, height = 0.10}, Colors = {0, 0, 171, 255} })
+
+ -- Right bottom box buttons
+ for i = 0, 5 do
+ table.insert(InGame.Polygons, { Type = "rectangle", DrawMode = "fill", Position = { x = 0.50+i*0.075, y = 0.875}, Dimension = {width = 0.04, height = 0.04}, Colors = InGame.Colors[i+1] })
+ table.insert(InGame.Polygons, { Type = "rectangle", DrawMode = "line", LineWidth = 0.01, Position = { x = 0.50+i*0.075, y = 0.875}, Dimension = {width = 0.04, height = 0.04}, Colors = {0, 0, 171, 255} })
+ table.insert(InGame.Polygons, { Type = "line", Position = { x1 = 0.52+i*0.075, y1 = 0.75, x2 = 0.52+i*0.075, y2 = 0.875}, Colors = {0, 0, 171, 255} })
+ if i < 5 then
+ table.insert(InGame.Polygons, { Type = "line", Position = { x1 = 0.5+i*0.075+0.04, y1 = 0.895, x2 = 0.52+(i+1)*0.075, y2 = 0.895}, Colors = {0, 0, 171, 255} })
+ end
+ end
+end
+
+return InGame
diff --git a/GUI/Menu.lua b/GUI/Menu.lua
new file mode 100644
index 0000000..29f3386
--- /dev/null
+++ b/GUI/Menu.lua
@@ -0,0 +1,8 @@
+return {
+ Buttons = {
+ "Solo",
+ "Multiplayer",
+ "Options",
+ "About"
+ }
+}
diff --git a/Gamestates/Init.lua b/Gamestates/Init.lua
new file mode 100644
index 0000000..5f42661
--- /dev/null
+++ b/Gamestates/Init.lua
@@ -0,0 +1,4 @@
+return {
+ Solo = require("Gamestates/Solo"),
+ Multiplayer = require("Gamestates/Multiplayer")
+}
diff --git a/Gamestates/Menu.lua b/Gamestates/Menu.lua
new file mode 100644
index 0000000..7e82857
--- /dev/null
+++ b/Gamestates/Menu.lua
@@ -0,0 +1,21 @@
+local Menu = {}
+local Gui = require "Quickie"
+local Utils = require "Utils"
+local GUI = { Menu = require("GUI/Menu")}
+local Gamestates = require "Gamestates/Init"
+
+function Menu:update(dt)
+ Gui.group{grow = "down", pos = {Utils.percentCoordinates(10, 10)}, function()
+ for _, name in ipairs(GUI.Menu.Buttons) do
+ if Gui.Button{text = name, size = {Utils.percentCoordinates(80, 10)}} then
+ Gamestate.switch(Gamestates[name])
+ end
+ end
+ end}
+end
+
+function Menu:draw()
+ Gui.core.draw()
+end
+
+return Menu
diff --git a/Gamestates/Multiplayer.lua b/Gamestates/Multiplayer.lua
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Gamestates/Multiplayer.lua
diff --git a/Gamestates/Solo.lua b/Gamestates/Solo.lua
new file mode 100644
index 0000000..8d50ad6
--- /dev/null
+++ b/Gamestates/Solo.lua
@@ -0,0 +1,106 @@
+local GUI = { InGame = require("GUI/InGame")}
+
+local Solo = {}
+
+Solo.Keypressed = {{}}
+Solo.Answer = {}
+Solo.Hints = {}
+
+
+function Solo:checkKeys()
+ local found = true
+ Solo.Hints[#Solo.Hints+1] = {}
+
+ for id, num in ipairs(Solo.Keypressed[#Solo.Keypressed]) do
+ if num == Solo.Answer[id] then -- Right
+ table.insert(Solo.Hints[#Solo.Hints], { Type = "rectangle", LineWidth = 0.0025, DrawMode = "fill",
+ Position = { x = 0.795+((#Solo.Hints[#Solo.Hints]-1)%2)*0.0325, y = 0.12+math.floor(#Solo.Hints[#Solo.Hints]/2)*0.0325+(#Solo.Keypressed-1)*0.075},
+ Dimension = {width = 0.0225, height = 0.025}, Colors = {0, 0, 171, 255} })
+ else -- Misplaced or Wrong
+ found = false
+
+ for k,v in ipairs(Solo.Answer) do
+ if num == v then -- Misplaced
+ table.insert(Solo.Hints[#Solo.Hints], { Type = "rectangle", LineWidth = 0.0025, DrawMode = "fill",
+ Position = { x = 0.795+((#Solo.Hints[#Solo.Hints]-1)%2)*0.0325, y = 0.12+math.floor(#Solo.Hints[#Solo.Hints]/2)*0.0325+(#Solo.Keypressed-1)*0.075},
+ Dimension = {width = 0.0225, height = 0.025}, Colors = {171, 171, 171, 255} })
+ end
+ end
+ end
+ end
+
+ return found
+end
+
+function Solo:init()
+ GUI.InGame.loadInterface()
+ tmpanswer = { 1, 2, 3, 4, 5, 6 }
+
+ if not love.getVersion then -- Check if LÖVE is older than 0.9.1, getVersion() introduced in version 0.9.1
+ love.math.random() -- Throw first value since it's not random in LÖVE 0.9.0
+ end
+
+ while #Solo.Answer < 4 do
+ local n = love.math.random(#tmpanswer)
+ table.insert(Solo.Answer, tmpanswer[n])
+ table.remove(tmpanswer, n) -- table.insert(GUI.InGame.Polygons, { Type = "print", Text = n, Position = {x = 0.1+i*0.01, y = 0.5}, Colors = {255, 255, 255, 255}})
+ end
+
+ -- Debug
+ for k,v in ipairs(Solo.Answer) do
+ print(k,v)
+ table.insert(GUI.InGame.Polygons, { Type = "print", Text = v, Position = {x = 0.1+k*0.01, y = 0.5}, Colors = {255, 255, 255, 255}})
+ end
+end
+
+function Solo:draw()
+ for id, polygon in ipairs(GUI.InGame.Polygons) do
+ GUI.InGame.drawPolygon(polygon)
+ end
+
+ for num, line in ipairs(Solo.Hints) do
+ for k, poly in ipairs(line) do
+ GUI.InGame.drawPolygon(poly)
+ end
+ end
+
+ for line, keys in ipairs(Solo.Keypressed) do
+ for id, num in ipairs(keys) do
+ GUI.InGame.drawPolygon({ Type = "rectangle", DrawMode = "fill", Position = { x = 0.50+(id-1)*0.075, y = 0.15+(line-1)*0.075-0.025}, Dimension = {width = 0.04, height = 0.04}, Colors = GUI.InGame.Colors[num] })
+ end
+ end
+end
+
+function Solo:mousepressed(x, y, b)
+ x = x/Screen.width
+ y = y/Screen.height
+ if 0.875 < y and y < 0.915 then
+ if x > 0.45 then
+ for i = 0,5 do
+ if 0.50+i*0.075 < x and x < 0.50+i*0.075+0.04 then
+ if #Solo.Keypressed > 7 or #Solo.Keypressed[#Solo.Keypressed] >= 4 then
+ return
+ else
+ for k,v in pairs(Solo.Keypressed[#Solo.Keypressed]) do
+ if v == i+1 then
+ return -- Disallow multiple identical colors in same line
+ end
+ end
+
+ table.insert(Solo.Keypressed[#Solo.Keypressed], i+1)
+ end
+ end
+ end
+ elseif 0.25 < x and x < 0.375 and #Solo.Keypressed <= 7 and #Solo.Keypressed[#Solo.Keypressed] == 4 then
+ if Solo.checkKeys() then
+ table.insert(GUI.InGame.Polygons, { Type = "print", Text = "FOUND !", Position = {x = 0.5, y = 0.5}, Colors = {255, 255, 255, 255}})
+ else
+ Solo.Keypressed[#Solo.Keypressed+1] = {}
+ end
+ elseif #Solo.Keypressed <= 7 and 0.075 < x and x < 0.200 and #Solo.Keypressed[#Solo.Keypressed] > 0 then
+ Solo.Keypressed[#Solo.Keypressed] = {}
+ end
+ end
+end
+
+return Solo
diff --git a/Utils.lua b/Utils.lua
new file mode 100644
index 0000000..c811e1b
--- /dev/null
+++ b/Utils.lua
@@ -0,0 +1,9 @@
+local Utils = {}
+
+function Utils.percentCoordinates(x, y)
+ x = (x/100)*Screen.width
+ y = (y/100)*Screen.height
+ return x, y
+end
+
+return Utils \ No newline at end of file
diff --git a/main.lua b/main.lua
index aef7a80..48eb910 100644
--- a/main.lua
+++ b/main.lua
@@ -1,155 +1,19 @@
require 'love2d-fakecanvas/fakecanvas'
-local Window = {}
-local colors = { {255, 0, 0, 255}, {255, 128, 0, 255}, {255, 255, 0, 255}, {0, 255, 0, 255}, {128, 128, 128, 255}, {255, 255, 255, 255} }
-local Polygons = {}
-local Keypressed = {{}}
-local Answer = {}
-local Hints = {}
+Screen = {}
-local function checkKeys()
- local ansfound = true
- local tmpans = {}
- for k,v in ipairs(Answer) do table.insert(tmpans, v) end
- local goodnum = 0
- for id, num in ipairs(Keypressed[#Keypressed]) do
- for j, answer in ipairs(tmpans) do
- if num == answer and id == j then
- goodnum = 2
- tmpans[j] = -1
- elseif num == answer and goodnum < 1 then
- goodnum = 1
- tmpans[j] = -1
- end
- end
- if goodnum < 2 then ansfound = false end
- table.insert(Hints, { Type = "print", Text = goodnum, Position = { x = 0.1 + id*0.05, y = 0.1+#Keypressed*0.05 }, Colors = { 255, 255, 255, 255}})
- goodnum = 0
- end
- return ansfound
-end
+Gamestate = require "hump.gamestate"
+Menu = require "Gamestates/Menu"
function love.load()
- love.graphics.setBackgroundColor(0, 0, 0)
-
- -- Inner window border
- table.insert(Polygons, { Type = "rectangle", DrawMode = "line", LineWidth = 0.005, Position = { x = 0.005, y = 0.005}, Dimension = {width = 0.99, height = 0.99}, Colors = {0, 0, 171, 255} })
-
- -- Background
- for i = 0, 5 do
- table.insert(Polygons, { Type = "polygon", DrawMode = "fill", Position = { x1 = 0.01, y1 = 0.02+0.02*i, x2 = 0.02+0.02*i, y2 = 0.01, x3 = 0.03+0.02*i, y3 = 0.01, x4 = 0.01, y4 = 0.03+0.02*i}, Colors = {0, 0, 171, 255} })
- table.insert(Polygons, { Type = "polygon", DrawMode = "fill", Position = { x1 = 0.99, y1 = 0.98-0.02*i, x2 = 0.98-0.02*i, y2 = 0.99, x3 = 0.97-0.02*i, y3 = 0.99, x4 = 0.99, y4 = 0.97-0.02*i}, Colors = {0, 0, 171, 255} })
- end
-
- -- Left box
- table.insert(Polygons, { Type = "rectangle", DrawMode = "fill", Position = { x = 0.05, y = 0.05}, Dimension = {width = 0.35, height = 0.90}, Colors = {0, 0, 0, 255} })
- table.insert(Polygons, { Type = "rectangle", DrawMode = "line", Position = { x = 0.05, y = 0.05}, Dimension = {width = 0.35, height = 0.90}, Colors = {0, 0, 171, 255} })
- table.insert(Polygons, { Type = "line", Position = { x1 = 0.05, y1 = 0.1, x2 = 0.4, y2 = 0.1}, Colors = {0, 0, 171, 255} })
-
- -- Left box buttons
- table.insert(Polygons, { Type = "rectangle", DrawMode = "line", Position = { x = 0.075, y = 0.875}, Dimension = {width = 0.125, height = 0.05}, Colors = {0, 0, 171, 255} })
- table.insert(Polygons, { Type = "rectangle", DrawMode = "line", Position = { x = 0.25, y = 0.875}, Dimension = {width = 0.125, height = 0.05}, Colors = {0, 0, 171, 255} })
-
- -- Left box content
- table.insert(Polygons, { Type = "line", LineWidth = 0.01, Position = { x1 = 0.375, y1 = 0.15, x2 = 0.375, y2 = 0.75}, Colors = {0, 0, 171, 255} })
-
- -- Right top box
- table.insert(Polygons, { Type = "rectangle", LineWidth = 0.005, DrawMode = "line", Position = { x = 0.45, y = 0.05}, Dimension = {width = 0.50, height = 0.75}, Colors = {0, 0, 171, 255} })
- table.insert(Polygons, { Type = "line", Position = { x1 = 0.45, y1 = 0.1, x2 = 0.95, y2 = 0.1}, Colors = {0, 0, 171, 255} })
-
- -- Right top box content
- table.insert(Polygons, { Type = "line", LineWidth = 0.01, Position = { x1 = 0.375-0.005, y1 = 0.75, x2 = 0.52+5*0.075+0.005, y2 = 0.75}, Colors = {0, 0, 171, 255} })
- table.insert(Polygons, { Type = "line", LineWidth = 0.01, Position = { x1 = 0.48, y1 = 0.75, x2 = 0.48, y2 = 0.15}, Colors = {0, 0, 171, 255} })
-
- -- Right bottom box
- table.insert(Polygons, { Type = "rectangle", LineWidth = 0.005, DrawMode = "fill", Position = { x = 0.45, y = 0.85}, Dimension = {width = 0.50, height = 0.10}, Colors = {0, 0, 0, 255} })
- table.insert(Polygons, { Type = "rectangle", DrawMode = "line", Position = { x = 0.45, y = 0.85}, Dimension = {width = 0.50, height = 0.10}, Colors = {0, 0, 171, 255} })
-
- -- Right bottom box buttons
- for i = 0, 5 do
- table.insert(Polygons, { Type = "rectangle", DrawMode = "fill", Position = { x = 0.50+i*0.075, y = 0.875}, Dimension = {width = 0.04, height = 0.04}, Colors = colors[i+1] })
- table.insert(Polygons, { Type = "rectangle", DrawMode = "line", LineWidth = 0.01, Position = { x = 0.50+i*0.075, y = 0.875}, Dimension = {width = 0.04, height = 0.04}, Colors = {0, 0, 171, 255} })
- table.insert(Polygons, { Type = "line", Position = { x1 = 0.52+i*0.075, y1 = 0.75, x2 = 0.52+i*0.075, y2 = 0.875}, Colors = {0, 0, 171, 255} })
- if i < 5 then
- table.insert(Polygons, { Type = "line", Position = { x1 = 0.5+i*0.075+0.04, y1 = 0.895, x2 = 0.52+(i+1)*0.075, y2 = 0.895}, Colors = {0, 0, 171, 255} })
- end
- end
-
- for i = 1, 4 do
- local n = love.math.random(1, 6)
- table.insert(Answer, n)
- end
- for k,v in ipairs(Answer) do print(k,v) end
-end
-
-local function drawPolygon(polygon)
- if polygon.Colors then
- love.graphics.setColor(unpack(polygon.Colors))
- end
-
- if polygon.LineWidth then
- love.graphics.setLineWidth(polygon.LineWidth*(Window.width+Window.height)/2)
- end
-
- if polygon.Type == "rectangle" then
- love.graphics.rectangle(polygon.DrawMode, polygon.Position.x*Window.width, polygon.Position.y*Window.height,
- polygon.Dimension.width*Window.width, polygon.Dimension.height*Window.height)
-
- elseif polygon.Type == "polygon" then
- love.graphics.polygon(polygon.DrawMode, polygon.Position.x1*Window.width, polygon.Position.y1*Window.height,
- polygon.Position.x2*Window.width, polygon.Position.y2*Window.height,
- polygon.Position.x3*Window.width, polygon.Position.y3*Window.height,
- polygon.Position.x4*Window.width, polygon.Position.y4*Window.height)
-
- elseif polygon.Type == "line" then
- love.graphics.line(polygon.Position.x1*Window.width, polygon.Position.y1*Window.height,
- polygon.Position.x2*Window.width, polygon.Position.y2*Window.height)
- elseif polygon.Type == "print" then
- love.graphics.print(polygon.Text, polygon.Position.x*Window.width, polygon.Position.y*Window.height)
- end
+ Gamestate.registerEvents()
+ Gamestate.switch(Menu)
end
-function love.mousepressed(x, y, b)
- x = x/Window.width
- y = y/Window.height
- if 0.875 < y and y < 0.915 then
- if x > 0.45 then
- for i = 0,5 do
- if 0.50+i*0.075 < x and x < 0.50+i*0.075+0.04 then
- if #Keypressed[#Keypressed] >= 4 then
- return
- else
- table.insert(Keypressed[#Keypressed], i+1)
- end
- end
- end
- elseif 0.25 < x and x < 0.375 and #Keypressed < 7 and #Keypressed[#Keypressed] == 4 then
- if checkKeys() then
- table.insert(Polygons, { Type = "print", Text = "FOUND !", Position = {x = 0.5, y = 0.5}, Colors = {255, 255, 255, 255}})
- else
- Keypressed[#Keypressed+1] = {}
- end
- elseif 0.075 < x and x < 0.200 and #Keypressed[#Keypressed] > 0 then
- Keypressed[#Keypressed] = {}
- end
- end
+function love.update(dt)
+ Screen.width, Screen.height = love.window.getDimensions()
end
function love.draw()
- Window.width, Window.height = love.window.getDimensions()
-
- for id, polygon in ipairs(Polygons) do
- drawPolygon(polygon)
- end
-
- for id, hint in ipairs(Hints) do
- drawPolygon(hint)
- end
-
- for line, keys in ipairs(Keypressed) do
- for id, num in ipairs(keys) do
- drawPolygon({ Type = "rectangle", DrawMode = "fill", Position = { x = 0.50+(id-1)*0.075, y = 0.15+(line-1)*0.075-0.025}, Dimension = {width = 0.04, height = 0.04}, Colors = colors[num] })
- love.graphics.print(num, (0.1+(id%5)*0.05)*Window.width, (0.6+((id-(id%5))/5)*0.05)*Window.height)
- end
- end
+-- Gui.core.draw()
end