-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
2575 lines (2250 loc) · 73.2 KB
/
index.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
var canvas = document.getElementById("canvas")
if (typeof (canvas.getContext) !== undefined) {
ctx = canvas.getContext("2d")
}
canvas.height = Math.floor(document.documentElement.clientHeight)
canvas.width = Math.floor(document.documentElement.clientWidth)
/*
canvas.height = Math.floor(window.innerHeight * 3 / 4)
canvas.width = Math.floor(window.innerWidth * 3 / 4)
*/
//###########################################################################################################
// GLOBALS GLOBALS GLOBALS GLOBALS
//###########################################################################################################
//#####################################
// COLORS AND STYLINGS
//#####################################
const BLACK = "rgb(0,0,0)"
const SILVER = "rgb(192,192,192)"
const SIENNA = "rgb(160,82,45)"
const BLUE = "rgb(0,0,255)"
const HOT_PINK = "rgb(255,105,180)"
const LIGHT_GREY = "rgb(220,220,220)"
const RED = "rgb(255,0,0)"
const ORANGE = "rgb(255,140,0)"
const SANDY_YELLOW = "rgb(253,223,119)"
const SANDY_BROWN = "rgb(244,164,96)"
const IVORY = "#fffff0"
const LIMESTONE = "rgb(246,248,220)"
const GRANITE = "#4A5355"
const BRONZE = "#88540b"
const GREEN = "rgb(0,255,0)"
const PURPLE = "rgb(148,0,211)"
const DIRT_BROWN = "#573B0C"
const DUNGEON_BRONZE = "#594f46"
const LIGHT_GREEN = "rgb(152,251,152)"
const DEEP_SKY_BLUE = "rgb(0,191,255)"
const ROYAL_PURPLE = "#7851a9 "
const ORANGE_YELLOW = "#ffae42"
const IMPERIAL_RED = "#ED2939"
const MAHOGANY = "#5B443E"
const END_DARK_ALPHA = 0.5
const VOID_COLOR = BLACK
const PORTAL_COLOR = SILVER
const PORTAL_FADE_COLOR = BLACK
const TEXT_BACKGROUND_COLOR = IVORY// "rgb(222,184,135)"
const TEXT_BORDER_COLOR = LIGHT_GREY
const TEXT_FONT = "20px Arial"
const TEXT_COLOR = "rgb(0,0,0)"
const GREEK_FLOOR_COLOR = IVORY
const GREEK_WALL_COLOR = SILVER
const GREEK_COL_COLOR = SILVER
const CORNER_OBJ_COLOR = SIENNA
const VESTIBULE_COLOR = BRONZE
const ROMAN_WALL_COLOR = VESTIBULE_COLOR
const ROMAN_FLOOR_COLOR = GRANITE
const CROSS_COLOR = ORANGE
const FRANCE_FLOOR_COLOR = GRANITE
const FRANCE_WALL_COLOR = BRONZE
const FRANCE_OFF_COLOR = SIENNA
const EGYPT_FLOOR_COLOR = SANDY_YELLOW
const EGYPT_WALL_COLOR = SANDY_BROWN
const EGYPT_COL_COLOR = SANDY_BROWN
const PHAROH_COLOR = BRONZE
const END_FLOOR_COLOR = LIGHT_GREY
const END_WALL_COLOR = BRONZE
const OVERWORLD_WALL_COLOR = DUNGEON_BRONZE
const OVERWORLD_FLOOR_COLOR = DIRT_BROWN
const TORCH_SILVER = SILVER
const TORCH_BROWN = SIENNA
const GREEK_DOOR_COLOR = DEEP_SKY_BLUE
const ROMAN_DOOR_COLOR = ROYAL_PURPLE
const FRANCE_DOOR_COLOR = IMPERIAL_RED
const EGYPT_DOOR_COLOR = ORANGE_YELLOW
const FINAL_DOOR_COLOR = MAHOGANY
const FINAL_DOOR_STROKE = SILVER
const OPEN_DOOR_COLOR = IVORY
const TEST_STRING = "hello, my name is joe, I want to tell you all about what I have been up to lately. I have to make way more filler text than I expected which is why none of this means anything unless you subscribe to iceberg theory where even if I'm not trying to inject any meaning, tunconscious event in my mind influence my writing in a such a way as to make my opinion about my work irrelevant"
const TO_STRING = "You can't tell what's different, but the world is not the same as it just was...."
const GREEK_VICTORY_TEXT = "You feel a slight breeze. Somewhere far away, a bird sings. Your work here is done."
const ROMAN_VICTORY_TEXT = "A loud hiss echos through the chamber. Order has been restored, and your work here is done."
const FRANCE_VICTORY_TEXT = "Aha! As the last one clicks into place, the unholy mirage begins to fade. Your work here is done."
const EGYPT_VICTORY_TEXT = "An old clay tablet, with something written on it... \n \"Who are you who can walk through walls? Surely no mere door could stop you. \""
const DEFAULT_OVERLAY_TEXT = "You squint with scrutiny, but find nothing of interest..."
//####################################
// CONST VALUES
//###################################
const PORTAL_POINTS_CONST = 50
const PORTAL_POINTS_RADIUS = 1
const CELL_SIZE = 40
const HALF_CELL = Math.floor(CELL_SIZE / 2)
const SHIFT_TIME = 300 // in millis
const SCREEN = {
width: 600,
height: 600
}
const CENTER_ROW = Math.floor(Math.floor(SCREEN.height / CELL_SIZE) / 2)
const CENTER_COL= Math.floor(Math.floor(SCREEN.width / CELL_SIZE) / 2)
const ORIGIN = {
x: Math.floor((canvas.width - SCREEN.width) / 2),
y: Math.floor((canvas.height - SCREEN.height) / 2)
}
const MAIN_SPAWN = 0
const GREECE_SPAWN = 1
const ROME_SPAWN = 2
const FRANCE_SPAWN = 3
const EGYPT_SPAWN = 4
const END_SPAWN = 5
//console.log(`can wh=${canvas.width},${canvas.height}, origing=${ORIGIN.x},${ORIGIN.y}`)
//#####################################
// ENUMS
//#####################################
const SOLVED = 0;
const UNSOLVED = 1;
const PRIMARY = 73 // "i"
const SECONDARY = 71// "g"
const INSPECT = "inspect"
const GRAB = "grab"
const LEFT = "left"
const RIGHT = "right"
const UP = "up"
const DOWN = "down"
const TEXT_FINISHED = -1
//######################################
// GLOBAL DATASTRUCTURES
//######################################
const mapData = new Map()
mapData.set("greece", {
path: "map_jsons/greece.json",
template: null
})
mapData.set("overworld", {
path: "map_jsons/overworld.json",
template: null
})
mapData.set("rome", {
path: "map_jsons/rome.json",
template: null
})
mapData.set("france", {
path: "map_jsons/france.json",
template: null
})
mapData.set("egypt", {
path: "map_jsons/egypt.json",
template: null
})
mapData.set("end", {
path: "map_jsons/end.json",
template: null
})
const questProgress = {
greece: UNSOLVED,
france: UNSOLVED,
egypt: UNSOLVED,
rome: UNSOLVED
}
function totalVictory() {
return (questProgress.greece == SOLVED &&
questProgress.rome == SOLVED &&
questProgress.france == SOLVED &&
questProgress.egypt == SOLVED)
}
const dirMap = new Map()
dirMap.set(LEFT, [-1, 0])
dirMap.set(UP, [0, -1])
dirMap.set(RIGHT, [1, 0])
dirMap.set(DOWN, [0, 1])
var keyData = {
keyStack: new Array(),
isKeyNew: new Map(),
logic: null,
isBlocking: false
}
keyData.isKeyNew.set(LEFT, true)
keyData.isKeyNew.set(UP, true)
keyData.isKeyNew.set(RIGHT, true)
keyData.isKeyNew.set(DOWN, true)
keyData.isKeyNew.set(INSPECT, true)
keyData.isKeyNew.set(GRAB, true)
function registerEventListeners() {
document.addEventListener("keydown", onKeyPress , false)
document.addEventListener("keyup", onKeyUp , false)
}
function onKeyPress(event) {
if (event.keyCode == '37' && keyData.isKeyNew.get(LEFT)) {
keyData.keyStack.push(LEFT)
keyData.isKeyNew.set(LEFT, false)
keyData.logic(LEFT)
}
else if (event.keyCode == '38' && keyData.isKeyNew.get(UP)) {
keyData.keyStack.push(UP)
keyData.isKeyNew.set(UP, false)
keyData.logic(UP)
}
else if (event.keyCode == '39' && keyData.isKeyNew.get(RIGHT)) {
keyData.keyStack.push(RIGHT)
keyData.isKeyNew.set(RIGHT, false)
keyData.logic(RIGHT)
}
else if (event.keyCode == '40' && keyData.isKeyNew.get(DOWN)) {
keyData.keyStack.push(DOWN)
keyData.isKeyNew.set(DOWN, false)
keyData.logic(DOWN)
}
else if (event.keyCode == PRIMARY && keyData.isKeyNew.get(INSPECT)) {
keyData.isKeyNew.set(INSPECT, false)
keyData.logic(INSPECT)
}
else if (event.keyCode == SECONDARY && keyData.isKeyNew.get(GRAB)) {
keyData.isKeyNew.set(GRAB, false)
keyData.logic(GRAB)
}
}
function onKeyUp(event) {
if (event.keyCode == '37') {
keyData.keyStack.splice(keyData.keyStack.indexOf(LEFT), 1)
keyData.isKeyNew.set(LEFT, true)
if (keyData.keyStack.length !== 0) keyData.logic(keyData.keyStack[keyData.keyStack.length - 1])
}
else if (event.keyCode == '38') {
keyData.keyStack.splice(keyData.keyStack.indexOf(UP), 1)
keyData.isKeyNew.set(UP, true)
if (keyData.keyStack.length !== 0) keyData.logic(keyData.keyStack[keyData.keyStack.length - 1])
}
else if (event.keyCode == '39') {
keyData.keyStack.splice(keyData.keyStack.indexOf(RIGHT), 1)
keyData.isKeyNew.set(RIGHT, true)
if (keyData.keyStack.length !== 0) keyData.logic(keyData.keyStack[keyData.keyStack.length - 1])
}
else if (event.keyCode == '40') {
keyData.keyStack.splice(keyData.keyStack.indexOf(DOWN), 1)
keyData.isKeyNew.set(DOWN, true)
if (keyData.keyStack.length !== 0) keyData.logic(keyData.keyStack[keyData.keyStack.length - 1])
}
else if (event.keyCode == PRIMARY) {
keyData.isKeyNew.set(INSPECT, true)
}
else if (event.keyCode == SECONDARY) {
keyData.isKeyNew.set(GRAB, true)
keyData.logic(GRAB)
}
}
function blockLogic(logic) {
//// console.log("blocking logic")
}
//###########################################################################################################
//
//###########################################################################################################
/////////////////////////////////////////////////////
var drawable = {
draw: function(mapOrigin, row, col, delta, dir, alpha) {
// // console.log(`draw: orig=${mapOrigin} rox,col = [${row},${col}] delta=${delta}`)
let relRow = row - mapOrigin[0]
let relCol = col - mapOrigin[1]
if (isInView(relRow, relCol, dir)) {
let coord = gridToGlobal(relRow, relCol, delta, dir)
// // console.log(`coord = ${coord} relr,c=[${relRow},${relCol}]`)
this.drawImg(coord[0], coord[1], alpha)
// drawGridRect(coord[0], coord[1], relRow, relCol, "rgb(0,255,255)")//default
}
},
inc: function(dir) {
this.row += dir[1]
this.col += dir[0]
},
singleCellContains: function(row, col) {
return this.row == row && this.col == col
},
getSingleCellFrontier: function(dir) {
return [[incRow(this.row, dir), incCol(this.col, dir)]]
}
}
var bigDrawable = {
draw: function(mapOrigin, row, col, delta, dir, alpha) {
let relRow = row - mapOrigin[0]
let relCol = col - mapOrigin[1]
let cells = this.getCells(relRow, relCol)
let d = false
cells.forEach(function(cell) {
if (isInView(cell[0], cell[1], dir)) d = true
})
if (d) {
let coord = gridToGlobal(relRow, relCol, delta, dir)
this.drawImg(coord[0], coord[1], alpha)
// drawGridRect(coord[0], coord[1], relRow, relCol, "rgb(0,255,255)")//default
}
}
}
var player = Object.create(drawable, {
row: {value: 0,
writable: true},
col: {value: 0,
writable: true},
dir: {value: [0,1]},
drawImg: {value: function(x, y, alpha) {
// // console.log("drawing Player x,y = " + x + ", " + y)
drawGridRect(x, y, "rgb(255,0,0)")
}},
isMoving: {value: true,
writable: true},
contains: {value: function(row, col) {
return this.row === row && this.col === col
}},
getAdjCells: {value: function() {
var l = []
for (const dir of dirMap.values()) {
//// console.log(dir)
let coord = []
coord.push(incRow(this.row, dir))
coord.push(incCol(this.col, dir))
l.push(coord)
}
return l
}}
})
var overLay = {
registerCallback: function(callback) {
this.callback = callback
},
registerLogic: function(logic) {
this.prevLogic = logic
keyData.logic = this.eventLogic
},
callback: null,
prevLogic: null,
}
function textOverlay(text) {
var overlay = Object.create(overLay, {
text: {value: text},
textpnt: {value: 0,
writable: true
}
})
overlay.hasTrigger = false
overlay.eventLogic = function(worldEvent) {
if (worldEvent === INSPECT) {
// console.log(overlay)
overlay.step()
}
if (worldEvent === GRAB) {
overlay.prevLogic(GRAB)
}
}
overlay.curText = text
overlay.step = function() {
if (overlay.textpnt !== TEXT_FINISHED) {
let pnt = wrappedTextbox(overlay.curText)
if (pnt === TEXT_FINISHED) overlay.textpnt = TEXT_FINISHED
else {
overlay.textpnt += pnt
overlay.curText = overlay.text.slice(overlay.textpnt, overlay.text.length)
}
}
else {
if (overlay.hasTrigger) {
overlay.activateTrigger()
}
keyData.logic = overlay.prevLogic
overlay.callback()
overlay.textpnt = 0
overlay.curText = overlay.text
}
}
return overlay
}
function defaultOverlay() {
return textOverlay(DEFAULT_OVERLAY_TEXT)
}
function textOverlayVictoryTrigger(text, trigger) {
let overlay = textOverlay(text)
overlay.hasTrigger = true
overlay.activateTrigger = trigger
return overlay
}
function deltaDir(delta, dir) {
let index = Math.floor(Math.abs(dir[0] + dir[1]) / 2)
let x = delta[1 - index] * dir[0]
let y = delta[index] * dir[1]
return [x, y]
}
function gridDeltaDir(delta, dir) {
let index = Math.floor(Math.abs(dir[0] + dir[1]) / 2)
let r = delta[1 - index] * dir[1]
let c = delta[index] * dir[0]
return [r,c]
}
function dumbMoveDir(delta, dir) {
let index = Math.floor(Math.abs(dir[0] + dir[1]) / 2)
let x = delta[1 - index] * dir[1]
let y = delta[index] * dir[0]
return [x, y]
}
function dist(p0,p1) {
let sum = 0
for (i = 0; i < p0.length; i ++) {
sum += Math.pow(Math.abs(p0[i] - p1[i]), 2)
}
return Math.sqrt(sum)
}
//https://stackoverflow.com/questions/12219802/a-javascript-function-that-returns-the-x-y-points-of-intersection-between-two-ci
// ^thanks dude
function intersection(x0, y0, r0, x1, y1, r1) {
var a, dx, dy, d, h, rx, ry;
var x2, y2;
/* dx and dy are the vertical and horizontal distances between
* the circle centers.
*/
dx = x1 - x0;
dy = y1 - y0;
/* Determine the straight-line distance between the centers. */
d = Math.sqrt((dy*dy) + (dx*dx));
/* Check for solvability. */
if (d > (r0 + r1)) {
/* no solution. circles do not intersect. */
return false;
}
if (d < Math.abs(r0 - r1)) {
/* no solution. one circle is contained in the other */
return false;
}
/* 'point 2' is the point where the line through the circle
* intersection points crosses the line between the circle
* centers.
*/
/* Determine the distance from point 0 to point 2. */
a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;
/* Determine the coordinates of point 2. */
x2 = x0 + (dx * a/d);
y2 = y0 + (dy * a/d);
/* Determine the distance from point 2 to either of the
* intersection points.
*/
h = Math.sqrt((r0*r0) - (a*a));
/* Now determine the offsets of the intersection points from
* point 2.
*/
rx = -dy * (h/d);
ry = dx * (h/d);
/* Determine the absolute intersection points. */
var xi = x2 + rx;
var xi_prime = x2 - rx;
var yi = y2 + ry;
var yi_prime = y2 - ry;
return [xi, xi_prime, yi, yi_prime];
}
var turtle = {
x: 0,
y: 0,
beginPath: function() {
ctx.beginPath()
},
moveTo: function(delta) {
this.x += delta[0]
this.y += delta[1]
ctx.moveTo(this.x, this.y)
},
lineTo: function(delta) {
this.x += delta[0]
this.y += delta[1]
ctx.lineTo(this.x, this.y)
},
arcTo: function(delta, radius, innerArc) {
let xp = this.x + delta[0]
let yp = this.y + delta[1]
let centers = intersection(this.x, this.y, radius, xp, yp, radius)
let cx = (innerArc) ? centers[0] : centers[1] //guessed at these, let's see if they actually work
let cy = (innerArc) ? centers[2] : centers[3]
let startAngle = Math.atan2(this.y - cy, this.x - cx)
let endAngle = Math.atan2(yp - cy, xp - cx)
ctx.arc(cx, cy, radius, startAngle, endAngle, !innerArc)
this.x = xp
this.y = yp
},
closePath: function() {
ctx.closePath()
},
stroke: function(color) {
let orig = ctx.strokeStyle
ctx.strokeStyle = color
ctx.stroke()
ctx.strokeStyle = orig
},
fill: function(color) {
let orig = ctx.fillStyle
ctx.fillStyle = color
ctx.fill()
ctx.fillStyle = orig
}
}
//#######################################################################3
// CELLS AND MAP FEATURES MAKING THEM WORLDS AREALITY
//########################################################################
var cellPrototype = Object.create(drawable, {
drawImg: {value: function(x, y, alpha) {
drawGridRect(x, y, "rgb(0,255,255)")//default
}},
isObstacle: {value: false}
})
function emptyCell(overlay) {
let cell = Object.create(cellPrototype)
cell.overlay = overlay
return cell
}
function worldEdgeCell() {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
drawGridRect(x, y, BLACK)
}
cell.isObstacle = true
return cell
}
function portalCell(dir) {
let cell = Object.create(drawable)
let points = []
for (i = 0; i < 50; i ++) {
let dx = Math.floor(Math.random() * CELL_SIZE)
let dy = Math.floor(Math.random() * CELL_SIZE)
points.push([dx,dy])
}
cell.drawImg = function(x, y, alpha) {
drawGradientRect(x, y, PORTAL_COLOR, PORTAL_FADE_COLOR, dir)
//drawRect(x, y, BLUE)
/* points.forEach(function(pnt) {
drawCircle(x + pnt[0], y + pnt[1], 1, PORTAL_SPOT_COLOR)
})*/
}
cell.isObstacle = false
return cell
}
function lowerPortal() {
return portalCell(1)
}
function upperPortal() {
return portalCell(-1)
}
function greekCol(size) {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
drawRect(x, y, GREEK_FLOOR_COLOR)
drawCircle(x + HALF_CELL, y + HALF_CELL, size, GREEK_COL_COLOR)
}
cell.isObstacle = true
return cell
}
function bigCol() {
return greekCol(HALF_CELL)
}
function medCol() {
return greekCol(Math.floor(HALF_CELL * 3/4))
}
function smallCol() {
return greekCol(Math.floor(HALF_CELL / 2))
}
function greekWallCell() {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
drawRect(x, y, GREEK_WALL_COLOR)
}
cell.isObstacle = true
return cell
}
function greekFloorCell() {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
drawRect(x, y, GREEK_FLOOR_COLOR)
}
cell.isObstacle = false
return cell
}
/////////////////////////
function normalDoor(color) {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
drawGenRect(x, y, 3 * CELL_SIZE, 3 * CELL_SIZE, OVERWORLD_WALL_COLOR)
drawCircle(x + CELL_SIZE + HALF_CELL, y + CELL_SIZE + HALF_CELL, CELL_SIZE + HALF_CELL, color)
drawGenRect(x, y + CELL_SIZE + HALF_CELL, 3 * CELL_SIZE, 2 * CELL_SIZE, color)
}
cell.isObstacle = false
cell.isLink = true
return cell
}
function greekDoor() {
return normalDoor(GREEK_DOOR_COLOR)
}
function romeDoor() {
return normalDoor(ROMAN_DOOR_COLOR)
}
function franceDoor() {
return normalDoor(FRANCE_DOOR_COLOR)
}
function egyptDoor() {
return normalDoor(EGYPT_DOOR_COLOR)
}
function finalDoor() {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
drawGenRect(x, y, CELL_SIZE * 4, CELL_SIZE * 6, OVERWORLD_WALL_COLOR)
drawCircle(x + 2 * CELL_SIZE, y + CELL_SIZE * 2, 2 * CELL_SIZE, FINAL_DOOR_COLOR)
drawGenRect(x, y + 2 * CELL_SIZE, 4 * CELL_SIZE, 4 * CELL_SIZE, FINAL_DOOR_COLOR)
drawTorch(x, y + 2 * CELL_SIZE,
(questProgress.greece == SOLVED) ? GREEK_DOOR_COLOR: FINAL_DOOR_COLOR,
(questProgress.greece == SOLVED) ? ORANGE: FINAL_DOOR_COLOR)
drawTorch(x, y + 4 * CELL_SIZE,
(questProgress.rome == SOLVED) ? ROMAN_DOOR_COLOR: FINAL_DOOR_COLOR,
(questProgress.rome == SOLVED) ? ORANGE : FINAL_DOOR_COLOR)
drawTorch(x + 2 * CELL_SIZE, y + 2 * CELL_SIZE,
(questProgress.france == SOLVED) ? FRANCE_DOOR_COLOR: FINAL_DOOR_COLOR,
(questProgress.france == SOLVED) ? ORANGE: FINAL_DOOR_COLOR)
drawTorch(x + 2 * CELL_SIZE, y + 4 * CELL_SIZE,
(questProgress.egypt == SOLVED) ? EGYPT_DOOR_COLOR: FINAL_DOOR_COLOR,
(questProgress.egypt == SOLVED) ? ORANGE: FINAL_DOOR_COLOR)
if(totalVictory()) {
drawCircle(x + 2 * CELL_SIZE, y + CELL_SIZE * 2, 2 * CELL_SIZE, OPEN_DOOR_COLOR)
drawGenRect(x, y + 2 * CELL_SIZE, 4 * CELL_SIZE, 4 * CELL_SIZE, OPEN_DOOR_COLOR)
}
}
cell.isObstacle = true
cell.isLink = true
return cell
}
function secretDoor() {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
drawGenRect(x, y, CELL_SIZE * 2, CELL_SIZE * 2, OVERWORLD_WALL_COLOR)
drawCircle(x + CELL_SIZE, y + CELL_SIZE, CELL_SIZE, FINAL_DOOR_COLOR)
drawGenRect(x, y + CELL_SIZE, 2 * CELL_SIZE, CELL_SIZE, FINAL_DOOR_COLOR)
}
cell.isObstacle = true
cell.isLink = true
return cell
}
function overworldTopWall() {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
drawRect(x, y, OVERWORLD_WALL_COLOR)
}
cell.isObstacle = true
return cell
}
function overworldLeftWall() {
return overworldTopWall()
}
function overworldRightWall() {
return overworldTopWall()
}
function overworldBotWall() {
return overworldTopWall()
}
function blankObstacle() {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {}
cell.isObstacle = true
return cell
}
function blankNonObstacle() {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {}
cell.isObstacle = false
return cell
}
function torch() {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
drawGenRect(x, y, 2 * CELL_SIZE, 2 * CELL_SIZE, OVERWORLD_WALL_COLOR)
drawTorch(x, y, RED, ORANGE)
}
cell.isObstacle = true
cell.isLink = true
return cell
}
function overworldFloor() {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
drawRect(x, y, OVERWORLD_FLOOR_COLOR)
}
cell.isObstacle = false
return cell
}
//////////////////////////////////////////
function linkedCell(link, transform, isObstacle, color) {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
if (!link.hasBeenDrawn) {
let coord = transform(x, y)
drawRect(x, y, color)
link.drawImg(coord[0], coord[1], alpha)
}
}
cell.isObstacle = isObstacle
return cell
}
function romeAlcove(dir) {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
x = (dir[0] == 1) ? x : x + CELL_SIZE
y = (dir[1] == 1) ? y : y + CELL_SIZE
turtle.x = x
turtle.y = y
turtle.beginPath()
turtle.moveTo(deltaDir([-8 * CELL_SIZE, 10 * CELL_SIZE], dir))
turtle.arcTo(deltaDir([17 * CELL_SIZE, 0], dir), 8 * CELL_SIZE + HALF_CELL, true)
turtle.lineTo(deltaDir([-2 * CELL_SIZE, 0], dir))
turtle.lineTo(deltaDir([0, -2 * CELL_SIZE], dir))
turtle.lineTo(deltaDir([-2 * CELL_SIZE, 0], dir))
turtle.arcTo(deltaDir([-9 * CELL_SIZE, 0], dir), Math.floor(9 / 2 * CELL_SIZE), false)
turtle.lineTo(deltaDir([-2 * CELL_SIZE, 0], dir))
turtle.lineTo(deltaDir([0, 2 * CELL_SIZE], dir))
turtle.lineTo(deltaDir([-2 * CELL_SIZE, 0], dir))
turtle.closePath()
turtle.fill(VESTIBULE_COLOR)
}
cell.isObstacle = true
cell.isLink = true
return cell
}
function romeAlcoveTop() {
return romeAlcove([1,1])
}
function romeAlcoveRight() {
return romeAlcove([-1,1])
}
function romeAlcoveLeft() {
return romeAlcove([1, -1])
}
function romeWall() {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
drawRect(x, y, ROMAN_WALL_COLOR)
}
cell.isObstacle = true
return cell
}
function romeFloor() {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
drawRect(x, y, ROMAN_FLOOR_COLOR)
}
cell.isObstacle = false
return cell
}
function romeCorner(dir) {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
drawRect(x, y, HOT_PINK)
}
cell.isObstacle = true
cell.isLink = true
return cell
}
function romeCornerTL() {
return romeCorner([1,1])
}
function romeCornerTR() {
return romeCorner([-1,1])
}
function romeCornerBL() {
return romeCorner([1,-1])
}
function romeCornerBR() {
return romeCorner([-1,-1])
}
//////////
function romeMiddleRect(dir) {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
drawRect(x, y, HOT_PINK)
}
cell.isObstacle = true
cell.isLink = true
return cell
}
function romeMiddleRectLeft() {
return romeMiddleRect(-1)
}
function romeMiddleRectRight() {
return romeMiddleRect(1)
}
///////////
function romeSquare() {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
drawRect(x, y, HOT_PINK)
}
cell.isObstacle = true
cell.isLink = true
return cell
}
function romeVest(dir) {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
}
cell.isObstacle = true
cell.isLink = true
return cell
}
function romeVestLeft() {
return romeVest(-1)
}
function romeVestRight() {
return romeVest(1)
}
function romeWeirdVest() {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
turtle.x = x
turtle.y = y
turtle.beginPath()
turtle.lineTo([2 * CELL_SIZE, 0])
turtle.arcTo([4 * CELL_SIZE, 3 * CELL_SIZE], 3 * CELL_SIZE, false)
turtle.lineTo([0, CELL_SIZE])
turtle.lineTo([-6 * CELL_SIZE, 0])
turtle.lineTo([0, -4 * CELL_SIZE])
turtle.closePath()
turtle.fill(ROMAN_WALL_COLOR)
turtle.beginPath()
turtle.moveTo([11 * CELL_SIZE, 0])
turtle.lineTo([2 * CELL_SIZE, 0])
turtle.lineTo([0, 4 * CELL_SIZE])
turtle.lineTo([-6 * CELL_SIZE, 0])
turtle.lineTo([0, - CELL_SIZE])
turtle.arcTo([4 * CELL_SIZE, -3 * CELL_SIZE], 3 * CELL_SIZE, false)
turtle.closePath()
turtle.fill(ROMAN_WALL_COLOR)
}
cell.isObstacle = true
cell.isLink = true
return cell
}
//////////////////////////////////////////
// FRANCE BULLSHIT
/////////////////////////////////////////
function franceFloor() {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {
drawRect(x, y, FRANCE_FLOOR_COLOR)
}
cell.isObstacle = false
cell.isLink = false
return cell
}
function franceBigPillar() {
let cell = Object.create(drawable)
cell.drawImg = function(x, y, alpha) {