-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
687 lines (665 loc) · 26.6 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
<!DOCTYPE html>
<html>
<head>
<title> She's Not Here </title>
<style>
#game {
padding-left: 0;
padding-right: 0;
margin: auto;
display: block;
width: 800px;
}
</style>
<link href='http://fonts.googleapis.com/css?family=Sigmar+One|Pacifico' rel='stylesheet' type='text/css'>
</head>
<body>
<div align='center'><font style='font-size:60px; font-family:Pacifico'>She's Not Here</font></div>
<div id="game"></div>
<p align='center' style='font-size:15px; font-family:Verdana'>A game about conquering your inner demons and insecurities. Take on the role of a troubled teen and get out of the nightmare!</p>
<p align='center' style='font-size:15px; font-family:Verdana'> INSTRUCTIONS (in case you didn't read them in-game -.-): </p>
<p align='center' style='font-size:15px; font-family:Verdana'>Use the WASD or arrow keys to move and jump.</p>
<p align='center' style='font-size:15px; font-family:Verdana'>Use the X and C keys to switch between the Zodiac Abilities. Press the SPACEBAR to actually use them (unless stated otherwise).</p>
<p align='center' style='font-size:15px; font-family:Verdana'>Created by: A.L., J.H., E.M., T.M., and N.C. as our final project for Girls Who Code, 2015.</p>
<p align='center' style='font-size:15px; font-family:Verdana'>COPYRIGHTED... Lol.</p>
<p align='center' style='font-size:10px; font-family:Verdana'>All game art was drawn by ourselves. The game was programmed in JavaScript and HTML5, using the library CraftyJS.</p>
<p align='center' style='font-size:10px; font-family:Verdana'>Introduction music: 1AM (from the game Animal Crossing: New Leaf, owned by Nintendo Co., Ltd.)</p>
<script type="text/javascript" src="https://rawgit.com/craftyjs/Crafty/release/dist/crafty-min.js"></script>
<script>
//prevent arrow keys/spacebar from moving scrollbar
window.addEventListener("keydown", function(e) {
// space and arrow keys
if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {
e.preventDefault();
}
}, false);
//play audio files stored on the web
function playSound(url, secs) {
var a = new Audio(url);
a.play();
setTimeout(function(){
a.pause();
a.currentTime = 0;
}, secs);
}
//initiate crafty & window
Crafty.init(800,600, document.getElementById('game'));
/** CLASSES **/
//template for solids
Crafty.c('Solid', {
breakable:false,
init: function() {
this.requires('2D, Canvas, Grid, Color')
.color('black');
},
});
//template for water
Crafty.c('Water',{
init: function(){
this.requires('2D, Canvas, Grid, Color, Collision, Gravity')
.color('#008B8B', 0.5) //#248F8F
.onHit('PlayerC', function(e){
if(e[0].obj.slotSelect != 12 && e[0].obj.y > this.y+20){
e[0].obj.health -= 0.01;
e[0].obj.takeDamage();
}
});
}
})
//template for Player-controlled sprite
Crafty.c('PlayerC', {
dir:1, health:30, maxHealth:30, shield:0, slotSelect:1, sprite:'http://i.imgur.com/lSex1EM.png',
init: function() {
this.requires('2D, Canvas, Twoway, Gravity, Image, Collision')
.twoway(4,7) //built-in movement/jumping function
.attr({w: playerw, h: playerh})
.image(this.sprite)
.gravity('Solid')
.bind('Moved', function(p) { //executes the function when the 'Moved' event occurs
if (this.hit('Solid')){
this.attr({x: p.x}); //so that the sprite can't pass through solids horizontally
}
})
.bind('KeyDown', function(e){
//keep track of which direction player is facing
if(e.key === Crafty.keys.RIGHT_ARROW || e.key === Crafty.keys.D){
this.dir = 1;
this.unflip('X');
}
else if(e.key === Crafty.keys.LEFT_ARROW || e.key === Crafty.keys.A){
this.dir = -1;
this.flip('X');
}
//change ability slot
if(e.key === Crafty.keys.C){
this.slotSelect += 1;
if(this.slotSelect === 13){
this.slotSelect = 1;}
}
else if(e.key === Crafty.keys.X){
this.slotSelect -= 1;
if(this.slotSelect === 0){
this.slotSelect = 12;}
}
});
},
takeDamage: function(){
var t = 0;
this.bind('EnterFrame', function damage(){
if(t<15){this.image('http://i.imgur.com/BHrK1C1.png');}
else if(t>15){
this.image(this.sprite);
this.unbind(damage);
}
t += 1;
})
}
});
//template for enemies
var kills = 0;
Crafty.c('Enemy', {
health:30, type:1, attackStrength:0.5, velocity:4, sprite:'http://i.imgur.com/U6IzklM.png',
init: function(){
this.requires('2D, Canvas, Twoway, Gravity, Image, Collision')
.gravity('Solid')
.image(this.sprite)
.onHit('PlayerC', function(e){
if(e[0].obj.shield === 0 && this.type > 0){
e[0].obj.takeDamage();
}
e[0].obj.health -= (this.attackStrength - this.attackStrength*e[0].obj.shield);
})
.onHit('Solid', function(){
this.velocity *= -1;
if(Crafty.math.abs(this.velocity) != this.velocity){this.flip('X');} //if velocity is negative, flip it
else{this.unflip('X');}
})
.bind('EnterFrame', function(){
this.x += this.velocity;
if(Crafty.math.abs(this.velocity) != this.velocity){this.flip('X');} //if velocity is negative, flip it
else{this.unflip('X');}
if(this.health <= 0){
if(this.type > 0){kills += 1;}
this.destroy();
}
});
},
takeDamage: function(){
var t = 0;
this.bind('EnterFrame', function damage(){
if(t<15){this.image('http://i.imgur.com/CE7O9pX.png');}
else if(t>15){
this.image(this.sprite);
this.unbind(damage);}
t += 1;
})
}
});
//template for projectiles (both player & enemy)
Crafty.c('Projectile', {
strength:0, xspeed:0,
init: function(){
this.requires('2D, DOM, Image, Collision')
.image('http://i.imgur.com/rJPITsy.png')
.bind('EnterFrame', function(){
this.x += this.xspeed; //move the bullet
if(Crafty.math.abs(this.xspeed) != this.xspeed){this.flip('X');}
else{this.unflip('X');}
if(this._x < this._x-Crafty.viewport.width || this._x > this._x+Crafty.viewport.width || this._y < this.y-Crafty.viewport.height || this._y > this.y+Crafty.viewport.height || this.hit('Solid')) {
this.destroy(); //destroy the bullet if it leaves the visible screen portion
}
})
.onHit('Enemy', function(e){
e[0].obj.takeDamage();
e[0].obj.health -= this.strength;
this.destroy();
});
}
});
//template for all doors
Crafty.c('Door', {
level:'level0', killsNeeded:0,
init: function(){
this.requires('2D, Canvas, Grid, Color, Collision')
.attr({w: 50, h: 80})
.color('#BBBBBB')
//enables scene change
.bind('KeyDown', function(e){
if(e.key === Crafty.keys.DOWN_ARROW && this.hit('PlayerC') && kills >= this.killsNeeded){
Crafty.enterScene(this.level);
}
else if((e.key === Crafty.keys.DOWN_ARROW || e.key === Crafty.keys.S) && this.hit('PlayerC') && kills < this.killsNeeded){
Crafty.e('Words').attr({x: this.x, y: this.y - 20, w:75, h: 20}).text('Locked!').textFont({size:'15px'});
}
});
}
});
//default template for all canvas text (it can be overwritten for customization)
Crafty.c('Words', {
init: function(){
this.requires('2D, DOM, Text')
.unselectable()
.textColor('white')
.textFont({type:'italic', family:'Verdana', size:'20px'});
}
});
//template for text box
Crafty.c('TextBox', {
text:'',
init: function(){
this.requires('2D, Canvas, Grid, Color')
.attr({x:200, y: 425, w:400, h:120})
.color('#C2AA8A', 0.9)
.one('EnterFrame', function(){
Crafty.pause(true);
l1 = Crafty.e('Words').attr({x: this._x+20, y: this._y+20, w:360, h:60}).textColor('black').text(this.text);
l2 = Crafty.e('Words').attr({x: this._x+20, y: this._y+100, w:300, h:20}).textColor('black').textFont({size:'15px'}).text('Press SPACE to continue');
})
.bind('KeyDown', function(e){
if(e.key === Crafty.keys.SPACE){
Crafty.pause(false);
l1.destroy();
l2.destroy();
this.destroy();
}
});
}
});
/** STUFF **/
var spawnEnemy = function(xpos, ypos){
Crafty.e('Enemy').attr({x: xpos, y: ypos, w: 30, h:50});
}
/** LEVEL SCREENS **/
var currentLevel = 'level0';
//game over screen
Crafty.defineScene('Over', function(){
Crafty.background('url(http://i.imgur.com/HdmmNJV.png)'); //http://i.imgur.com/c2A937j.png
Crafty.e('Words').attr({x: 100, y:100, w:800, h:100}).text('You lost to your nightmare...').textFont({size:'40px'});
Crafty.e('Words').attr({x: 200, y:200, w:250, h:200}).text('Press the spacebar to restart.')
.bind('KeyDown', function(e){
if(e.key === Crafty.keys.SPACE){
Crafty.enterScene(currentLevel);
}
});
});
//start screen
Crafty.defineScene('Start', function(){
Crafty.background('url(http://i.imgur.com/HdmmNJV.png)');//
Crafty.e('Words').attr({x:70, y:150, w: 700, h: 100}).text("She's Not Here").textFont({size:'90px'});
Crafty.e('Words').attr({x:270, y:300, w: 300, h: 100}).text("Press any key to begin playing").textFont({size:'15px'})
.bind('KeyDown', function(e){
Crafty.enterScene('cutscene1');
});
});
//cutscene 1
Crafty.defineScene('cutscene1', function(){
playSound('http://vignette1.wikia.nocookie.net/animalcrossing/images/6/67/015_-_Animal_Crossing_New_Leaf_%283DS%29_-_1_AM.ogg/revision/latest?cb=20150815210836', 22250);
Crafty.background('#000 url(http://i.imgur.com/vNAZEVj.gif) no-repeat center center');
setTimeout(function(){
Crafty.enterScene('level0');
spawnPlayer(100,550);
Crafty.e('TextBox').attr({text:'...Huh? Am I dreaming right now? This looks sort of like my room...'})
.bind('KeyDown', function(e){
if(e.key === Crafty.keys.SPACE){
Crafty.e('TextBox').attr({text:"...Oh, I even seem to have Zodiac Abilities in this dream. I've always wanted them..."});
}
});
}, 22250);
})
//tutorial screen
Crafty.defineScene('level0', function(){
currentLevel = 'level0';
Crafty.background('url(http://i.imgur.com/zp9XKZ2.png)');
//platforms
Crafty.e('Solid').attr({x: 0, y: 550, w: 800, h: 50}); //floor
Crafty.e('Solid').attr({x: 520, y: 440, w: 140, h: 160});
Crafty.e('Solid').attr({x: 660, y: 335, w: 140, h: 265});
//border
Crafty.e('Solid').attr({x: 0, y: 0, w: 30, h: 600}); //W side
Crafty.e('Solid').attr({x: 770, y: 0, w: 30, h: 600}); //E side
Crafty.e('Door').attr({x:720, y: 255, w: 50, h: 80, level:'level1'});
Crafty.e('Words').attr({x: 38, y: 200, w: 400}).text("Use WASD or arrow keys to jump/move. Use the DOWN arrow key to enter doors.").textColor('#CCCCCC');
});
//Level 1
Crafty.defineScene('level1', function(){
currentLevel = 'level1';
Crafty.background('url(https://raw.githubusercontent.com/creatoramy/Final-Project/a1226b20dad74feea6090e7825ffdc723c11f6b5/cutscenes/bg/bg%20lvl3.png)');
//PLATFORMS
Crafty.e('Solid').attr({x: 0, y: 550, w: 1600, h: 50}); //floor
Crafty.e('Solid').attr({x: 1200, y: 440, w: 400, h: 120});
Crafty.e('Solid').attr({x: 1400, y: 330, w: 200, h: 120});
//BORDER
Crafty.e('Solid').attr({x: 0, y: 0, w: 30, h: 600, visible:false}); //W side
Crafty.e('Solid').attr({x: 1600, y: 0, w: 30, h: 600}); //E side
//EXIT
Crafty.e('Door').attr({x:1550, y: 250, killsNeeded:2, level:'level2'});
Crafty.e('Words').attr({x:50, y:200, w:400}).text("Use the X and C keys to switch abilities, SPACEBAR to use the ability.").textColor('#CCCCCC');
spawnEnemy(720, 550);
spawnEnemy(350, 550);
spawnPlayer(50, 550);
Crafty.e('TextBox').attr({text:'!!! W-what is this?! And that thing...it feels evil...'});
});
//Level 2 Forest
Crafty.defineScene('level2', function(){
currentLevel = 'level2';
Crafty.background('url(http://i.imgur.com/h5Hy9tJ.png)');
//border & floor
Crafty.e('Solid').attr({x: 0, y: -200, w: 30, h: 800, visible:false}).color('black'); //W side
Crafty.e('Solid').attr({x: 1600, y: -200, w: 30, h: 800}).color('black'); //E side
Crafty.e('Solid').attr({x: 0, y: 550, w: 1600, h: 50}).color('black'); //floor
//hill
Crafty.e('Solid').attr({x: 1400, y: 430, w: 200, h: 120}).color('black'); //hill
Crafty.e('Solid').attr({x: 1350, y: 500, w: 250, h: 70}).color('black'); //hill
//tree branches
Crafty.e('Solid').attr({x: 100, y: 360, w: 300, h: 20}).color('#5C3317'); //must use double jump to get on
Crafty.e('Solid').attr({x: 540, y: 180, w: 450, h: 20}).color('#5C3317');
Crafty.e('Solid').attr({x: 570, y: 370, w: 380, h: 20}).color('#5C3317');
Crafty.e('Solid').attr({x: 130, y: 250, w: 80, h: 20}).color('#5C3317'); //platform 2
Crafty.e('Solid').attr({x: 70, y: 70, w: 160, h: 20}).color('#5C3317');
Crafty.e('Solid').attr({x: 220, y: 170, w: 65, h: 20}).color('#5C3317');
Crafty.e('Solid').attr({x: 350, y: 80, w: 100, h: 20}).color('#5C3317');
Crafty.e('Solid').attr({x: 540, y: 165, w: 20, h: 15}).color('#5C3317'); //keeps the enemy from sliding off
//tree trunks
Crafty.e('Solid').attr({x: 436, y: 0, w: 66, h: 550}).color('#5C3317');
Crafty.e('Solid').attr({x: 206, y: 0, w: 54, h: 550}).color('#5C3317');
Crafty.e('Solid').attr({x: 745, y: 0, w: 47, h: 550}).color('#5C3317');
//door
Crafty.e('Door').attr({x:1550, y: 349, locked:true, killsNeeded:3, level:'level3'});
//enemies & player
spawnEnemy(610, 180);
spawnEnemy(1000, 180);
spawnEnemy(300, 550);
spawnPlayer(50, 550);
});
//Level 3 mountains
Crafty.defineScene('level3', function(){
currentLevel = 'level3';
Crafty.background('url(http://i.imgur.com/iFxoMAy.png)');
Crafty.viewport._x = 0;
Crafty.e('Words').attr({x:100, y:100, w: 200, h:100}).text('This is a work-in-progress. Press space to continue...')
.bind('KeyDown', function(e){
if(e.key === Crafty.keys.SPACE){Crafty.enterScene('level4');}
});
});
//level 4 mountains2
Crafty.defineScene('level4', function(){
currentLevel = 'level4';
Crafty.background('url(http://i.imgur.com/Rxtm2M1.png)');
Crafty.e('Words').attr({x:100, y:100, w: 200, h:100}).text('This is a work-in-progress. Press space to continue...')
.bind('KeyDown', function(e){
if(e.key === Crafty.keys.SPACE){Crafty.enterScene('level5');}
});
})
//level 5 cave
Crafty.defineScene('level5', function(){
currentLevel = 'level5';
Crafty.background('url(https://raw.githubusercontent.com/creatoramy/Final-Project/master/cutscenes/bg/bg%20lvl1.png)');
Crafty.e('Words').attr({x:100, y:100, w: 200, h:100}).text('This is a work-in-progress. Press space to continue...')
.bind('KeyDown', function(e){
if(e.key === Crafty.keys.SPACE){Crafty.enterScene('level6');}
});
})
//Level 6 Underwater
Crafty.defineScene('level6', function(){
currentLevel = 'level6';
Crafty.background('url(http://i.imgur.com/6j3PyHK.png)');
//Crafty.audio.remove("ed2");
//platforms
Crafty.e('Solid').attr({x:0, y:400, w:300, h:200});
Crafty.e('Solid').attr({x:1100, y:400, w:300, h:200});
Crafty.e('Solid').attr({x:425, y:360, w: 200, h:240})
.color('white');
Crafty.e('Solid').attr({x:600, y:480, w:100, h:120})
.color('white');
Crafty.e('Door').attr({x: 1300, y:320, level:'end', killsNeeded:0});
spawnEnemy(1000, 300);
spawnPlayer(40, 300);
//ceiling stuff (to make it more cave-like)
Crafty.e('Solid').attr({x:0, y:0, w:290, h:100});
Crafty.e('Solid').attr({x:290, y:0, w:330, h:50});
Crafty.e('Solid').attr({x:620, y:0, w:40, h:100});
Crafty.e('Solid').attr({x:660, y:0, w:40, h:65});
Crafty.e('Solid').attr({x:700, y:0, w:290, h:20});
Crafty.e('Solid').attr({x:990, y:0, w:210, h:100});
Crafty.e('Solid').attr({x:1200, y:0, w:200, h:125})
//water
Crafty.e('Water').attr({x:300, y: 410, w: 800, h: 190});
//floor & border
Crafty.e('Solid').attr({x: 0, y: 0, w: 30, h: 600, visible:false}); //W side
Crafty.e('Solid').attr({x: 1400, y: 0, w: 30, h: 600}); //E side
Crafty.e('Solid').attr({x: 0, y: 580, w: 1400, h: 20}); //floor
});
//end screen...?
Crafty.defineScene('end', function(){
Crafty.viewport._x = 0;
Crafty.background('black');
Crafty.e('Words').attr({x:100, y:100, w: 200, h:100}).text('Thanks for playing what we have made so far!');
Crafty.e('Words').attr({x:200, y:200, w: 200, h:100}).text("Much thanks to Girls Who Code, our awesome mentors, and Moody's for making this game possible!")
});
/** INITIATIONS & PLAYER FUNCTIONS **/
//start scene
Crafty.enterScene('Start');
//spawns player & misc.
var playerw = 30;
var playerh = 50;
var abilities = ["Aries' Ability: The classic Sword", "Taurus' Ability: Super Strength; can even smash walls", "Gemini's Ability: Unleash your inner minion for five seconds",
"Cancer's Ability: Body Shield; immunity to all damage", "Leo's Ability: Roar; can briefly stun enemies", "Virgo's Ability: Absorb life force from what you touch",
"Libra's Ability: Heal yourself a bit at a time", "Scorpio's Ability: Poison Darts wither enemies away", "Sagittarius' Ability: Archer's Arrows",
"Capricorn's Ability: Double Jumping; just press UP key twice", "Aquarius' Ability: Water Blast; can also put out fires",
"Pisces' Ability: Breathe underwater"];
var spawnPlayer = function(xpos, ypos){
var state = 0; //keep track of whether the game has just restarted or not
kills = 0; //reset amount of kills so doors can be locked
player = Crafty.e('PlayerC').attr({x: xpos, y: ypos, w: playerw, h: playerh});
Crafty.viewport.follow(player,0,0); //camera to follow player
//update health & ability slot bars so they're visible at all times
updateHealth = function(){
if(state === 1){
healthBarOutline.destroy();
healthBar.destroy();
healthText.destroy();
slotBarOutline.destroy();
slotBars.destroy();
slotSelector.destroy();
abilityText.destroy();
}
//health bar
healthBarOutline = Crafty.e('2D, Canvas, Color')
.attr({x: -Crafty.viewport._x+18, y: -Crafty.viewport._y+25, w: player.maxHealth*2+10, h: 30})
.color('black');
healthBar = Crafty.e('2D, Canvas, Color')
.attr({x: -Crafty.viewport._x+23, y: -Crafty.viewport._y+30, w: player.health*2, h: 20})
.color('green');
healthText = Crafty.e('Words').attr({x: healthBarOutline.x, y: healthBarOutline.y-20, w:100, h:30}).text('Health:').textFont({size:'15px'});
if(player.health > player.maxHealth){player.health = player.maxHealth;}
//slot bars
slotBarOutline = Crafty.e('2D, Canvas, Color')
.attr({x: -Crafty.viewport._x+300, y: -Crafty.viewport._y+25, w:490, h:50})
.color('black');
slotBars = Crafty.e('2D, DOM, Image')
.attr({x: -Crafty.viewport._x+305, y: -Crafty.viewport._y+30, w: 480, h:40})
.image('http://i.imgur.com/oVWgV3l.png');
slotSelector = Crafty.e('2D, Canvas, Color')
.attr({x: slotBars.x + player.slotSelect*40-40, y: slotBars.y + 40, w: 40, h:10})
.color('white');
abilityText = Crafty.e('Words').attr({x: slotBarOutline.x, y: slotBarOutline.y - 20, w: 500, h: 40}).text(abilities[player.slotSelect-1]).textFont({size:'15px'});
state = 1;
//game over screen
if(player.health <= 0){
Crafty.enterScene('Over');
Crafty.viewport._x = 0;
Crafty.viewport._y = 0;
}
}
player.bind('EnterFrame', function(){updateHealth();});
/** ABILITIES **/
player.uniqueBind('KeyDown', function(e) {
//sword
if(player.slotSelect === 1){
player.sprite = 'http://i.imgur.com/lSex1EM.png';
player.image(player.sprite);
if(e.key === Crafty.keys.SPACE){
player.sprite = 'http://i.imgur.com/QWYfemj.png';
player.image(player.sprite);
player.onHit('Enemy', function(e){
if((player.dir === 1 && e[0].obj.x > player.x+playerw && e[0].obj.x < player.x + player.w) || (player.dir === -1 && e[0].obj.x > player.x-38 && e[0].obj.x < player.x)){
e[0].obj.takeDamage();
e[0].obj.health-=10;
player.health += 0.5;
}
});
player.one('KeyUp', function(){
player.sprite = 'http://i.imgur.com/lSex1EM.png';
player.image(player.sprite);
});
}
}
//super strength to KO enemies and smash through certain walls
else if(player.slotSelect === 2){
player.sprite = 'http://i.imgur.com/zX3t9YY.png';
player.image(player.sprite);
if(e.key === Crafty.keys.SPACE){
player.sprite = 'http://i.imgur.com/n9oLKTt.png';
player.image(player.sprite);
player.onHit('Enemy', function(e){
var hit = false;
if((player.dir === 1 && e[0].obj.x > player.x+playerw && e[0].obj.x < player.x + player.w) || (player.dir === -1 && e[0].obj.x > player.x-38 && e[0].obj.x < player.x)){
if(hit === false){
e[0].obj.takeDamage();
e[0].obj.health-=30;
hit = true;
}
}
});
setTimeout(function(){
player.sprite = 'http://i.imgur.com/zX3t9YY.png';
player.image(player.sprite);
}, 1000);
}
}
//unleash an inner minion
else if(player.slotSelect === 3){
player.sprite = 'http://i.imgur.com/3twc0Qe.png';
player.image(player.sprite);
if(e.key === Crafty.keys.SPACE){
Crafty.e('Enemy').attr({x: this._x, y: this._y, w: playerw, h: playerh, velocity: 2*player.dir, attackStrength:0, health:5, type:0})
.image('http://i.imgur.com/WUQrodK.png')
.bind('EnterFrame', function(){this.health -= 0.02;}) //because the default FPS is 50
.onHit('Enemy', function(e){
if(e[0].obj.type > 0){
e[0].obj.health -= 6;
e[0].takeDamage();
this.health = 0;
}
});
}
}
//body shield makes player immune to all damage
else if(player.slotSelect === 4){
player.sprite = 'http://i.imgur.com/bZW5l01.png';
player.image(player.sprite);
if(e.key === Crafty.keys.SPACE){
player.shield = 1;
player.sprite = 'http://i.imgur.com/T2BQcfL.png';
player.image(player.sprite);
player.y -= 2;
player.one('KeyUp', function(){
player.shield = 0;
player.sprite = 'http://i.imgur.com/bZW5l01.png';
player.image(player.sprite);
});
}
}
//roar to briefly stun enemies
else if(player.slotSelect === 5){
player.sprite = 'http://i.imgur.com/DlROvFf.png';
player.image(player.sprite);
if(e.key === Crafty.keys.SPACE){
player.sprite = 'http://i.imgur.com/jPDBlap.png';
player.image(player.sprite);
player.y -= 2;
player.one('KeyUp', function(){
player.sprite = 'http://i.imgur.com/DlROvFf.png';
player.image(player.sprite);
});
}
}
//suck the life force out of enemies and heal yourself
else if(player.slotSelect === 6){
player.sprite = 'http://i.imgur.com/58f3YWP.png';
player.image(player.sprite);
if(e.key === Crafty.keys.SPACE){
player.shield = 1;
player.sprite = 'http://i.imgur.com/hoVowYe.png';
player.image(player.sprite);
player.y -= 2;
player.onHit('Enemy', function(e){
player.health += 0.1;
updateHealth();
e[0].obj.takeDamage();
e[0].obj.health -= 0.1;
});
player.one('KeyUp', function(){
player.shield = 0;
player.sprite = 'http://i.imgur.com/58f3YWP.png';
player.image(player.sprite);
});
}
}
//healing
else if(player.slotSelect === 7){
player.sprite = 'http://i.imgur.com/A04X0bC.png';
player.image(player.sprite);
if(e.key === Crafty.keys.SPACE){
player.health += 10;
updateHealth();
player.sprite = 'http://i.imgur.com/AfcrQ7n.png';
player.image(player.sprite);
player.y -= 2;
player.one('KeyUp', function(){
player.sprite = 'http://i.imgur.com/A04X0bC.png';
player.image(player.sprite);
});
}
}
//poison darts that slowly decrease an enemy's health until it dies, once hit
else if(player.slotSelect === 8){
player.sprite = 'http://i.imgur.com/cBHxYQl.png';
player.image(player.sprite);
if(e.key === Crafty.keys.SPACE){
player.sprite = 'http://i.imgur.com/zL75Q38.png';
player.image(player.sprite);
Crafty.e('Projectile').attr({x: this._x, y: this._y + 0.5*playerh, w: 15, h: 10, xspeed: 7*player.dir, strength: 5}).image('http://i.imgur.com/EJAIT1H.png')
.onHit('Enemy', function(e){
var timer = setInterval(function(){
e[0].obj.takeDamage();
e[0].obj.health -= 5;
if(e[0].obj.health <= 0){clearInterval(timer);}
}, 1000);
});
player.one('KeyUp', function(){
player.sprite = 'http://i.imgur.com/cBHxYQl.png';
player.image(player.sprite);
});
}
}
//arrows that do the most damage out of all the projectiles
else if(player.slotSelect === 9){
player.sprite = 'http://i.imgur.com/1BkL56F.png';
player.image(player.sprite);
if(e.key === Crafty.keys.SPACE){
player.sprite = 'http://i.imgur.com/xFYXJ2L.png';
player.image(player.sprite);
Crafty.e('Projectile').attr({x: this._x, y: this._y + 0.4*playerh, w: 25, h: 5, xspeed: 10*player.dir, strength: 10}).image('http://i.imgur.com/rJPITsy.png');
player.one('KeyUp', function(){
player.sprite = 'http://i.imgur.com/1BkL56F.png';
player.image(player.sprite);
});
}
}
//double jump
else if(player.slotSelect === 10){
player.sprite = 'http://i.imgur.com/fCOhRqf.png';
player.image(player.sprite);
player.y -= 3;
if (!this._falling && e.key === Crafty.keys.UP_ARROW) {
this._canJumpAgain = true;}
else if (this._canJumpAgain && e.key === Crafty.keys.UP_ARROW) {
this._up = true;
this._gy = 0;
this._canJumpAgain = false;
}
}
//water blast can also put out fires and push back enemies
else if(player.slotSelect === 11){
player.sprite = 'http://i.imgur.com/KlijvuQ.png';
player.image(player.sprite);
if(e.key === Crafty.keys.SPACE){
player.sprite = 'http://i.imgur.com/dAWHVjM.png';
player.image(player.sprite);
Crafty.e('Projectile').attr({x: this._x, y: this._y + 0.3*playerh, w: 25, h: 25, xspeed: 8*player.dir, strength: 4}).image('http://i.imgur.com/xRc8cEG.png');
player.one('KeyUp', function(){
player.sprite = 'http://i.imgur.com/KlijvuQ.png';
player.image(player.sprite);
});
}
}
//breathe underwater
else if(player.slotSelect === 12){
player.sprite = 'http://i.imgur.com/I1ia1vk.png';
player.image(player.sprite);
player.uniqueBind('EnterFrame', function(){
if(player.hit('Water')){
player.gravityConst(-0.05);
player.bind('KeyUp', function(){player.gravityConst(0.2);});
}
else if(!player.hit('Water')){
player.gravityConst(0.2);
}
});
}
});
}
</script>
</body>
</html>