-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
159 lines (135 loc) · 2.97 KB
/
main.lua
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
--[[
Squaricles
Copyright (C) 2017 ITR
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
]]--
require ".rules"
require ".helperfunctions"
require ".input"
require ".squindices"
require ".board"
require ".game"
require ".wrapper"
local WIDTH = 1920.0/2
local HEIGHT = 1200.0
local rescaleNextFrame = false
font = love.graphics.newFont("font/Play-Bold.ttf",60)
love.graphics.setFont(font)
function love.load()
initRandom()
love.window.setMode(
0,
0,
{resizable = true, centered = true}
)
love.window.maximize()
rescaleNextFrame = true
love.window.setTitle("Squaricles")
leftCanvas = love.graphics.newCanvas(WIDTH, HEIGHT)
--rightCanvas = love.graphics.newCanvas(WIDTH, HEIGHT)
wrappers = {
Wrapper:new(leftCanvas, QWEASD),
--Wrapper:new(rightCanvas, ARROWS),
}
end
function quit(force)
if force then
love.event.quit()
return
end
for i=1,#wrappers do
if wrappers[i].playing then
return
end
end
love.event.quit()
end
function love.draw()
local w = love.graphics.getWidth()/#wrappers
local h = love.graphics.getHeight()
if rescaleNextFrame then
w, h = w/1920, h/1200
rescaleNextFrame = false
if w<h then
love.window.setMode(
w*WIDTH,
w*HEIGHT,
{resizable = true, centered = true}
)
w = w*WIDTH
h = w*HEIGHT
else
love.window.setMode(
h*WIDTH,
h*HEIGHT,
{resizable = true, centered = true}
)
w = h*WIDTH
h = h*HEIGHT
end
end
for i=1,#wrappers do
wrappers[i]:draw()
end
love.graphics.setCanvas()
love.graphics.clear(0x00,0x00,0x00,000)
love.graphics.setColor(255,255,255,255)
local mult = 1
if w/WIDTH < h/HEIGHT then
mult = w/WIDTH
else
mult = h/HEIGHT
end
for i=1,#wrappers do
love.graphics.draw(
wrappers[i].canvas,
(w-(1920/2)*mult)/2 + (i-1)*w,
(h-(1200/1)*mult)/2,
0,
mult, mult,
0, 0
)
end
if DEBUGONSCREEN then
love.graphics.setColor(255,255,255,255)
love.graphics.print(DEBUGONSCREEN)
end
end
function love.update(dt)
for i=1,#wrappers do
wrappers[i]:update(dt)
end
end
function initRandom()
math.randomseed(os.time())
for i=0,10 do
math.random()
end
end
function setColor(colorindex, makeghost, inverted)
local c = {}
if inverted then
for i=1,3 do
c[i] = 1-COLORS[colorindex][i]
end
else
for i=1,3 do
c[i] = COLORS[colorindex][i]
end
end
if makeghost then
c[4] = 0.5
else
c[4] = 1
end
love.graphics.setColor(c)
end