-
Notifications
You must be signed in to change notification settings - Fork 0
/
controll-precise.lua
196 lines (162 loc) · 4.33 KB
/
controll-precise.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
--[[
This software is released under the MIT License. See LICENSE.txt for details.
Also, on a non-legal note: I do not recommend reading my code, especially not for educative
purposes. It was written over like three years, and I often forgot how I implemented several
things over time. Also, I was mostly drunk and listening to the Katamari Damacy soundtrack.
So yeah.
]]
conTrollP = newControl()
function conTrollP:load()
controlClass.load(self)
self.loopOpen = false
self.game.newloop = nil
end
function conTrollP:update2(dt)
if not self.loopOpen then
self.butts:update(dt)
else
local nl = self.game.newloop
self.game:updateLoop(nl.x + nl.w, nl.y + nl.h)
end
if love.keyboard.isDown("i") then
self.game:changeZoom(2*dt)
elseif love.keyboard.isDown("o") then
self.game:changeZoom(-2*dt)
end
if love.keyboard.isDown("w") then
self.game:moveCam(0,-200*dt)
end
if love.keyboard.isDown("a") then
self.game:moveCam(-200*dt,0)
end
if love.keyboard.isDown("d") then
self.game:moveCam(200*dt,0)
end
if love.keyboard.isDown("s") then
self.game:moveCam(0,200*dt)
end
local mx,my = love.mouse.getPosition()
local a,b = self:insideBounds(mx,my)
if love.mouse.isDown('l') and self.loopOpen then
self.game:updateLoop(self:toCoords(mx,my))
end
if a and not self.butts:lolInside() then
self.game:moveCam(a*250*dt,b*dt*250)
end
end
function conTrollP:mousereleased(k)
if self.game.newloop and math.abs(self.game.newloop.w) <= 2 and math.abs(self.game.newloop.h) <= 2 then
self.game:makeLoop()
self.loopOpen = false
end
self.game:moveCamCont(0,0)
end
local lolrange = 60
function conTrollP:insideBounds(x,y)
local d = 4
if flagFullscreen then
d = -1
end
if mouseOutsideBounds or x < d or x > width - d or y < d or y > height - d then
return
end
if x > width - lolrange then
return 1,0
end
if x < lolrange then
return -1,0
end
if y > height - lolrange then
return 0,1
end
if y < lolrange then
return 0,-1
end
end
local function fastdist(x1, y1, x2, y2)
return math.abs(x1-x2) + math.abs(y1-y2)
end
function conTrollP:mousepressed(k)
if k=='l' then
if not self.butts:click() then
local x,y = love.mouse.getPosition()
local lolx,loly = self:insideBounds(x,y)
if not lolx then
if self.game.newloop then
local loop = self.game.newloop
self.loopOpen = true
local smallest = 50
local found = 0
if loop.w < 0 then
loop.x = loop.x + loop.w
loop.w = loop.w * -1
end
if loop.h < 0 then
loop.y = loop.y + loop.h
loop.h = loop.h * -1
end
local poss = {loop.x, loop.y, loop.x, loop.y + loop.h, loop.x + loop.w, loop.y, loop.x + loop.w, loop.y + loop.h}
for i = 1,4 do
local pos = 2*i - 1
local d = fastdist(x, y, state:toScreenCoordsX(poss[pos]), state:toScreenCoordsY(poss[pos + 1]))
print(i .. ": " .. d)
if d < smallest then
smallest = d
found = i
end
end
if found == 1 then
local xlol = loop.x
local ylol = loop.y
loop.x = loop.x + loop.w
loop.y = loop.y + loop.h
loop.w = loop.x - xlol
loop.h = loop.y - ylol
return
elseif found == 2 then
local xlol = loop.x
loop.x = loop.x + loop.w
loop.w = loop.x - xlol
return
elseif found == 3 then
local ylol = loop.y
loop.y = loop.y + loop.h
loop.h = loop.y - ylol
return
elseif found == 4 then
return
end
local x2, y2 = self:toCoords(x, y)
if x2 < loop.x + loop.w and x2 > loop.x and y2 < loop.y + loop.h and y2 > loop.y then
if self.game.newloop then
self.game:makeLoop()
end
self.loopOpen = false
else
self.game:beginLoop(self:toCoords(x,y))
self.loopOpen = true
end
else
self.game:beginLoop(self:toCoords(x,y))
self.loopOpen = true
end
else
self.game:moveCamCont(lolx*250,loly*250)
end
else
self.loopOpen = false
--self.game.newloop = nil
end
end
end
function conTrollP:draw()
--if self.loopOpen then
if love.mouse.isDown("l") and self.loopOpen then
self.butts:draw(true)
else
self.butts:draw()
end
love.graphics.setColor(255,255,255,40)
love.graphics.rectangle("line",lolrange,lolrange,width - 2*lolrange,height - 2*lolrange)
love.graphics.setColor(255,255,255)
end