-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmenu.lua
579 lines (473 loc) · 17 KB
/
menu.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
require "load"
require "cameram"
menu = {}
menu.loadplayer = 0
--animated image for menu background
function menu.load()
background1 = love.graphics.newImage("scrollbackground.png")
background2 = love.graphics.newImage("scrollbackground.png")
positiontitleY,positiontitleX= titlefont:getHeight() , width/2 - titlefont:getWidth("Metal Bug")/2
--width of the button
widthButton = {}
heightOptionFont = menufont:getHeight()
--button play, Option, editor and quit
widthButton.Play,widthButton.Quit = menufont:getWidth("Play"),menufont:getWidth("Quit")
widthButton.Options,widthButton.editor = menufont:getWidth("Options"),menufont:getWidth("Editor")
--TODO make instruction menu
positionPlayY,positionPlayX = positiontitleY + titlefont:getHeight()+20,width/2 - widthButton["Play"]/2
positionEditorY,positionEditorX = positionPlayY + heightOptionFont+20,width/2 - widthButton["editor"]/2
positionOptionsY,positionOptionsX = positionEditorY + heightOptionFont+20,width/2 - widthButton["Options"]/2
positionQuitY,positionQuitX = positionOptionsY + heightOptionFont+20,width/2 - widthButton["Quit"]/2
--option
widthButton.Controls = menufont:getWidth("Controls")
widthButton.Credit = menufont:getWidth("Credit")
widthButton.Back = menufont:getWidth("Back")
--option editor
widthButton.Dimension = menufont:getWidth("Dimension")
widthButton.Background = menufont:getWidth("Background")
--widthButton.x500 = menufont:getWidth("500x224")
widthButton.x918 = menufont:getWidth("900x224")
widthButton.x1247 = menufont:getWidth("1247x224")
widthButton.x1602 = menufont:getWidth("1602x224")
widthButton.x2000 = menufont:getWidth("2000x224")
widthButton.x2568 = menufont:getWidth("2568x224")
widthButton.W = menufont:getWidth("w")
widthButton.S = menufont:getWidth("s")
widthButton.A = menufont:getWidth("a")
widthButton.D = menufont:getWidth("d")
widthButton.J = menufont:getWidth("j")
widthButton.K = menufont:getWidth("k")
widthButton.L = menufont:getWidth("l")
positionControlsY,positionControlsX = positiontitleY + titlefont:getHeight()+20,width/2 - widthButton["Controls"]/2
positionCreditY,positionCreditX = positionControlsY+heightOptionFont+20,width/2 - widthButton["Credit"]/2
positionBackY,positionBackX = positionCreditY + heightOptionFont+20,width/2 - widthButton["Back"]/2
positionBackgroundY,positionBackgroundX = positiontitleY + titlefont:getHeight()+20,width/2 - widthButton["Background"]/2
positionDimensionY,positionDimensionX = positiontitleY + titlefont:getHeight()+20,width/2 - widthButton["Dimension"]/2
--position of the dimension
--position500x224Y,position500x224X = positionDimensionY + heightOptionFont+10,width/2 - widthButton.x500/2
position918x224Y,position918x224X = positionDimensionY + heightOptionFont+10,width/2 - widthButton.x918/2
position1247x224Y,position1247x224X = position918x224Y + heightOptionFont+10,width/2 - widthButton.x1247/2
position1602x224Y,position1602x224X = position1247x224Y + heightOptionFont+10,width/2 - widthButton.x1602/2
position2000x224Y,position2000x224X = position1602x224Y + heightOptionFont+10,width/2 - widthButton.x2000/2
position2568x224Y,position2568x224X = position2000x224Y + heightOptionFont+10,width/2 - widthButton.x2568/2
--see when finish the image
backgroundend = background1:getWidth()
scrollX = 0
scrollX1 = backgroundend
nextimg = 0
--thumbnail for the Editor
Background.quad1 = love.graphics.newQuad(0,0,500,224,Background[1]:getDimensions())
Background.quad2 = love.graphics.newQuad(0,0,500,224,Background[2]:getDimensions())
Background.quad3 = love.graphics.newQuad(0,0,500,224,Background[3]:getDimensions())
Background.quad4 = love.graphics.newQuad(0,0,500,224,Background[4]:getDimensions())
Background.quad5 = love.graphics.newQuad(0,0,500,224,Background[5]:getDimensions())
Background.quad6 = love.graphics.newQuad(0,0,500,224,Background[6]:getDimensions())
Background.quad1Y,Background.quad1X = positiontitleY + titlefont:getHeight()+10,width/2 - 300
Background.quad2Y,Background.quad2X = Background.quad1Y + 120,width/2 - 300
Background.quad3Y,Background.quad3X = Background.quad2Y + 120,width/2 - 300
Background.quad4Y,Background.quad4X = positiontitleY + titlefont:getHeight()+10,width/2
Background.quad5Y,Background.quad5X = Background.quad4Y + 120,width/2
Background.quad6Y,Background.quad6X = Background.quad5Y + 120,width/2
camera:newLayer(0.9,backgroundraw)
camera:newLayer(1,menu.draw)
end
--add event resize
function menu.resize(w,h)
positiontitleX = w/2 - titlefont:getWidth("Metal Bug")/2
positionPlayX = w/2 - widthButton["Play"]/2
positionEditorX = w/2 - widthButton["editor"]/2
positionOptionsX = w/2 - widthButton["Options"]/2
positionBackgroundX = w/2 - widthButton["Background"]/2
positionDimensionX = w/2 - widthButton["Dimension"]/2
positionCreditX = w/2 - widthButton["Credit"]/2
positionBackX = w/2 - widthButton["Back"]/2
positionQuitX = w/2 - widthButton["Quit"]/2
positionControlsX = w/2 - widthButton["Controls"]/2
Background.quad1X = w/2 - 300
Background.quad2X = w/2 - 300
Background.quad3X = w/2 - 300
Background.quad4X = w/2
Background.quad5X = w/2
Background.quad6X = w/2
end
local function movebackground()
--move backgroundcondition use dt instead of int
scrollX = scrollX - 1/2
scrollX1 = scrollX1 - 1/2
--transition 2 image to draw
if scrollX < -backgroundend then
nextimg = 1
scrollX = backgroundend
scrollX1 = 0
elseif scrollX1 < -backgroundend then
nextimg = 0
scrollX1 = backgroundend
scrollX = 0
else
nextimg = 0
end
end
--update
function menu.update(dt)
--variable scale calculate width only one time
movebackground()
end
local released = false
function menu.mousereleased(x, y, button)
if button == 1 then
released = true
end
end
--check if optionmode or menumode or else
--draw all option on screen
--see when mouse is over option for change color
function overbutton(text,x,y)
local mouseX,mouseY = love.mouse.getPosition()
if mouseX >= x and mouseX <= x+widthButton[text] and mouseY >= y and mouseY <= y+heightOptionFont then
return true
else
return false
end
end
local function overimage(x,y)
local mouseX,mouseY = love.mouse.getPosition()
if mouseX >= x and mouseX <= x+250 and mouseY >= y and mouseY <= y+112 then
love.graphics.setColor(222, 255, 0)
love.graphics.rectangle("line", x, y, 250, 112)
love.graphics.setColor(255, 255, 255)
return true
else
love.graphics.setColor(255, 255, 255)
return false
end
end
--draw button on screen
local function button(text,i,x,y)
local inside = false
--check if pointer is over the button
if overbutton(i,x,y) then
love.graphics.setColor(0,0,0,255)
inside = true
else
love.graphics.setColor(255,255,255,255)
end
love.graphics.setFont(menufont)
love.graphics.print(text,x,y)
--if click the button return true
return inside and released
end
function backgroundraw()
love.graphics.setColor(255, 255, 255 )
if nextimg == 1 then
love.graphics.draw(background2,scrollX1,30,0,1,2)
elseif nextimg == 2 then
love.graphics.draw(background1,scrollX,30,0,1,2)
else
love.graphics.draw(background1,scrollX,30,0,1,2)
love.graphics.draw(background2,scrollX1,30,0,1,2)
end
end
--add function for draw option and editor
--remove layer menu.draw and add layer of drawing editor or option
local function playbutton()
StateGame = player
if menu.loadplayer == 0 then
print("loading...player")
menu.loadplayer = 1
StateGame.load(nil,nil)
else
camera:ToGame()
end
end
local function DrawCredit()
love.graphics.setFont(CreditFont)
love.graphics.setColor(0, 0, 0, 255)
love.graphics.rectangle("fill", 8, 100, 190, 15)
love.graphics.rectangle("fill", 8, 150, 550, 15)
love.graphics.rectangle("fill", 8, 200, 920, 15)
love.graphics.rectangle("fill", 8, 250, 850, 15)
love.graphics.rectangle("fill", 8, 300, 660, 15)
love.graphics.rectangle("fill", 8, 350, 510, 15)
love.graphics.setColor(255, 0, 0, 255)
love.graphics.print("Thanks To:",10,100 )
love.graphics.print("MAD SOLDIER:enemy spridesheet",10,150)
love.graphics.print("Kevin Huff([email protected]):marco spritesheet",10,200 )
love.graphics.print("Alessio Vanni:sprite of rock and another stuff",10,250)
love.graphics.print("Elia Ruggeri:Highlighted the errors",10,300 )
love.graphics.print("Ivan Carosi:He knows french",10,350 )
if button("Back","Back",positionBackX,500) then
camera:removeLayer(DrawCredit)
camera:newLayer(1,DrawOptionbutton)
end
released = false
end
local function isclicked(text,i,x,y)
if text == "w" and overbutton(i,x,y) and released then
BindKey.click = 1
elseif text == "s" and overbutton(i,x,y) and released then
BindKey.click = 2
elseif text == "a" and overbutton(i,x,y) and released then
BindKey.click = 3
elseif text == "d" and overbutton(i,x,y) and released then
BindKey.click = 4
elseif text == "j" and overbutton(i,x,y) and released then
BindKey.click = 5
elseif text == "k" and overbutton(i,x,y) and released then
BindKey.click = 6
elseif text == "l" and overbutton(i,x,y) and released then
BindKey.click = 7
end
if BindKey.click ~= 0 then
if BindKey.click == 1 and text == "w" then
love.graphics.setColor(255,255,255,255)
love.graphics.print(BindKey[text],x,y)
elseif BindKey.click == 2 and text == "s" then
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print(BindKey[text],x,y)
elseif BindKey.click == 3 and text == "a" then
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print(BindKey[text],x,y)
elseif BindKey.click == 4 and text == "d" then
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print(BindKey[text],x,y)
elseif BindKey.click == 5 and text == "j" then
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print(BindKey[text],x,y)
elseif BindKey.click == 6 and text == "k" then
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print(BindKey[text],x,y)
elseif BindKey.click == 7 and text == "l" then
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print(BindKey[text],x,y)
end
else
love.graphics.print(BindKey[text],x,y)
end
love.graphics.setColor(0,0,0,255)
end
function menu.keyreleased(key)
if BindKey.click == 1 then
BindKey["w"] = key
elseif BindKey.click == 2 then
BindKey["s"] = key
elseif BindKey.click == 3 then
BindKey["a"] = key
elseif BindKey.click == 4 then
BindKey["d"] = key
elseif BindKey.click == 5 then
BindKey["j"] = key
elseif BindKey.click == 6 then
BindKey["k"] = key
elseif BindKey.click == 7 then
BindKey["l"] = key
end
BindKey.click = 0
end
local function DrawControls()
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("lookup:",50,100 )
isclicked("w","W",600,100)
love.graphics.print("move left:",50,150 )
isclicked("a","A",600,150 )
love.graphics.print("move right:",50,200)
isclicked("d","D",600,200)
love.graphics.print("crouch:",50,250)
isclicked("s","S",600,250)
love.graphics.print("shoot:",50,300 )
isclicked("j","J",600,300 )
love.graphics.print("jump:",50,350 )
isclicked("k","K",600,350 )
love.graphics.print("throw rock:",50,400 )
isclicked("l","L",600,400 )
if button("Back","Back",positionBackX,500) then
camera:removeLayer(DrawControls)
camera:newLayer(1,DrawOptionbutton)
end
released = false
end
function DrawOptionbutton()
love.graphics.setColor(0, 0, 0, 255)
love.graphics.setFont(titlefont)
love.graphics.print("Metal Bug",positiontitleX,positiontitleY)
if button("Controls","Controls",positionControlsX,positionControlsY)then
camera:removeLayer(DrawOptionbutton)
camera:newLayer(1,DrawControls)
end
--setting instruction
if button("Credit","Credit",positionCreditX,positionCreditY)then
camera:removeLayer(DrawOptionbutton)
camera:newLayer(1,DrawCredit)
end
if button("Back","Back",positionBackX,positionBackY) then
camera:removeLayer(DrawOptionbutton)
camera:newLayer(1,menu.draw)
end
released = false
end
--variable to choose which background
local index = 1
local function EditorLevel(dimension)
StateGame = maker
StateGame.load(index,dimension)
print(index)
camera:ToMaker()
end
function DrawselectDimension()
love.graphics.setColor(0, 0, 0, 255)
love.graphics.setFont(titlefont)
love.graphics.print("Metal Bug",positiontitleX,positiontitleY)
--button("Dimension","Dimension",positionDimensionX,positionDimensionY)
love.graphics.setColor(255,255,255,255)
love.graphics.setFont(menufont)
love.graphics.print("Dimension",positionDimensionX,positionDimensionY)
--setting button for various dimension
if index == 1 then
if button("918x224","x918",position918x224X,position918x224Y)then
EditorLevel(918)
end
elseif index == 2 then
if button("918x224","x918",position918x224X,position918x224Y)then
EditorLevel(918)
end
if button("1247x224","x1247",position1247x224X,position1247x224Y)then
EditorLevel(1247)
end
elseif index == 3 or index == 4 or index == 5 then
if button("918x224","x918",position918x224X,position918x224Y)then
EditorLevel(918)
end
if button("1247x224","x1247",position1247x224X,position1247x224Y)then
EditorLevel(1247)
end
if button("1602x224","x1602",position1602x224X,position1602x224Y)then
EditorLevel(1602)
end
else
if button("918x224","x918",position918x224X,position918x224Y)then
EditorLevel(918)
end
if button("1247x224","x1247",position1247x224X,position1247x224Y)then
EditorLevel(1247)
end
if button("1602x224","x1602",position1602x224X,position1602x224Y)then
EditorLevel(1602)
end
if button("2000x224","x2000",position2000x224X,position2000x224Y)then
EditorLevel(2000)
end
if button("2568x224","x2568",position2568x224X,position2568x224Y)then
EditorLevel(2568)
end
end
if button("Back","Back",positionBackX,position2568x224Y + heightOptionFont+20) then
camera:removeLayer(DrawselectDimension)
camera:newLayer(1,DrawThumbnail)
end
released = false
end
function DrawThumbnail()
love.graphics.setColor(0, 0, 0, 255)
love.graphics.setFont(titlefont)
love.graphics.print("Metal Bug",positiontitleX,positiontitleY)
--set width of the line
love.graphics.setLineWidth(10)
local s = false
--draw rectangle over image
if overimage(Background.quad1X,Background.quad1Y) and released then
index = 1
camera:removeLayer(DrawThumbnail)
camera:newLayer(1,DrawselectDimension)
end
love.graphics.draw(Background[1],Background.quad1,
Background.quad1X,
Background.quad1Y,
0,
0.5,
0.5
)
if overimage(Background.quad2X,Background.quad2Y) and released then
index = 2
camera:removeLayer(DrawThumbnail)
camera:newLayer(1,DrawselectDimension)
end
love.graphics.draw(Background[2],Background.quad2,
Background.quad2X,
Background.quad2Y,
0,
0.5,
0.5
)
if overimage(Background.quad3X,Background.quad3Y) and released then
index = 3
camera:removeLayer(DrawThumbnail)
camera:newLayer(1,DrawselectDimension)
end
love.graphics.draw(Background[3],Background.quad3,
Background.quad3X,
Background.quad3Y,
0,
0.5,
0.5
)
if overimage(Background.quad4X,Background.quad4Y) and released then
index = 4
camera:removeLayer(DrawThumbnail)
camera:newLayer(1,DrawselectDimension)
end
love.graphics.draw(Background[4],Background.quad4,
Background.quad4X,
Background.quad4Y,
0,
0.5,
0.5
)
if overimage(Background.quad5X,Background.quad5Y) and released then
index = 5
camera:removeLayer(DrawThumbnail)
camera:newLayer(1,DrawselectDimension)
end
love.graphics.draw(Background[5],Background.quad5,
Background.quad5X,
Background.quad5Y,
0,
0.5,
0.5
)
if overimage(Background.quad6X,Background.quad6Y) and released then
index = 6
camera:removeLayer(DrawThumbnail)
camera:newLayer(1,DrawselectDimension)
end
love.graphics.draw(Background[6],Background.quad6,
Background.quad6X,
Background.quad6Y,
0,
0.5,
0.5
)
if button("Back","Back",positionBackX,Background.quad6Y+130) then
camera:removeLayer(DrawThumbnail)
camera:newLayer(1,menu.draw)
end
released = false
end
function menu.draw()
love.graphics.setColor(0, 0, 0, 255)
love.graphics.setFont(titlefont)
love.graphics.print("Metal Bug",positiontitleX,positiontitleY)
if button("Play","Play",positionPlayX,positionPlayY)then
playbutton()
end
if button("Editor","editor",positionEditorX,positionEditorY)then
camera:removeLayer(menu.draw)
camera:newLayer(1,DrawThumbnail)
end
if button("Options","Options",positionOptionsX,positionOptionsY)then
camera:removeLayer(menu.draw)
camera:newLayer(1,DrawOptionbutton)
end
if button("Quit","Quit",positionQuitX,positionQuitY) then
love.event.quit()
end
released = false
end