-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
executable file
·995 lines (820 loc) · 35.3 KB
/
index.html
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
<html>
<head>
<title>SparDrawersEpilepticDrools</title>
<link rel="stylesheet" href="css/style.css">
<link href='https://fonts.googleapis.com/css?family=Orbitron:400,900' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Bree+Serif' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Muli:400,300' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Trade+Winds' rel='stylesheet' type='text/css'>
</head>
<body background="images/background.png">
<div id="menu">
<ul id="wrapper">
<li>
<input id="enterName" type="text" value="" title="Come on, be creative" placeHolder="Nick" maxlength="15" spellcheck="false">
</li>
<li>
<input id="enterNumPlayers" type="text" value="" placeHolder="Number of players" maxlength="1">
</li>
<li>
<select id="player" class="noselect"></select>
</li>
<li>
<select id="biome" class="noselect">
<option>Forest</option>
<option>Desert</option>
<option>Mountain</option>
</select>
</li>
<li>
<button id="proceed" class="noselect">Next</button>
</li>
</ul>
</div>
<div id="statBar" class="noselect"> <!-- Stat Bar for player info and actions -->
<div id="statHealthFill"></div> <!-- Element that gets smaller as the current player's health gets lower -->
<h2 id="statName">Player 1</h2> <!-- Current player name -->
<h2 id="statCharacter">Greed</h2> <!-- Current player character type -->
<h3 id="statHealth">Health:</h3> <!-- Current player health label -->
<div id="statHealthNumber">20</div> <!-- Current player health variable displayed -->
<h3 id="statActions">Remaining Actions:</h3> <!-- Current player actions label -->
<div id="statActionNumber">2</div> <!-- Current player actions variable displayed -->
<div id="statActionButton">Roll</div> <!-- Button for proceeding though the current player's turn: Move -> End turn. -->
<h3 id="cardShowButtonText">Show Cards</h3> <!-- Label for card show button -->
<div id="cardShowButton" class="triangle"></div> <!-- Button for expanding the bar, showing the cards. -->
</div>
<canvas id="spriteCanvas"></canvas>
<canvas id="myCanvas" resize></canvas>
<div id="bBar">
<div class="deck"></div>
<div id="cards"></div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="js/paper-full.js"></script>
<!--<script type="text/javascript" src="js/spriteAnimationCode.js"></script> -->
<script type="text/paperscript" canvas="myCanvas">
/*
to do:
3. figure out what the hell to do with attacks
players[currentPlayer].health/players[currentPlayer].character.health
*/
// wrathSprite.destinationX = 900;
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
|| window[vendors[x]+'CancelRequestAnimationFrame'];
}
if (!window.requestAnimationFrame)
window.requestAnimationFrame = function(callback, element) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function() { callback(currTime + timeToCall); },
timeToCall);
lastTime = currTime + timeToCall;
return id;
};
if (!window.cancelAnimationFrame)
window.cancelAnimationFrame = function(id) {
clearTimeout(id);
};
}());
var wrathSprite;
(function () {
// var coin,
// coinImage,
// canvas;
var wrathImage,
canvas;
function gameLoop () {
window.requestAnimationFrame(gameLoop);
// coin.update();
// coin.render();
wrathSprite.update();
wrathSprite.render();
}
function sprite (options) {
var that = {},
frameIndex = 0,
tickCount = 0,
ticksPerFrame = options.ticksPerFrame || 0,
numberOfFrames = options.numberOfFrames || 1;
that.context = options.context;
that.width = options.width;
that.height = options.height;
that.destinationX = options.destinationX;
that.destinationY = options.destinationY;
that.sizeWidth = options.sizeWidth;
that.sizeHeight = options.sizeHeight;
that.image = options.image;
that.update = function () {
tickCount += 1;
if (tickCount > ticksPerFrame) {
tickCount = 0;
// If the current frame index is in range
if (frameIndex < numberOfFrames - 1) {
// Go to the next frame
frameIndex += 1;
} else {
frameIndex = 0;
}
}
};
that.render = function () {
// Clear the canvas
that.context.clearRect(that.destinationX - 100, that.destinationY - 100, that.sizeWidth+200, that.sizeHeight+200);
// Draw the animation
that.context.drawImage(
that.image,
frameIndex * that.width / numberOfFrames,
0, // potential for stacked spritesheet
that.width / numberOfFrames,
that.height,
that.destinationX, //destination x
that.destinationY, //destination y
that.sizeWidth,
that.sizeHeight,
that.width / numberOfFrames,
that.height);
};
return that;
}
// Get canvas
canvas = document.getElementById("spriteCanvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// Create sprite sheet
//coinImage = new Image();
wrathImage = new Image();
// Create sprite
// coin = sprite({
// context: canvas.getContext("2d"),
// width: 1000,
// height: 100,
// image: coinImage,
// numberOfFrames: 10,
// ticksPerFrame: 2
// });
wrathSprite = sprite({
context: canvas.getContext("2d"),
width: 3420,
height: 158,
destinationX: -500,
destinationY: -500,
sizeWidth: 110,
sizeHeight: 90,
image: wrathImage,
numberOfFrames: 18,
ticksPerFrame: 2
});
// Load sprite sheet
// coinImage.addEventListener("load", gameLoop);
// coinImage.src = "images/coin-sprite-animation.png";
wrathImage.addEventListener("load", gameLoop);
wrathImage.src = "images/tryRun2.png";
} ());
var expanded = false; // Is the bottom bar expanded?
var numCards = 0; // number of cards
var bBarWidth = 6;// width of bottom bar for cards
var healthRatio = 1; // change in health fill on the statbar
var currentAttack = 0, currentDefense = 0;
$("#cards").hide();
$('#bBar').hide(); // hides the card holder bar
$("#statBar").hide();
function expandBBar() {// expand the card shelf a.k.a. bottom bar
for (var i = 0; i < players[currentPlayer].cards.length; i += 1) {
$("#cards").append('<div class="cardy" id="' + players[currentPlayer].cards[i].css + '"><div id="cardLabels"><p id="attackLabel">' + players[currentPlayer].cards[i].attack + '</p> <p id="defendLabel">' + players[currentPlayer].cards[i].defend + '</p></div></div>');
}
$("#bBar").css("background", "#C96A4B");
$("#bBar").css("width", "80%");
$("#cards").delay(680).show(680);
$(".triangle").css("transform","rotate(30deg) skewX(-30deg) scale(1,.866)");
$("#cardShowButton").css("margin", "4.9vw 0vw 9vw 9vw")
$("#cardShowButtonText").html('Hide Cards')
if (numCards >= 4) {
$("#bBar").css("overflowX", "scroll");
}
if (turnCounter === 2) {
$("#statActionButton").html('Draw Card');
}
expanded = true;
}
function hideBBar() { // hide the card cabinet a.k.a. bottom bar
if (expanded === true) {
$("#cards").delay(600).show(600).finish();
$("#bBar").css("background", "#FF551C");
$("#bBar").css("width", "0");
$("#cards").hide(0);
$("#bBar").css("overflowX", "hidden");
for (var i = 0; i < players[currentPlayer].cards.length; i += 1) {
$(".cardy").remove();
}
$("#cardShowButton").css("margin", "3vw 0vw 9vw 7.5vw")
$("#cardShowButtonText").html('Show Cards')
$(".triangle").css("transform","rotate(-30deg) skewX(-30deg) scale(1,.866)");
if (turnCounter === 2) {
$("#statActionButton").html('Next Turn');
}
expanded = false;
}
}
$('#cardShowButton').click(function () {
"use strict";
if (expanded === false) {
expandBBar();
} else {
hideBBar();
}
});
$('#cardShowButtonText').click(function () {
"use strict";
if (expanded === false) {
expandBBar();
} else {
hideBBar();
}
});
$("body").on('click', '#card1', function () {
console.log("here is card1 click");
if (turnCounter === 2 && cardSelected === false && actionCounter !== 0) {
cardSelected = true;
currentAttack = playerTypes[0].cards[0].attack;
currentDefense = playerTypes[0].cards[0].defend;
this.remove();
}
});
$("body").on('click', '#card2', function () {
console.log("here is card2 click");
if (turnCounter === 2 && cardSelected === false && actionCounter !== 0) {
cardSelected = true;
currentAttack = playerTypes[0].cards[1].attack;
currentDefense = playerTypes[0].cards[1].defend;
this.remove();
}
});
$("body").on('click', '#card3', function () {
console.log("here is card3 click");
if (turnCounter === 2 && cardSelected === false && actionCounter !== 0) {
cardSelected = true;
currentAttack = playerTypes[0].cards[2].attack;
currentDefense = playerTypes[0].cards[2].defend;
this.remove();
}
});
$("body").on('click', '#card4', function () {
console.log("here is card4 click");
if (turnCounter === 2 && cardSelected === false && actionCounter !== 0) {
cardSelected = true;
currentAttack = playerTypes[0].cards[3].attack;
currentDefense = playerTypes[0].cards[3].defend;
this.remove();
}
});
$("body").on('click', '#card5', function () {
console.log("here is card5 click");
if (turnCounter === 2 && cardSelected === false && actionCounter !== 0) {
cardSelected = true;
currentAttack = playerTypes[0].cards[4].attack;
currentDefense = playerTypes[0].cards[4].defend;
this.remove();
}
});
$("body").on('click', '#card6', function () {
console.log("here is card6 click");
if (turnCounter === 2 && cardSelected === false && actionCounter !== 0) {
cardSelected = true;
currentAttack = playerTypes[0].cards[5].attack;
currentDefense = playerTypes[0].cards[5].defend;
this.remove();
}
});
$("body").on('click', '#card6', function () {
console.log("Here is being card clicked yo");
if (turnCounter === 2 && cardSelected === false && actionCounter !== 0) {
cardSelected = true;
currentAttack = playerTypes[0].cards[6].attack;
currentDefense = playerTypes[0].cards[6].defend;
this.remove();
}
});
//var scrollW = document.getElementsByClassName("");
function addCard() {
"use strict";
if (numCards < 10 && actionCounter > 0 && turnCounter === 2) {
numCards += 1;
var randomCardIndex = Math.floor((Math.random() * (players[currentPlayer].character.cards.length -1)));
//add a card li to the cards div
$("#cards").append('<div class="cardy" id="' + players[currentPlayer].character.cards[randomCardIndex].css + '"><div id="cardLabels"><p id="attackLabel">' + players[currentPlayer].character.cards[randomCardIndex].attack + '</p> <p id="defendLabel">' + players[currentPlayer].character.cards[randomCardIndex].defend + '</p></div></div>');
//extend bar width
bBarWidth += (players[currentPlayer].cards.length * 1.4 + 8);
$("#cards").css("width", bBarWidth + "vw");
if (numCards >= 4) {
$("#bBar").css("overflowX", "scroll");
}
players[currentPlayer].cards.push(players[currentPlayer].character.cards[randomCardIndex]);
actionCounter -= 1;
$("#statActionNumber").html(actionCounter);
}
}
var actionJustSwitched = true;
$("#statActionButton").click(function () {
if ($("#statActionButton").html() !== "Draw Card") {
turnCounter++;
if (turnCounter === 2) {
actionJustSwitched = true;
}
}
if (turnCounter === 3) { // next players turn !!!!!!!!!!!!!!!!!!!!!!
for (var i = 0; i < size; i += 1) {// clearing the highlights at end of turn
for (var ii = 0; ii < size; ii += 1) {
boardMain[i][ii].backgroundPath.visible = false; // reset all tiles to non movable
}
}
hideBBar();
currentPlayer++;
if (currentPlayer === players.length) {
currentPlayer = 0;
}
//hideBBar();
turnCounter = 0;
currentAttack = 0;
currentDefense = 0;
numCards = players[currentPlayer].cards.length;
actionCounter = players[currentPlayer].character.numActions;
cardSelected = false;
healthRatio = players[currentPlayer].health / players[currentPlayer].character.health;
$("#statHealthFill").css("transition", "top: 2s");
$("#statHealthFill").css("top", ((1 - healthRatio) * 100) + '%'); //slowly shifts red health fill downwards in sync with
$("#statName").html(players[currentPlayer].nick);
$("#statActionNumber").html(actionCounter);
$("#statHealthNumber").html(players[currentPlayer].health);
//$("#statName").html(players[currentPlayer].nick);
$("#statCharacter").html(players[currentPlayer].character.type);
} else if (turnCounter === 1) {
moveCounter = Math.floor((Math.random() * players[currentPlayer].character.dice) + 1);
}
if (turnCounter === 0) {
$("#statActionButton").html('Roll');
} else if (turnCounter === 1) {
$("#statActionButton").html('Action');
} else if (turnCounter === 2) {
if (expanded === true) {
$("#statActionButton").html('Draw Card');
if (actionJustSwitched === false) {
addCard();
}
} else {
$("#statActionButton").html('Next Turn');
}
actionJustSwitched = false;
}
for (var i = 0; i < size; i += 1) {//just trying to see where i can go
for (var ii = 0; ii < size; ii += 1) {
// move events here
boardMain[i][ii].backgroundPath.visible = false; // reset all tiles to non movable, then set them to movable don there\/
if (turnCounter === 1) { // if in the move phase
if (canPlayerMoveOrNah(ii,i)) {// shows you where you can move on the map
boardMain[i][ii].backgroundPath.visible = true;// can move here
}
}
}
}
});
$("#myCanvas").hide();
var size, biome, playerType, numPlayers = 30, gameSetup = 1, players = [], move = false, currentPlayer = 0, turnCounter = 0, moveCounter = 0, cardSelected = false, dragging = false;
var playerTypes = [// array of player types: add new player types here
{
type: 'Greed',
sprite: wrathSprite,
dice: 12,
health: 20,
numActions: 3,
cards: [// array of cards: put new cards here
{attack: 4,defend: 2,move: 5,count: 6, css: "card1"},
{attack: 5,defend: 1,count: 4, css: "card2"},
{attack: 6,defend: 0,count: 2, css: "card3"},
{attack: 3,defend: 4,count: 5, css: "card4"},
{attack: 3,defend: 0,count: 3, css: "card5"},
{attack: 4,defend: 5,count: 2, css: "card6"},
{attack: 0,defend: 5,count: 3, css: "card7"}
]
},
{
type: 'Wrath',
sprite: wrathSprite,
dice: 4,
health: 16,
numActions: 2,
cards: [// array of cards: put new cards here
{attack: 8,defend: 0,count: 2, css: "card8"},
{attack: 4,defend: 1,count: 5, css: "card9"},
{attack: 3,defend: 2,count: 7, css: "card10"},
{attack: 0,defend: 4,count: 3, css: "card11"},
{attack: 5,defend: 0,count: 3, css: "card12"},
{attack: 6,defend: 0,count: 1, css: "card13"},
{attack: 3,defend: 0,pierce: true,count: 3, css: "card14"},
{attack: 3,defend: 3,pierce: true,count: 1, css: "card15"}
]
},
{
type: 'Pride',
sprite: wrathSprite,
dice: 8,
health: 22,
numActions: 2,
cards: [// array of cards: put new cards here
{attack: 8,defend: 0,count: 2, css: "card16"},
{attack: 0,defend: 7,count: 3, css: "card17"},
{attack: 5,defend: 2,count: 5, css: "card18"},
{attack: 3,defend: 2,count: 4, css: "card19"},
{attack: 2,defend: 3,count: 4, css: "card20"},
{attack: 0,defend: 0,heal: 8,count: 2, css: "card21"},
{attack: 0,defend: 0,heal: 2,count: 1, css: "card22"},
{attack: 4,defend: 4,count: 4}
]
}
];
$("#player").hide();
$("#enterName").hide();
$("#proceed").click(function() {
playerType = $("#player").val();
biome = $("#biome").val();
if (numPlayers === gameSetup) {
$("#proceed").html('Start Game');
}
if (gameSetup === 1) {
$("#enterNumPlayers").hide();
$("#biome").hide();
numPlayers = $("#enterNumPlayers").val();// taking in the number of players
numPlayers = parseInt(numPlayers,10);
size = 3 + (numPlayers * 2);// scaling the size of map to the number of players
$("#player").show();
$("#enterName").show();
}
if (gameSetup > 1) {
var xSpawn = 6, ySpawn = 6; // coords where players spawn
if (numPlayers === 2) {
if (gameSetup === 2) {
xSpawn = 4;
ySpawn = 1;
} else {
xSpawn = 2;
ySpawn = 5;
}
} else if (numPlayers === 3) {
if (gameSetup === 2) {
xSpawn = 4;
ySpawn = 1;
} else if (gameSetup === 3) {
xSpawn = 7;
ySpawn = 4;
} else {
xSpawn = 1;
ySpawn = 7;
}
} else if (numPlayers === 4) {
if (gameSetup === 2) {
xSpawn = 5;
ySpawn = 1;
} else if (gameSetup === 3) {
xSpawn = 9;
ySpawn = 2;
} else if (gameSetup === 4) {
xSpawn = 1;
ySpawn = 9;
} else {
xSpawn = 6;
ySpawn = 8;
}
}
player = {
nick: $("#enterName").val(),
character: playerTypes[$("#player option:selected").index()],
coord: {
x: xSpawn,// x coord of where player spawns
y: ySpawn // y coord of where player spawns
},
sprite: wrathSprite,
cards: [],// put cards that the player can gets in this array
health: playerTypes[$("#player option:selected").index()].health,
// healthFromLastTurn: 1, // ratio of health that the player had at the start of their previous turn
nameLabel: new PointText() // name label
};
if (player.nick === '') {
player.nick = 'Player ' + (gameSetup-1); // if no nickname is entered, they get assigne a player number
}
players.push(player);
}
if (numPlayers + 1 === gameSetup) {
$("body").css('background-image', 'none');
$("#menu").hide();
$("#myCanvas").fadeToggle("slow");
$('#bBar').show('slow');
$("#statBar").show();
actionCounter = players[currentPlayer].character.numActions;
$("#statActionNumber").html(actionCounter);
$("#statHealthNumber").html(players[currentPlayer].health);
$("#statName").html(players[currentPlayer].nick);
$("#statCharacter").html(players[currentPlayer].character.type);
setup();
}
$("#enterName").val('');
gameSetup += 1;
});
for (var i = 0; i < playerTypes.length; i += 1) {// add player types to select option in html code
$("#player").append("<option>" + playerTypes[i].type + "</option>");
}
//wrathSprite.destinationX = 500;
var boardMain = [];
function setup() {// setup map here, also draw it
var x = 200,y = 100;
var topLeft = -1;
var bottomRight = -size;
for (var i = 0; i < size; i += 1) {
var row = [];
topLeft++;
bottomRight++;
for (var ii = 0; ii < size; ii += 1) {
var type = randomTileType();
if (ii < ((size-1)/2)-topLeft && i < ((size-1)/2)){ //this removes the top left corner to make the board a hexagon
var raster = new Raster({ // a raster is just an image and this is where the tile images are made ;)
position: new Point(20000,y),
source: imagePicker(type)
})
var circle = new Shape.Circle(new Point(20000,y), 60);//circle for in front of image
circle.fillColor = new Color(0.5,0.5,05,0.3);
circle.visible = false;
} else if (ii > ((size - ((size-1)/2))-1)-bottomRight && i > ((size - ((size-1)/2))-1)){ //this removes the bottom right corner
var raster = new Raster({ // a raster is just an image and this is where the tile images are made ;)
position: new Point(20000,y),
source: imagePicker(type)
})
var circle = new Shape.Circle(new Point(20000,y), 60);//circle for in front of image
circle.fillColor = new Color(0.5,0.5,05,0.3);
circle.visible = false;
} else {
var raster = new Raster({ // a raster is just an image and this is where the tile images are made ;)
position: new Point(x,y),
source: imagePicker(type)
})
var circle = new Path.RegularPolygon(new Point(x,y),6, 64);//circle for in front of image
circle.fillColor = new Color((22/255),(240/255),(80/255),0.3);
circle.visible = false;
}
var hexObject = {
x: x, // x coord in pixels
y: y, // y coord in pixels
radius: 50, // radius of tile, i need to remember why we need this
type: type, // type of tile i.e. forest, mountain
path: raster, // image
backgroundPath: circle // circle for in front of image
};
row.push(hexObject);
x += 110;
}
boardMain.push(row);
y += 95;
x = (200-5*(i+1)) + (i+1) * 60;
}
for (var i = 0; i < players.length; i += 1) {// setup all of the images for the players including the nametag
var xP = boardMain[players[i].coord.y][players[i].coord.x].path.position.x;
var yP = boardMain[players[i].coord.y][players[i].coord.x].path.position.y;
players[i].sprite = players[i].character.sprite;
players[i].sprite.destinationX = xP - players[i].sprite.sizeWidth/2;
players[i].sprite.destinationY = yP - players[i].sprite.sizeHeight/2;
players[i].nameLabel = new PointText({
point: new Point(xP,yP),
justification: 'center',
fontSize: 30,
fillColor: 'white',
fontFamily: 'Trade Winds',
content: players[i].nick
});
}
actionCounter = players[currentPlayer].character.numActions;
}
function imagePicker(type) { // choose images for tiles
if (type === 'forest') {
return 'images/grass.png';
}
else if (type === 'sand') {
return 'images/desert.png';
}
else if (type === 'rock') {
return 'images/rock.png';
}
}
function randomTileType() { // choose a random tile type to assign to a tile
var randomTile = Math.floor((Math.random() * 6) + 1);
if (biome === 'Forest') {
if (randomTile <= 4) {
return 'forest';
} else if (randomTile === 5) {
return 'sand';
} else if (randomTile === 6) {
return 'rock';
}
} else if (biome === 'Desert') {
if (randomTile <= 4) {
return 'sand';
} else if (randomTile === 5) {
return 'rock';
} else if (randomTile === 6) {
return 'forest';
}
} else if (biome === 'Mountain') {
if (randomTile <= 4) {
return 'rock';
} else if (randomTile === 5) {
return 'forest';
} else if (randomTile === 6) {
return 'sand';
}
}
}
function isNegative(number) { // check if number is negative
if (number > 0) {
return true;
} else if (number < 0) {
return false;
}
}
function isPlayerThereOrNah(x,y) { // check if player is on a space
for (var i = 0; i < players.length; i += 1) {
if (players[i].coord.x === x && players[i].coord.y === y) {
return true;
}
}
return false;
}
function canPlayerMoveOrNah(x,y) { // check if player can move to a certain spot
var deltaX = x - players[currentPlayer].coord.x;
var deltaY = y - players[currentPlayer].coord.y;
if (players[currentPlayer].coord.x + moveCounter >= x &&
players[currentPlayer].coord.y + moveCounter >= y &&
players[currentPlayer].coord.x - moveCounter <= x &&
players[currentPlayer].coord.y - moveCounter <= y &&
(Math.abs(deltaX) + Math.abs(deltaY) <= moveCounter || (isNegative(deltaX) !== isNegative(deltaY) && (Math.abs(deltaY) <= moveCounter || Math.abs(deltaX) <= moveCounter))) &&
isPlayerThereOrNah(x,y) === false &&
boardMain[y][x].type !== "rock") { // player cannot move onto a rock space
return true;
}
return false;
}
function rangedAttack() {
for (var i = players[currentPlayer].coord.x; i < size; i+=1) { // shoot to the right along x axis || RANGED
if (boardMain[players[currentPlayer].coord.y][i].type === 'rock') {
break;
} else {
boardMain[players[currentPlayer].coord.y][i].backgroundPath.visible = true;
}
}
for (var i = players[currentPlayer].coord.x; i >= 0; i-=1) { // shoot to the left along x axis || RANGED
if (boardMain[players[currentPlayer].coord.y][i].type === 'rock') {
break;
} else {
boardMain[players[currentPlayer].coord.y][i].backgroundPath.visible = true;
}
}
for (var i = players[currentPlayer].coord.y; i < size; i+=1) { // shoot down along y axis || RANGED
if (boardMain[i][players[currentPlayer].coord.x].type === 'rock') {
break;
} else {
boardMain[i][players[currentPlayer].coord.x].backgroundPath.visible = true;
}
}
for (var i = players[currentPlayer].coord.y; i >= 0; i-=1) { // shoot up along y axis || RANGED
if (boardMain[i][players[currentPlayer].coord.x].type === 'rock') {
break;
} else {
boardMain[i][players[currentPlayer].coord.x].backgroundPath.visible = true;
}
}
// for (var i = 0; i < (size - players[currentPlayer].coord.y); i+=1) { // shoot down along z axis || RANGED
// if (players[currentPlayer].coord.y + i - 1 <= size && players[currentPlayer].coord.x - i + 1 >= 0) {
// if (boardMain[players[currentPlayer].coord.y + i][players[currentPlayer].coord.x - i].type === 'rock') {
// break;
// Console.log(i);
// } else {
// boardMain[players[currentPlayer].coord.y + i][players[currentPlayer].coord.x - i].backgroundPath.visible = true;
// }
// }
// }
// for (var i = 0; i < (players[currentPlayer].coord.y) + 1; i+=1) { // shoot up along z axis || RANGED
// if (players[currentPlayer].coord.x + i <= size && players[currentPlayer].coord.y - i >= 0) {
// if (boardMain[players[currentPlayer].coord.y - i][players[currentPlayer].coord.x + i].type === 'rock') {
// break;
// } else {
// boardMain[players[currentPlayer].coord.y - i][players[currentPlayer].coord.x + i].backgroundPath.visible = true;
// }
// }
// }
// third axis ii - players[currentPlayer].coord.x)*(-1) === i - players[currentPlayer].coord.y
}
function statBox(player) {
}
function onFrame(event) { // runs 60 times per second TIP: Dont put a lot of loops in here because it will slow the game down a BUNCH
if (turnCounter === 2 && cardSelected === true) {
rangedAttack();
}
}
function onMouseMove(event) {
// for (var i = 0; i < size; i += 1) {
// for (var ii = 0; ii < size; ii += 1) {
// if (boardMain[i][ii].path.contains(event.point)) {
// // move events here
// }
// }
// }
}
function onMouseDrag(event) {
//if statement about if it is too far dragged or not
dragging = true;
for (var i = 0; i < size; i += 1) {
for (var ii = 0; ii < size; ii += 1) {// reposition tiles for the draging of the map
boardMain[i][ii].backgroundPath.position.x += event.delta.x/3; // drag circles that highlight usable tiles: x coord
boardMain[i][ii].backgroundPath.position.y += event.delta.y/3; // y ccord
boardMain[i][ii].path.position.x += event.delta.x/3; // drag the tiles: x coord
boardMain[i][ii].path.position.y += event.delta.y/3; // y coord
}
if (i < players.length) { // just using the board checker to also check the players
players[i].sprite.destinationX += event.delta.x/3; // move players when map is being drgged
players[i].sprite.destinationY += event.delta.y/3;
players[i].nameLabel.position.x += event.delta.x/3; // move the name label
players[i].nameLabel.position.y += event.delta.y/3;
}
}
}
function onMouseDown(event) {
for (var i = 0; i < size; i += 1) {
for (var ii = 0; ii < size; ii += 1) {
if (Math.pow(event.point.x - boardMain[i][ii].path.position.x,2) + Math.pow(event.point.y - boardMain[i][ii].path.position.y,2) < Math.pow(43,2)) {
//click events here
boardMain[i][ii].path.bounds.width -=10; // make the tile small when click down
boardMain[i][ii].path.bounds.height -=10;
boardMain[i][ii].path.position.x +=5;// reposition tile to center
boardMain[i][ii].path.position.y +=5;
console.log('x: ' + ii + ' y: ' + i);
if (move === true) {
// move math here
}
}
}
}
}
function onMouseUp(event) {
for (var i = 0; i < size; i += 1) {
for (var ii = 0; ii < size; ii += 1) {
if (boardMain[i][ii].path.bounds.width < 109) {// make the tile large again
boardMain[i][ii].path.bounds.width +=10;
boardMain[i][ii].path.bounds.height +=10;
boardMain[i][ii].path.position.x -=5;// reposition tile back to center
boardMain[i][ii].path.position.y -=5;
}
if (Math.pow(event.point.x - boardMain[i][ii].path.position.x,2) + Math.pow(event.point.y - boardMain[i][ii].path.position.y,2) < Math.pow(43,2)) {
// move events here
if (turnCounter === 1 && dragging === false) {
//console.log(ii + " " + i)
var deltaX = ii - players[currentPlayer].coord.x;
var deltaY = i - players[currentPlayer].coord.y;
if (canPlayerMoveOrNah(ii,i)) {
players[currentPlayer].sprite.destinationX = boardMain[i][ii].path.position.x - players[currentPlayer].sprite.sizeWidth/2;
players[currentPlayer].sprite.destinationY = boardMain[i][ii].path.position.y - players[currentPlayer].sprite.sizeHeight/2;
players[currentPlayer].nameLabel.position = boardMain[i][ii].path.position;
players[currentPlayer].coord.x = ii;
players[currentPlayer].coord.y = i;
moveCounter = 0;
}
}
if (turnCounter === 2 && boardMain[i][ii].backgroundPath.visible === true && actionCounter !== 0 && dragging === false) { // this whole shabang is about attacking
for (var u = 0; u < players.length; u += 1) {
if (u !== currentPlayer) {
if (players[u].coord.x === ii && players[u].coord.y === i) {
players[u].health -= currentAttack;
console.log("player " + (u+1) + " loses 1 health and is at " + players[u].health + " health");
actionCounter -= 1;
$("#statActionNumber").html(actionCounter);
cardSelected = false;
// healthRatio = players[currentPlayer].health / players[currentPlayer].character.health;
// $("#statHealthFill").css("height", (healthRatio * 100) + '%');
// $("#statHealthFill").css("top", ((1 - healthRatio) * 100) +'%');
}
}
}
}
}
if (turnCounter === 2) {
//boardMain[i][ii].backgroundPath.visible = false;
}
if (dragging === false) {
boardMain[i][ii].backgroundPath.visible = false; // reset all tiles to non movable
}
}
}
dragging = false;
}
</script>
</body>
</html>