1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
--[[
Gamestates/Solo.lua
Solo mode
by piernov
]]--
local GUI = { InGame = require("GUI/InGame")}
local Game = require("Gamestates/Game")
local Solo = {}
function Solo:enter() -- Initialize or reset variables when entering game
Previous = "Gamestates/Menu"
Solo.Keypressed = {{}} -- 2D array for storage of button pressed
Solo.Hints = {} -- Hints displayed
Solo.state = "playing" -- Default to "playing" but it doesn't mean anything
Solo.Answer = Game.genAnswer() -- Generate answer
-- Debug
if Debug == true then
for k,v in ipairs(Solo.Answer) do
print(k,v)
end
end
Solo:resize() -- Call the function filling the canvas
Solo.Music = Menu.Music
Solo.Music:setLooping(true)
if Config.Mute == false then
Solo.Music:rewind()
end
end
function Solo:resize() -- Called in :enter() and when the window is resized
Solo.Display = love.graphics.newCanvas(Screen.width, Screen.height) -- Create the canvas containing base interface to avoid drawing it entirely each frame
love.graphics.setCanvas(Solo.Display)
love.graphics.setFont(Fonts[3]) -- Use font with size 3% by default
Solo.Display:clear()
for id, polygon in ipairs(GUI.InGame.Polygons) do
GUI.InGame.drawPolygon(polygon)
end
love.graphics.setCanvas()
end
function Solo:init()
Game.init()
GUI.InGame.loadInterface()
end
function Solo:draw()
love.graphics.setColor(255, 255, 255, 255)
love.graphics.setBlendMode('premultiplied')
love.graphics.draw(Solo.Display)
love.graphics.setBlendMode('alpha')
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
-- Debug
if Debug == true then
for id, num in ipairs(Solo.Answer) do
GUI.InGame.drawPolygon({ Type = "rectangle", DrawMode = "fill", Position = { x = 0.08+(id-1)*0.075+0.005, y = 0.12+0.005}, Dimension = {width = 0.035, height = 0.04}, Colors = GUI.InGame.Colors[num] }) -- Display answer
end
end
if Solo.state == "found" then
GUI.InGame.displayPopup("Found !")
end
GUI.InGame.drawPolygon({ Type = "print", Text = "Solo", Position = { x = 0.15, y = 0.06}, Colors = {0, 0, 171, 255} }) -- Display "Solo" text
GUI.InGame.drawPolygon({ Type = "print", Text = Config.player_name.text, Position = { x = 0.60, y = 0.06}, Colors = {0, 0, 171, 255} }) -- Display local player's name
end
function Solo:mousepressed(x, y, b) -- Handle mouse
if Solo.state == "found" then return end -- Don't do anything if answer is already found
x = x/Screen.width -- relative coordinates
y = y/Screen.height
if 0.875 < y and y < 0.915 then -- lower part of the screen
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 -- Line already full
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) -- Click detected on a color-button
end
end
end
elseif 0.25 < x and x < 0.375 and #Solo.Keypressed <= 7 and #Solo.Keypressed[#Solo.Keypressed] == 4 then -- Clik on Ok button
local hints = table.concat(Game.checkKeys(Solo.Keypressed[#Solo.Keypressed], Solo.Answer))
if hints == "1111" then
Solo.state = "found"
else
table.insert(Solo.Hints, Game.addHints(hints, #Solo.Keypressed))
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 -- Click on reset button
Solo.Keypressed[#Solo.Keypressed] = {}
end
end
end
function Solo:leave()
Solo.Music:stop()
end
return Solo
|