-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
executable file
·673 lines (545 loc) · 21.8 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
<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"></select>
</li>
<li>
<select id="biome">
<option>Forest</option>
<option>Desert</option>
<option>Mountain</option>
</select>
</li>
<li>
<button id="proceed">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. -->
</div>
<canvas id="myCanvas" resize></canvas>
<div id="bBar">
<div class="deck"></div>
<ul id="cards">
</ul>
</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/paperscript" canvas="myCanvas">
/*
to do:
3. figure out what the hell to do with attacks
*/
var expanded = false; // Is the bottom bar expanded?
var numCards = 0; // number of cards
var bBarWidth = 0;// width of bottom bar for cards
$("#cards").hide();
$('#bBar').hide();
$("#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('<li class="card">This is Card <p>Attack: ' + players[currentPlayer].cards[i].attack + '</p> <p>Defense: ' + players[currentPlayer].cards[i].defend + '</p> </li>');
}
$("#bBar").css("background", "black");
$("#bBar").css("width", "100%");
$("#cards").delay(680).show(680);
if (numCards >= 4) {
$("#bBar").css("overflowX", "scroll");
}
if (turnCounter === 2) {
$("#statActionButton").html('Add 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", "AntiqueWhite");
$("#bBar").css("width", "20vw");
$("#cards").hide(0);
$("#bBar").css("overflowX", "hidden");
$(".card").remove();
if (turnCounter === 2) {
$("#statActionButton").html('Next Turn');
}
expanded = false;
}
}
$('#bBar').click(function () {
"use strict";
if (expanded === false) {
expandBBar();
} else {
hideBBar();
}
});
//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('<li class="card">This is Card <p>Attack: ' + players[currentPlayer].character.cards[randomCardIndex].attack + '</p> <p>Defense: ' + players[currentPlayer].character.cards[randomCardIndex].defend + '</p> </li>');
//extend bar width
bBarWidth += (28);
$("#cards").css("width", bBarWidth + "vw");
if (numCards >= 4) {
$("#bBar").css("overflowX", "scroll");
}
players[currentPlayer].cards.push(players[currentPlayer].character.cards[randomCardIndex]);
actionCounter -= 1;
}
}
$("#statActionButton").click(function () {
if (expanded === false) {
turnCounter++;
}
if (turnCounter === 3) {
for (var i = 0; i < size; i += 1) {// clearing the circles at end of turn
for (var ii = 0; ii < size; ii += 1) {
boardMain[i][ii].backgroundPath.visible = false; // reset all tiles to non movable
}
}
currentPlayer++;
if (currentPlayer === players.length) {
currentPlayer = 0;
}
hideBBar();
turnCounter = 0;
numCards = players[currentPlayer].cards.length;
actionCounter = players[currentPlayer].character.numActions;
} 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) {
addCard();
} else {
$("#statActionButton").html('Next Turn');
}
}
});
$("#myCanvas").hide();
var size, biome, playerType, numPlayers = 30, gameSetup = 1, players = [], move = false, currentPlayer = 0, turnCounter = 0, moveCounter = 0;
var playerTypes = [// array of player types: add new player types here
{
type: 'Greed',
color: '#cc00cc',
dice: 12,
health: 20,
numActions: 3,
cards: [// array of cards: put new cards here
{
attack: 5,
defend: 3,
rarity: 1
},
{
attack: 6,
defend: 0,
rarity: 2
},
{
attack: 2,
defend: 2,
rarity: 2
}
]
},
{
type: 'Wrath',
color: '#ff0000',
dice: 4,
health: 16,
numActions: 2,
cards: [// array of cards: put new cards here
{
attack: 3,
defend: 5,
rarity: 1
},
{
attack: 6,
defend: 0,
rarity: 2
}
]
},
{
type: 'Pride',
color: '#e5e600',
dice: 8,
health: 22,
numActions: 2,
cards: [// array of cards: put new cards here
{
attack: 3,
defend: 5,
rarity: 1
},
{
attack: 6,
defend: 0,
rarity: 2
}
],
aimerLine: new Path()
}
];
$("#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
},
path: new Path.RegularPolygon(new Point(0,0),0,0),
cards: [],// put cards that the player can gets in this array
health: playerTypes[$("#player option:selected").index()].health,
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();
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>");
}
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 Shape.Circle(new Point(x,y), 60);//circle for in front of image
circle.fillColor = new Color(0.5,0.5,05,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].path = new Path.RegularPolygon(new Point(xP, yP), 3, 30);
players[i].path.fillColor = players[i].character.color;
players[i].nameLabel = new PointText({
point: players[i].path.position,
justification: 'center',
fontSize: 30,
fillColor: 'black',
content: players[i].nick
});
}
actionCounter = players[currentPlayer].character.numActions;
}
function imagePicker(type) {
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() {
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) {
if (number > 0) {
return true;
} else if (number < 0) {
return false;
}
}
function isPlayerThereOrNah(x,y) {
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) {
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) {
return true;
}
return false;
}
function onFrame(event) {
if (turnCounter === 1) {
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 (canPlayerMoveOrNah(ii,i)) {
boardMain[i][ii].backgroundPath.visible = true;// can move here
}
}
}
} else if (turnCounter === 2) {
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;// set all tiles to unshootable
var deltaX = ii - players[currentPlayer].coord.x;
var deltaY = i - players[currentPlayer].coord.y;
if (ii === players[currentPlayer].coord.x || i === players[currentPlayer].coord.y || (ii - players[currentPlayer].coord.x)*(-1) === i - players[currentPlayer].coord.y) { // ranged attack
boardMain[i][ii].backgroundPath.visible = true; // set tiles to shootble
}
}
}
}
}
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
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].path.position.x += event.delta.x/3; // move players when map is being drgged
players[i].path.position.y += 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 (boardMain[i][ii].path.contains(event.point)) {
//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 (boardMain[i][ii].path.contains(event.point)) {
// move events here
if (turnCounter === 1) {
//console.log(ii + " " + i)
var deltaX = ii - players[currentPlayer].coord.x;
var deltaY = i - players[currentPlayer].coord.y;
if (canPlayerMoveOrNah(ii,i)) {
players[currentPlayer].path.position = boardMain[i][ii].path.position;
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) { // 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 -= 1;
console.log("player " + (u+1) + " loses 1 health and is at " + players[u].health + " health");
}
}
}
}
}
if (turnCounter === 2) {
//boardMain[i][ii].backgroundPath.visible = false;
}
}
}
}
</script>
</body>
</html>