-
Notifications
You must be signed in to change notification settings - Fork 34
/
game.js
3927 lines (3178 loc) · 101 KB
/
game.js
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
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
PACKABUNCHAS
by Mattia Fortunati
http://www.mattiafortunati.com
mattia@mattiafortunati.com
This game is made for the 2021 edition of js13kgames.
As you can see, this code is really messy, full of mistakes and unused/redundat/unoptimized/workaroundy/copypasted things.
It would have been great to optimize and beautify it, but I couldn't really make it in time for the js13k deadline!
So, if you want to check it for any reason, do it at your own risk :D
*/
/*
=============================================== VARS ===============================================
*/
//versionN = 0.3
c = document.getElementById("v");
ctx = c.getContext("2d");
w = v.width
h = v.height
mouseX = 0
mouseY = 0
startingMouseX = 0
startingMouseY = 0
isMousePressed = false
bgPos = {
x: 0,
y: 0
}
recPos = {
x: w / 2,
y: h / 2
}
titlePos = {
x: w / 2,
y: h * 0.9
}
menuTextPos = {
x: w / 2,
y: 3000
}
modeTextPos = {
x: w / 2,
y: -1500
}
storyTextPos = {
x: w / 2,
y: 100
}
helpCharPos = {
x: 45,
y: h + 100
}
textPos = {
x: 280,
y: h + 100
}
//score
pTextPos = {
x: w / 2,
y: 3000
}
numberOfPolyominos = 4
sizeOfPolyominos = 4
mixed = false
//starting additional area spaces
margin = 0
gameModes = ["CLASSIC", "PENTA", "MIX", "KIDS", "EZPZ", ]
currentGameMode = parseInt(loadData("currentGameMode", "0"))
gridOffsetX = 0
menuText = gameModes[currentGameMode]
lerpSpeed = 0.1
mylatesttap = 0
bottomTextText = ""
polyLeft = parseInt(loadData("polyLeft", "13"))
currentPolyTextToShow = polyLeft
blockSize = w / 13
bSize = blockSize / 2
GENERATING = false
pieces = []
draggedBlock = null
lastDraggedBlock = null
solution = null
bag = {}
buttons = []
isCinematic = false
endCinematicState = 999
center2Alpha = 0
toDrawPieces = true
overlayAlpha = 0
fireCounter = 0
fireAddendum = 5
showFire = false
showLoading = false
//saveData("storyState", "0")
storyState = parseInt(loadData("storyState", "0"))
/*
story states
0 = has to show intro
1 = has showed intro, has to show middle story
2 = is showing middle story
3 = has showed middle story, has to show ending
4 = is showing ending
*/
//storyState = 0
canSkip = false
skipState = 0
//can skip is a working var for story and
mouthCounter = 0
mouthAddendum = 5
animateMouth = false
gameStarted = false
lastLoop = new Date();
music = null
state = "title"
musicVolume = .1
effectVolume = 1
//muted = false
muted = loadData("muted", "false") == "true"
leftButton = createButton(w * 0.2, h * 0.55, 100, 100, "<", 70, -5, 22, function() {
changeMode(-1)
})
buttons.push(leftButton)
rightButton = createButton(w * 0.8, h * 0.55, 100, 100, ">", 70, 5, 22, function() {
changeMode(1)
})
buttons.push(rightButton)
startButton = createButton(w * 0.5, h * 0.6, 140, 350, "START", 70, 0, 25, goToGame)
buttons.push(startButton)
backButton = createButton(w * 0.1, h * 0.06, 100, 100, "<", 70, -5, 22, backToMenu)
buttons.push(backButton)
muteButton = createButton(w * 0.90, h * 0.06, 120, 120, "", 70, 0, 0, mute)
buttons.push(muteButton)
fullScreenButton = createButton(-1500, h * 0.06, 120, 120, "", 70, 0, 0, toggleFullscreen)
buttons.push(fullScreenButton)
leftButton.originalx = -10000
leftButton.x = -10000
rightButton.originalx = 10000
rightButton.x = 10000
startButton.originaly = 10000
startButton.y = 10000
backButton.originalx = -1000
backButton.x = -500
helpTimeout = null
showTutorial = loadData("showTutorial", "true") == "true"
message = {
text: ["", ""],
act: 0,
tct: 0,
x: 100,
y: 100,
timeout: null,
stayOnEnd: false,
isPressed: false,
restart: function() {
this.phrase = 0
this.letter = 0
this.timeout = window.setTimeout(writeText, 50)
}
}
storyMessage = {
message: ["", ""],
act: 0,
tct: 0,
x: 100,
y: 100,
timeout: null,
stayOnEnd: false,
restart: function() {
this.phrase = 0
this.letter = 0
this.timeout = window.setTimeout(writeStoryMessage, 50)
}
}
storyTimeOut = null
/*
=============================================== UPDATE ===============================================
*/
function update() {
//set mouse icon
if (isMousePressed == true) {
document.body.style.cursor = "grabbing"
} else {
document.body.style.cursor = "grab"
}
//"animate" score change
if (currentPolyTextToShow > polyLeft) {
currentPolyTextToShow -= 1
}
checkIfPiecesOutside()
alignPieces()
//Draw
draw()
requestAnimationFrame(update)
}
function checkIfPiecesOutside() {
pieces.find(currentPiece => {
if (!currentPiece.isDragged == true) {
for (let i = 0; i < currentPiece.blocks.length; i++) {
currentBlock = currentPiece.blocks[i]
if (currentBlock[0] * blockSize + currentPiece.originalPosition.x < blockSize) {
currentPiece.originalPosition.x += bSize
} else if (currentBlock[0] * blockSize + currentPiece.originalPosition.x > w - blockSize) {
currentPiece.originalPosition.x -= bSize
} else if (currentBlock[1] * blockSize + currentPiece.originalPosition.y < blockSize) {
currentPiece.originalPosition.y += bSize
} else if (currentBlock[1] * blockSize + currentPiece.originalPosition.y > h - blockSize) {
currentPiece.originalPosition.y -= bSize
}
}
}
})
}
function alignPieces() {
//align every piece to grid
pieces.find(piece => {
if (draggedBlock != piece) {
//trickier than it seems to align to an offset grid :)
//original pos + offset = flor(round((original pos + offset))/cell)*cell
piece.originalPosition.x = Math.floor(Math.round((piece.originalPosition.x + gridOffsetX) / blockSize) * blockSize) - gridOffsetX
piece.originalPosition.y = Math.floor(Math.round(piece.originalPosition.y / blockSize) * blockSize)
var COLL = collideWithOtherPieces(piece, pieces)
if (COLL != false && COLL != draggedBlock) {
if (piece.originalPosition.x <= COLL.originalPosition.x) {
piece.originalPosition.x -= bSize
} else if (piece.originalPosition.x > COLL.originalPosition.x) {
piece.originalPosition.x += bSize
}
if (piece.originalPosition.y <= COLL.originalPosition.y) {
piece.originalPosition.y -= bSize
} else if (piece.originalPosition.y > COLL.originalPosition.y) {
piece.originalPosition.y += bSize
}
}
}
})
}
function setLoadingColor() {
cc = ["#C2FDFF", "#FFC886", "#94DEC3", "#D8D0FF", "#FED1E6", "#7DC864", "#FF7E64", "#FDF3BD"]
loadingColor = cc[Math.floor(Math.random() * cc.length)]
}
function setStartingColors() {
bgColor = "#94DEC3"
planetColor = "#FED1E6"
sunColor = "#FDF3BD"
smallPlanetColor = "#FFC886"
bagColor = "#7DC864"
smallPlanet = 1
planetCraters = 0
sunCraters = 0
halfSun = 1
}
function setBgColors() {
//var colors = ["#A09CF1", "#94DEC3", "#D8D0FF", "#FED1E6"]
//var colors = ["#FFEA7E", "#C2FDFF", "#FFC886", "#94DEC3", "#D8D0FF", "#FED1E6", "#7DC864", "#FF7E64", "#FDF3BD"] //,"#DD558E"
var cc = ["#A09CF1", "#94DEC3", "#D8D0FF", "#FED1E6"]
bgColor = cc[Math.floor(Math.random() * cc.length)]
while (true) {
var cc = ["#C2FDFF", "#FFC886", "#94DEC3", "#D8D0FF", "#FED1E6", "#7DC864", "#FDF3BD"]
planetColor = cc[Math.floor(Math.random() * cc.length)]
if (planetColor != bgColor) break
}
while (true) {
var cc = ["#FFEA7E", "#C2FDFF", "#FFC886", "#94DEC3", "#D8D0FF", "#FED1E6", "#7DC864", "#FF7E64", "#FDF3BD"]
sunColor = cc[Math.floor(Math.random() * cc.length)]
if (sunColor != bgColor && sunColor != planetColor) break
}
while (true) {
var cc = ["#FFEA7E", "#C2FDFF", "#FFC886", "#94DEC3", "#D8D0FF", "#FED1E6", "#7DC864", "#FF7E64", "#FDF3BD"]
smallPlanetColor = cc[Math.floor(Math.random() * cc.length)]
if (smallPlanetColor != bgColor && smallPlanetColor != planetColor && smallPlanetColor != sunColor) break
}
while (true) {
var cc = ["#FFEA7E", "#C2FDFF", "#FFC886", "#94DEC3", "#D8D0FF", "#FED1E6", "#7DC864", "#FF7E64", "#FDF3BD"]
bagColor = cc[Math.floor(Math.random() * cc.length)]
if (bagColor != bgColor && bagColor != planetColor) break
}
smallPlanet = Math.random() < 0.5 ? -1 : 1
planetCraters = Math.random() < 0.5 ? -1 : 1
sunCraters = Math.random() < 0.5 ? -1 : 1
halfSun = Math.random() < 0.5 ? -1 : 1
}
/*
=============================================== DRAW ===============================================
*/
function drawPieces() {
//draw bag
ctx.lineWidth = 3
var xx = 0 - mouseX / 200
var yy = 0 - mouseY / 200
var newX = xx + bag.originalPosition.x
var newY = xx + bag.originalPosition.y
bag.position.x = lerp(bag.position.x, newX, lerpSpeed)
bag.position.y = lerp(bag.position.y, newY, lerpSpeed)
var minX = 0
var maxX = 0
var minY = 0
var maxY = 0
bag.blocks.find(b => {
minX = Math.min(minX, b[0])
maxX = Math.max(maxX, b[0])
minY = Math.min(minY, b[1])
maxY = Math.max(maxY, b[1])
})
var ww = (maxX - minX) + 1
var hh = (maxY - minY) + 1
//left
ctx.save();
ctx.translate(bag.position.x + minX * blockSize - bSize - bSize / 2 - 10, bag.position.y + minY * blockSize - bSize - bSize / 2 - 10)
ctx.beginPath();
ctx.lineWidth = 20
ctx.strokeStyle = "#5D4E51"
ctx.fillStyle = "#5D4E51"
var vertices = [{
x: ww * blockSize + bSize + bSize / 2,
y: hh * blockSize + bSize
}, {
x: ww * blockSize + bSize + bSize / 2,
y: hh * blockSize / 2
}, {
x: ww * blockSize + bSize + bSize / 2 + 100,
y: hh * blockSize + bSize
}];
roundedPoly(vertices, 5)
ctx.stroke()
ctx.fill()
ctx.restore()
//right
ctx.save();
ctx.translate(bag.position.x + minX * blockSize - bSize - bSize / 2 - 10, bag.position.y + minY * blockSize - bSize - bSize / 2 - 10)
ctx.beginPath();
ctx.lineWidth = 20
ctx.strokeStyle = "#5D4E51"
ctx.fillStyle = "#5D4E51"
var vertices = [{
x: 0,
y: hh * blockSize + bSize
}, {
x: 0,
y: hh * blockSize / 2
}, {
x: -100,
y: hh * blockSize + bSize
}];
roundedPoly(vertices, 5)
ctx.stroke()
ctx.fill()
ctx.restore()
//fire
if (showFire == true) {
fireCounter += fireAddendum
if (fireCounter <= 0) {
fireAddendum = 5
} else if (fireCounter >= 50) {
fireAddendum = -5
}
ctx.save();
ctx.translate(bag.position.x + minX * blockSize - bSize - bSize / 2 + (ww * blockSize / 2) - bSize, bag.position.y + maxY * blockSize + blockSize)
ctx.beginPath();
ctx.fillStyle = "#FF9E67"
ctx.ellipse(60, 0, 50, 150 + fireCounter, 0, 0, 2 * Math.PI);
ctx.fill()
ctx.beginPath();
ctx.fillStyle = "#FEE66C"
ctx.ellipse(60, 0, 25, 100 + fireCounter, 0, 0, 2 * Math.PI);
ctx.fill()
ctx.restore()
}
//bottom 1
ctx.save();
ctx.translate(bag.position.x + minX * blockSize - bSize - bSize / 2 + (ww * blockSize / 2) - bSize, bag.position.y + maxY * blockSize + blockSize + 60)
ctx.beginPath();
ctx.lineWidth = 20
ctx.strokeStyle = "#5D4E51"
ctx.fillStyle = "#5D4E51"
var vertices = [{
x: 0,
y: 0
}, {
x: 20,
y: -100
}, {
x: 100,
y: -100
}, {
x: 120,
y: 0
}];
roundedPoly(vertices, 5)
ctx.stroke()
ctx.fill()
ctx.restore()
//center
ctx.save();
ctx.translate(bag.position.x + minX * blockSize - bSize - bSize, bag.position.y + minY * blockSize)
ctx.beginPath();
ctx.lineWidth = 20
ctx.strokeStyle = "#5D4E51"
ctx.fillStyle = bagColor
var vertices = [{
x: 30,
y: -80
}, {
x: (ww * blockSize) / 2 + bSize,
y: -hh / 2 * blockSize - 80
}, {
x: ww * blockSize + bSize - 30 + bSize,
y: -80
}, {
x: ww * blockSize + bSize + bSize,
y: hh * blockSize
}, {
x: 0,
y: hh * blockSize
}];
roundedPoly(vertices, 90)
ctx.stroke()
ctx.fill()
ctx.restore()
ctx.save()
ctx.clip()
ctx.translate(bag.position.x + minX * blockSize - bSize - bSize, bag.position.y + minY * blockSize)
ctx.fillStyle = "#5D4E51"
ctx.roundRect(0, -hh / 2 * blockSize - 80, w, hh / 2 * blockSize, 0)
ctx.fill()
ctx.restore()
bag.blocks.find(b => {
ctx.save();
ctx.translate(bag.position.x + blockSize * b[0], bag.position.y + blockSize * b[1])
ctx.lineWidth = 4
ctx.beginPath();
ctx.globalAlpha = 1
//ctx.rect(-blockSize / 2, -blockSize / 2, blockSize, blockSize);
ctx.roundRect(-blockSize / 2, -blockSize / 2, blockSize, blockSize, 10)
ctx.strokeStyle = "#5D4E51"
ctx.stroke()
ctx.globalAlpha = 0.1
ctx.fillStyle = "#000"
ctx.fill()
ctx.globalAlpha = 1
ctx.restore()
})
//draw pieces
if (toDrawPieces == true) {
for (let j = 0; j < pieces.length; j++) {
var piece = pieces[j]
//check lerp
var xx = 0 - mouseX / 200
var yy = 0 - mouseY / 200
var newX = xx + piece.originalPosition.x
var newY = xx + piece.originalPosition.y
//move lerp
piece.position.x = lerp(piece.position.x, newX, lerpSpeed)
piece.position.y = lerp(piece.position.y, newY, lerpSpeed)
//draw piece blocks
piece.blocks.find(b => {
//for every block
ctx.save();
//get block position
var bx = piece.position.x + blockSize * b[0]
var by = piece.position.y + blockSize * b[1]
ctx.translate(bx, by)
//bg pieces transparent
ctx.lineWidth = 2
ctx.globalAlpha = 0.5
ctx.roundRect(-blockSize / 2, -blockSize / 2, blockSize, blockSize, 10)
ctx.fillStyle = piece.fillColor
//currently moving
if (draggedBlock == piece) {
ctx.fillStyle = "#fff"
}
ctx.fill()
ctx.globalAlpha = 1
ctx.restore()
//DRAW BORDERS
//size of borders
var size = bSize * 1.6
var roundness = 15
//center
ctx.fillStyle = "#5D4E51"
ctx.roundRect(bx - size / 2, by - size / 2, size, size, roundness)
ctx.fill()
//top
if (piece.containsCurrentPosition(bx, by - blockSize)) {
ctx.roundRect(bx - size / 2, by - size, size, size, roundness)
ctx.fill()
}
//bottom
if (piece.containsCurrentPosition(bx, by + blockSize)) {
ctx.roundRect(bx - size / 2, by, size, size, roundness)
ctx.fill()
}
//left
if (piece.containsCurrentPosition(bx - blockSize, by)) {
ctx.roundRect(bx - size, by - size / 2, size, size, roundness)
ctx.fill()
}
//right
if (piece.containsCurrentPosition(bx + blockSize, by)) {
ctx.roundRect(bx, by - size / 2, size, size, roundness)
ctx.fill()
}
//draw internal part
//size of interal part
//console.log(b[3])
//
//console.log(ctx.globalAlpha)
var sizeColored = bSize * 1.2
//center
ctx.fillStyle = piece.fillColor
ctx.roundRect(bx - sizeColored / 2, by - sizeColored / 2, sizeColored, sizeColored, roundness)
ctx.fill()
//top
if (piece.containsCurrentPosition(bx, by - blockSize)) {
ctx.roundRect(bx - sizeColored / 2, by - sizeColored * 2, sizeColored, sizeColored * 2, roundness)
ctx.fill()
}
//bottom
if (piece.containsCurrentPosition(bx, by + blockSize)) {
ctx.roundRect(bx - sizeColored / 2, by, sizeColored, sizeColored * 2, roundness)
ctx.fill()
}
//left
if (piece.containsCurrentPosition(bx - blockSize, by)) {
ctx.roundRect(bx - sizeColored * 2, by - sizeColored / 2, sizeColored * 2, sizeColored, roundness)
ctx.fill()
}
//right
if (piece.containsCurrentPosition(bx + blockSize, by)) {
ctx.roundRect(bx, by - sizeColored / 2, sizeColored * 2, sizeColored, roundness)
ctx.fill()
}
})
if (piece.type == "striped") {
piece.blocks.find(b => {
//for every block
//get block position
var bx = piece.position.x + blockSize * b[0]
var by = piece.position.y + blockSize * b[1]
var size = bSize * 1.6
var roundness = 15
ctx.globalAlpha = b[2]
//center
ctx.fillStyle = "#000"
ctx.roundRect(bx - size / 2, by - size / 2, size, size, roundness)
ctx.fill()
ctx.globalAlpha = 1
})
} else if (piece.type == "pois") {
piece.blocks.find(b => {
//for every block
//get block position
var bx = piece.position.x + blockSize * b[0]
var by = piece.position.y + blockSize * b[1]
//draw stripes
ctx.globalAlpha = 0.1
//draw internal stripes
//size of interal part
ctx.fillStyle = "#000"
//not top not bottom
var tp = 1
if (Math.abs(piece.blocks.indexOf(b) % 2) == 1) {
tp = 2
}
var size2 = 8
if (b != piece.blocks[piece.eyeBlock]) {
//ctx.fillRect(bx - sizeColored3 / 2, by - sizeColored2, sizeColored3, sizeColored2 * 2)
//ctx.fill()
if (tp == 1) {
ctx.beginPath();
ctx.arc(bx - size2, by - size2, size2 + 1, 0, 2 * Math.PI);
ctx.fill();
ctx.beginPath();
ctx.arc(bx + size2, by + size2, size2 - 1, 0, 2 * Math.PI);
ctx.fill();
} else {
ctx.beginPath();
ctx.arc(bx + size2, by - size2, size2 + 1, 0, 2 * Math.PI);
ctx.fill();
ctx.beginPath();
ctx.arc(bx - size2, by + size2, size2 - 1, 0, 2 * Math.PI);
ctx.fill();
}
}
ctx.globalAlpha = 1
})
}
//DRAW EYES
var currentBlock = piece.blocks[piece.eyeBlock]
var bx = piece.position.x + blockSize * currentBlock[0]
var by = piece.position.y + blockSize * currentBlock[1]
var eyeSize = 14
ctx.beginPath();
ctx.fillStyle = "#5D4E51"
ctx.arc(bx - bSize / 5, by, eyeSize, 0, 2 * Math.PI);
ctx.fill();
ctx.beginPath();
ctx.arc(bx + bSize - bSize / 5, by, eyeSize, 0, 2 * Math.PI);
ctx.fill();
ctx.beginPath();
ctx.fillStyle = "#fff"
ctx.arc(bx + bSize / 15 - bSize / 5, by - bSize / 15, eyeSize / 2.5, 0, 2 * Math.PI);
ctx.fill();
ctx.beginPath();
ctx.arc(bx + bSize + bSize / 15 - bSize / 5, by - bSize / 15, eyeSize / 2.5, 0, 2 * Math.PI);
ctx.fill();
}
}
//center2
ctx.save();
if (endCinematicState == 0) {
center2Alpha += 0.05
} else if (endCinematicState == 1) {
bag.originalPosition.y -= 60
}
ctx.globalAlpha = center2Alpha
ctx.translate(bag.position.x + minX * blockSize - bSize - bSize, bag.position.y + minY * blockSize)
ctx.beginPath();
ctx.lineWidth = 20
ctx.strokeStyle = "#5D4E51"
ctx.fillStyle = bagColor
var vertices = [{
x: 30,
y: -80
}, {
x: (ww * blockSize) / 2 + bSize,
y: -hh / 2 * blockSize - 80
}, {
x: ww * blockSize + bSize - 30 + bSize,
y: -80
}, {
x: ww * blockSize + bSize + bSize,
y: hh * blockSize
}, {
x: 0,
y: hh * blockSize
}];
roundedPoly(vertices, 90)
ctx.stroke()
ctx.fill()
ctx.restore()
ctx.save()
ctx.clip()
ctx.globalAlpha = center2Alpha
ctx.translate(bag.position.x + minX * blockSize - bSize - bSize, bag.position.y + minY * blockSize)
ctx.fillStyle = "#5D4E51"
ctx.roundRect(0, -hh / 2 * blockSize - 80, w, hh / 2 * blockSize, 0)
ctx.fill()
ctx.restore()
ctx.save()
//if ww is odd
var offs = 0
if (Math.abs(ww % 2) != 1) {
offs = -bSize
}
var sss = Math.min(ww, hh)
ctx.translate(bag.position.x + maxX * blockSize - sss / 4 * blockSize, bag.position.y + bSize / 2 + maxY * blockSize - sss / 6 * blockSize)
ctx.scale(0.08 * sss, 0.08 * sss)
ctx.rotate(-0.2, -0.2)
ctx.globalAlpha = center2Alpha * 0.5
ctx.strokeStyle = "#5D4E51";
ctx.fillStyle = "#5D4E51";
ctx.beginPath();
ctx.lineWidth = 20
var sX = 650
var sY = 350
ctx.roundRect(-sX / 2, -sY / 2, sX, sY, 45)
ctx.stroke();
//
ctx.font = "bold 170px Tahoma";
ctx.textAlign = "center";
ctx.save()
ctx.fillText("PACKA", 0, 0);
ctx.restore()
ctx.save()
ctx.font = "bold 118px Tahoma";
ctx.fillText("BUNCHAS", 0, 0 + 120);
ctx.restore()
ctx.restore()
ctx.globalAlpha = 1
}
function drawButtons() {
ctx.strokeStyle = "#5D4E51";
for (let bb = 0; bb < buttons.length; bb++) {
var currentButton = buttons[bb]
var xx = 0 - mouseX / 80
var yy = 0 - mouseY / 80
var newX = xx + currentButton.originalx
var newY = yy + currentButton.originaly
currentButton.x = lerp(currentButton.x, newX, lerpSpeed)
currentButton.y = lerp(currentButton.y, newY, lerpSpeed)
//draw bg
if (currentButton.isPressed == true) {
ctx.globalAlpha = 0.5
}
var roundness = 90
if (currentButton == muteButton || currentButton == fullScreenButton) roundness = 10
ctx.fillStyle = "#FFEA7E";
ctx.roundRect(currentButton.x - currentButton.w / 2, currentButton.y - currentButton.h / 2, currentButton.w, currentButton.h, roundness)
ctx.lineWidth = 5
ctx.fill()
ctx.stroke()
if (currentButton == muteButton) {
ctx.fillStyle = "#5D4E51";
var scal = 0.8
ctx.save()
ctx.scale(scal, scal)
ctx.translate(currentButton.x / scal, currentButton.y / scal)
ctx.beginPath();
ctx.moveTo(-35 + 5, -30);
ctx.lineTo(+35 - 5, -45);
ctx.lineTo(+35 - 5, -15);
ctx.lineTo(-35 + 5, -0);
ctx.closePath();
ctx.fill();
//
ctx.roundRect(-35 + 5, -30, 10, 70, 1)
ctx.fill();
ctx.roundRect(+30 - 5, -45, 10, 70, 1)
ctx.fill();
//
ctx.roundRect(-50 + 5, +22, 25, 25, 90)
ctx.fill();
ctx.roundRect(+15 - 5, +10, 25, 25, 90)
ctx.fill();
if (muted == true) {
var siz = 30
ctx.lineWidth = 15
ctx.strokeStyle = "#FF7E64"
ctx.beginPath();
ctx.moveTo(-siz, -siz);
ctx.lineTo(+siz, +siz);
ctx.closePath();
ctx.stroke();
ctx.beginPath();
ctx.moveTo(+siz, -siz);
ctx.lineTo(-siz, +siz);
ctx.closePath();
ctx.stroke();
}
ctx.restore()
}
if (currentButton == fullScreenButton) {
ctx.fillStyle = "#5D4E51";
ctx.save()
ctx.translate(currentButton.x, currentButton.y)
var cic = 10
ctx.roundRect(-45 + 5 + 5, -45 + 10 + 5 - 3 - 1, 30, cic, 180)
ctx.fill()
ctx.roundRect(-45 + 5 + 5, -45 + 10 + 5 - 3 - 1, cic, 30, 180)
ctx.fill()
//
ctx.roundRect(20 - 10 - 5, -45 + 10 + 5 - 3 - 1, 30, cic, 180)
ctx.fill()
ctx.roundRect(40 - 10 - 5, -45 + 10 + 5 - 3 - 1, cic, 30, 180)
ctx.fill()
//
ctx.roundRect(20 - 10 - 5, 40 - 10 - 5 - 1, 30, cic, 180)
ctx.fill()
ctx.roundRect(40 - 10 - 5, 20 - 10 - 5 - 1, cic, 30, 180)
ctx.fill()
//
ctx.roundRect(-45 + 5 + 5, 40 - 10 - 5 - 1, 30, cic, 180)
ctx.fill()
ctx.roundRect(-45 + 5 + 5, 20 - 10 - 5 - 1, cic, 30, 180)
ctx.fill()
ctx.restore()
}
ctx.fillStyle = "#5D4E51";
ctx.textAlign = "center";
ctx.font = "bold " + currentButton.fSize + "px Tahoma";
ctx.fillText(currentButton.text, currentButton.x + currentButton.xoff, currentButton.y + currentButton.yoff);
ctx.globalAlpha = 1
}
}
function drawCharacter(posx, posy, scale) {
ctx.save()
ctx.scale(scale, scale)
ctx.translate(posx / scale, posy / scale)
ctx.lineWidth = 10
ctx.strokeStyle = "#5D4E51";
ctx.fillStyle = "#5D4E51"
ctx.roundRect(-30, 60, 100, 160, 180)
ctx.fill()
ctx.roundRect(-30 + 310, 60, 100, 160, 180)
ctx.fill()
//
ctx.roundRect(40, 270, 100, 160, 180)
ctx.fill()
ctx.roundRect(210, 270, 100, 160, 180)
ctx.fill()
//
ctx.strokeStyle = "#5D4E51";
ctx.fillStyle = "#FFEA7E"
ctx.roundRect(0, 0, 300 + 50, 400, 90)
ctx.fill()
ctx.stroke()
ctx.fillStyle = "#FDF3BD"
ctx.roundRect(30, 40, 240 + 50, 190, 45)
ctx.fill()
//
//ctx.stroke()
//
ctx.fillStyle = "#fff"
ctx.beginPath();
ctx.ellipse(100, 130, 35, 55, 0, 0, 2 * Math.PI);
ctx.fill();
ctx.fillStyle = "#A09CF1"
ctx.beginPath();
ctx.ellipse(100, 120, 25, 45, 0, 0, 2 * Math.PI);