-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
221 lines (161 loc) · 7.2 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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
----------------------------------------------------------------------------------------------------
-- Code for imports, the initial load, and the `draw` loop
----------------------------------------------------------------------------------------------------
require "globals"
require "ui"
require "shoot"
require "logic"
require "touch"
require "keyboard"
-- Use this function to perform your initial setup
function love.load()
-- math.randomseed(42) -- goes out of bounds
-- math.randomseed(232) -- shot comes close to opponent; set `shotType3()` numOfBullets to 15 to hit opponent
math.randomseed(os.time()) -- randomize map every time
loadExternalAssets() -- globals.lua
setVariables() -- globals.lua
love.window.setMode(WIDTH, HEIGHT)
canvas = love.graphics.newCanvas(WIDTH, HEIGHT, { msaa = 2 })
canvas2 = love.graphics.newCanvas(WIDTH, HEIGHT, { msaa = 2 })
-- love.graphics.setCanvas(canvas)
-- love.graphics.setBlendMode("alpha") -- what does this do ?!??
-- love.graphics.setCanvas()
newGame()
bulType = 1
-- playerPressedShootButton() -- disable this to let the player take the first shot
end
-- This function gets called once every frame
function love.draw()
-- love.graphics.setBackgroundColor(0,0,50/255)
if endOfRound == true and shotInProgress == false then
endOfRound = false
newGame()
end
if colorMode == 1 then
-- this has potential to run over (how many minutes till it crashes?)
-- might want it to reset to 0 sometimes
rainbow.r = rainbow.r + 1
rainbow.g = rainbow.g + 2
rainbow.b = rainbow.b + 3
-- this code oscilates the color all the time (mathematically heavy)
love.graphics.setColor(math.floor(200 * math.abs(math.sin(rainbow.r * 0.005)) + 54) / 255,
math.floor(200 * math.abs(math.sin(rainbow.g * 0.004)) + 54) / 255,
math.floor(200 * math.abs(math.sin(rainbow.b * 0.003)) + 54) / 255, 1)
elseif colorMode == 2 then
love.graphics.setColor(1, 1, 1, 1)
end
-- only draw things if shot is in progress
if shotInProgress == true then
for i = 1, numOfBullets do drawShot(i) end
for i = 1, numOfBullets do collisonCheck(i) end
benign = benign + 1 -- benign makes your own bullet not kill you for the first few moments when you shoot
bulletsInFlight = false -- TODO: fix this hacky thing: if the x location of each shot == 0 then end the turn
for i = 1, numOfBullets do
if allBullets[i].x ~= 0 and allBullets[i].y ~= 0 then
bulletsInFlight = true -- HACK -- assumes position of disabled bullet is = (0, 0)
end
end
if bulletsInFlight == false then
print("all shots have finished")
shotInProgress = false
if turn == 1 then
turn = 2
elseif turn == 2 then
turn = 1
end
love.graphics.setCanvas(canvas)
drawUI()
love.graphics.setCanvas()
end
end
-- this code here WILL dim the trails continuously when explosion occurs
-- works too fast so I can slow it down by dimming every 5th frame (temp int)
-- if benign < 0 then dimTrails() end
-- drawUI() -- maybe do not draw continuously ?
-- starts dimming the playing field more aggressively
if endOfRound == true then
-- dimTrails()
-- love.graphics.setColor(0,0,0,1)
-- love.graphics.rectangle('fill',-1,-1,WIDTH+5,HEIGHT+5)
end
-- RENDER THE CANVAS NOW
love.graphics.draw(canvas)
if shotInProgress == false then
love.graphics.setCanvas(canvas2)
love.graphics.clear()
if turn == 1 then
drawPlayerAngleAndForce(player1)
if player1.lastAngle ~= nil then
drawAngleDiff(player1, 0)
end
drawForceAndAngle(player1, 1)
else
drawPlayerAngleAndForce(player2)
if player2.lastAngle ~= nil then
drawAngleDiff(player2, 1)
end
drawForceAndAngle(player2, 2)
end
love.graphics.setCanvas()
love.graphics.draw(canvas2)
end
drawShips()
love.graphics.setColor(1, 1, 1, 1)
end
function drawPlayerAngleAndForce(playerN)
-- large black circle
love.graphics.setColor(0, 0, 0, 0.6)
love.graphics.ellipse('fill', playerN.x, playerN.y, 100, 100)
-- red arc showing force
love.graphics.setColor(1, 0, 0, 1)
love.graphics.arc('fill', 'pie', playerN.x, playerN.y, playerN.force * 20, 0.0174533 * playerN.angle - 0.1, 0.0174533 * playerN.angle + 0.1)
-- smaller red circle showing force
love.graphics.setColor(1, 0, 0, 0.4)
love.graphics.ellipse('line', playerN.x, playerN.y, playerN.force * 20, playerN.force * 20)
-- love.graphics.setColor(1, 0, 0, 1)
-- love.graphics.line(playerN.x, playerN.y,
-- playerN.x + math.cos(0.0174533 * playerN.angle) * 100 * playerN.force / 5,
-- playerN.y + math.sin(0.0174533 * playerN.angle) * 100 * playerN.force / 5)
-- large white circle showing maximum
love.graphics.setColor(1, 1, 1, 0.6)
love.graphics.ellipse('line', playerN.x, playerN.y, 100, 100)
-- long line showing angle
love.graphics.setColor(1, 1, 1, 1)
love.graphics.ellipse('line', playerN.x, playerN.y, 10, 10)
love.graphics.line(playerN.x, playerN.y,
playerN.x + math.cos(0.0174533 * playerN.angle) * 100,
playerN.y + math.sin(0.0174533 * playerN.angle) * 100)
end
function drawAngleDiff(playerN, playerOffsetHack)
angleDiff = playerN.lastAngle - playerN.angle
forceDiff = playerN.force - playerN.lastForce
if angleDiff > 180 then
angleDiff = angleDiff - 360
end
if angleDiff < -180 then
angleDiff = angleDiff + 360
end
if angleDiff < 10 and angleDiff > -10 then
xOffset = playerN.x - 76 + playerOffsetHack * 90
fontOpacity = math.pow((10 - math.abs(angleDiff))/10, 0.5)
love.graphics.setFont(pixelFont)
if (angleDiff ~= 0) then
-- rectangle
love.graphics.setColor(0, 0, 0, 0.5)
love.graphics.rectangle('fill', xOffset + 5, playerN.y - 6, 56, 12, 4, 4)
-- text
love.graphics.setColor(1, 1, 1, fontOpacity)
love.graphics.printf(string.format("%.5f", angleDiff), xOffset, playerN.y - 7, 60, 'right')
end
love.graphics.setColor(1, 0, 0, fontOpacity)
if (forceDiff ~= 0) then
-- rectangle
love.graphics.setColor(0, 0, 0, 0.5)
love.graphics.rectangle('fill', xOffset + 5, playerN.y + 6, 56, 12, 4, 4)
-- text
love.graphics.setColor(1, 0, 0, fontOpacity)
love.graphics.printf(string.format("%.5f", forceDiff), xOffset, playerN.y + 5, 60, 'right')
end
love.graphics.setColor(1, 1, 1, 1)
end
end