-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprototype
More file actions
419 lines (392 loc) · 15.3 KB
/
prototype
File metadata and controls
419 lines (392 loc) · 15.3 KB
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
<!DOCTYPE html>
<html>
<head>
<title> She's Not Here </title>
<style>
#game {
padding-left: 0;
padding-right: 0;
margin-left: auto;
margin-right: auto;
display: block;
width: 800px;
}
</style>
</head>
<body>
<div id="game"></div>
<script type="text/javascript" src="https://rawgithub.com/craftyjs/Crafty/release/dist/crafty-min.js"></script>
<script>
Crafty.init(800,600, document.getElementById('game')); //initiate crafty & window
/** CLASSES **/
//template for solids
Crafty.c('mom', {
breakable:false,
init: function() {
this.requires('2D, Canvas, Solid, Grid, Color')
.color('black');
},
});
//template for water
Crafty.c('Water',{
init: function(){
this.requires('2D, Canvas, Grid, Color')
.color('#008B8B', 0.5)
.bind('EnterFrame', function(){
if(this.hit('PlayerC')){
PlayerC.gravityConst(0.3);
}
else if(!this.hit('PlayerC')){
PlayerC.gravityConst(0.2);
}
});
}
})
//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){
this.dir = 1;
this.image(this.sprite).unflip('X');
}
else if(e.key === Crafty.keys.LEFT_ARROW){
this.dir = -1;
this.image(this.sprite).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;}
}
});
}
});
//template for enemies
var kills = 0;
Crafty.c('Enemy', {
health:30, type:1, attackStrength:0.5, velocity:2, //type = attack & image type
init: function(){
this.requires('2D, Canvas, Twoway, Gravity, Color, Collision')
.gravity('Solid')
.onHit('PlayerC', function(e){
e[0].obj.health -= this.attackStrength - this.attackStrength*e[0].obj.shield;
})
.onHit('Solid', function(){
this.velocity *= -1;
})
.bind('EnterFrame', function(){
this.x += this.velocity;
if(this.health <= 0){
kills += 1;
this.destroy();
}
})
}
});
//template for projectiles (both player & enemy)
Crafty.c('Projectile', {
strength:0, xspeed:0,
init: function(){
this.requires('2D, DOM, Color, Image, Collision')
.bind('EnterFrame', function(){
this.x += this.xspeed; //move the bullet
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.health -= this.strength;
this.destroy();
});
}
});
//template for all doors
Crafty.c('Door', {
level:'level0', locked:false, 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(kills >= this.killsNeeded){this.locked = false;}
if(e.key === Crafty.keys.DOWN_ARROW && this.hit('PlayerC') && this.locked === false){
Crafty.enterScene(this.level);
}
else if(e.key === Crafty.keys.DOWN_ARROW && this.hit('PlayerC') && this.locked === true){
Crafty.e('Words').attr({x: this.x, y: this.y - 20, w:75, h: 20}).text('Locked!').textFont({size:'15px'});
}
});
}
});
//default template for all 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'});
}
});
/** LEVEL SCREENS **/
//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('level0');
//initials(200, 550);
spawnPlayer(200,550);
});
});
//game over screen
Crafty.defineScene('Over', function(){
Crafty.background('url(http://i.imgur.com/c2A937j.png)');
Crafty.e('Words').attr({x: 100, y:100, w:800, h:100}).text('You fell into eternal rest...').textFont({size:'40px'});
Crafty.e('Words').attr({x: 200, y:200, w:250, h:200}).text('Press any key to restart.')
.bind('KeyDown', function(e){
Crafty.enterScene('level1');
//spawnPlayer(200,550);
});
});
//tutorial screen
Crafty.defineScene('level0', function(){
Crafty.background('#2E2E2F');
//platforms
Crafty.e('mom').attr({x: 0, y: 550, w: 1160, h: 50}); //floor
Crafty.e('mom').attr({x: 420, y: 440, w: 400, h: 160});
Crafty.e('mom').attr({x:770, y: 335, w: 400, h: 265});
//border
Crafty.e('mom').attr({x: 0, y: 0, w: 30, h: 600}); //W side
Crafty.e('mom').attr({x: 1160, y: 0, w: 30, h: 600}); //E side
Crafty.e('Door').attr({x:790, y: 255, w: 50, h: 80, level:'level1'});
Crafty.e('Words').attr({x:38, y: 50, w: 300, h: 100}).text("^Your health bar.");
Crafty.e('Words').attr({x: 300, y:80, w: 300, h: 100}).text("^Your current ability.");
Crafty.e('Words').attr({x: 38, y: 120, w: 400}).text("Use WASD or arrow keys to jump/move. Press the DOWN arrow key while touching a door to enter it.").textColor('#CCCCCC');
//spawnEnemy(790, 255);
});
//Level 1
Crafty.defineScene('level1', function(){
Crafty.background('#2E2E2F');
//PLATFORMS
Crafty.e('mom').attr({x: 0, y: 550, w: 1600, h: 50});
Crafty.e('mom').attr({x: 1200, y: 440, w: 400, h: 20});
Crafty.e('mom').attr({x: 1400, y: 330, w: 200, h: 20});
//BORDER
Crafty.e('mom').attr({x: 0, y: 0, w: 30, h: 600}); //W side
Crafty.e('mom').attr({x: 1600, y: 0, w: 30, h: 600}); //E side
//EXIT
Crafty.e('Door').attr({x:1550, y: 250, locked:true, killsNeeded:1, level:'level2'});
Crafty.e('Words').attr({x:50, y:100, w:400}).text("To switch abilities, use the X and C keys. Then press the SPACEBAR to use it (unless stated otherwise in the description above it).").textColor('#CCCCCC');
Crafty.e('Words').attr({x:200, y:250, w:400}).text("Practice using the abilities and defeat the enemy in order to proceed.").textColor('#CCCCCC');
spawnEnemy(770, 140);
spawnPlayer(200, 550);
});
//Level 2 Forest
Crafty.defineScene('level2', function(){
Crafty.background('url(http://orig08.deviantart.net/213e/f/2015/183/3/6/background_practice___forest_by_christin_cat_bat-d8otwc1.png)');
//PLATFORMS
Crafty.e('mom').attr({x: 0, y: 550, w: 1600, h: 50}).color('#5C3317');
Crafty.e('mom').attr({x: 1200, y: 440, w: 400, h: 20}).color('#5C3317');
Crafty.e('mom').attr({x: 1400, y: 330, w: 200, h: 20}).color('#5C3317');
Crafty.e('mom').attr({x: 600, y: 100, w: 400, h: 50}).color('#5C3317');
Crafty.e('mom').attr({x: 600, y: 100, w: 400, h: 100}).color('#5C3317');
//BORDER
Crafty.e('mom').attr({x: 0, y: 0, w: 30, h: 600}).color('#5C3317'); //W side
Crafty.e('mom').attr({x: 1600, y: 0, w: 30, h: 600}).color('#5C3317'); //E side
//EXIT
Crafty.e('Door').attr({x:1550, y: 250, locked:true, killsNeeded:1, level:'level3'});
spawnEnemy(770, 140);
spawnPlayer(200, 550);
//spawnFire(771,139);
});
//LEVEL 3 UNDERWATER
Crafty.defineScene('level3', function(){
Crafty.background('url(http://i.imgur.com/FRAQq6V.jpg)');
spawnPlayer(150, 20);
spawnEnemy(300, 140);
//water
Crafty.e('2D, DOM, Canvas, Color, Gravity')
.attr({alpha: 0.5, x:30, y: 400, w: 1000, h: 530})
.color('#248F8F');
//iceberg standing platform
var ber = Crafty.e('2D, Canvas, Solid, Image, Collision')
.attr({x:125, y: 350, w: 200, h: 400})
.image('http://i.imgur.com/mrIQSpo.png');
ber.rotation = 360;
//blackbar at bottom
Crafty.e('mom')
.attr({x: 0, y: 1030, w: 1000, h: 20});
});
/** INITIATIONS & PLAYER FUNCTIONS **/
//start scene
Crafty.enterScene('Start');
//spawns player & misc.
var playerw = 30;
var playerh = 50;
var abilities = ['The classic Sword', 'Super Strength to smash through enemies and walls', 'Unleash your inner minion',
'Body Shield: makes you immune to all damage while activated', 'Roar to briefly stun enemies', 'Suck the life force out of your enemies and heal yourself',
'Heal yourself a bit at a time', 'Darts that gradually poison your enemies to death', 'Arrows of a Centaur',
"Double Jumping - don't need spacebar to use; just press UP key twice", 'Water Blast - can also put out fires',
'Breathe and swim underwater like a fish'];
var spawnPlayer = function(xpos, ypos){
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
//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');
//ability slots
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 - 15, w: 500, h: 40}).text('Your current ability: '+abilities[player.slotSelect-1]).textFont({size:'10px'});
//update health & ability slot bars so they're visible at all times
updateHealth = function(){
healthBarOutline.destroy();
healthBar.destroy();
slotBarOutline.destroy();
slotBars.destroy();
slotSelector.destroy();
abilityText.destroy();
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');
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 - 15, w: 500, h: 40}).text('Your current ability: '+abilities[player.slotSelect-1]).textFont({size:'10px'});
//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.bind('KeyDown', function(e) {
//sword
if(player.slotSelect === 1){
if(e.key === Crafty.keys.SPACE){
player.sprite = 'http://i.imgur.com/QWYfemj.png';
player.onHit('Enemy', function(e){
if(e[0].obj.x > player.x+playerw && e[0].obj.x < player.x + player.w){e[0].obj.health-=10;}
});
player.bind('KeyUp', function(){player.sprite = 'http://i.imgur.com/lSex1EM.png';});
}
}
//super strength to KO enemies and smash through certain walls
//gemini???? unleash a demolisher
//body shield makes player immune to all damage
else if(player.slotSelect === 4){
if(e.key === Crafty.keys.SPACE){
player.shield = 1;
player.bind('KeyUp', function(){player.shield = 0;})
}
}
//roar to briefly stun enemies
//suck the life force out of enemies and heal yourself
else if(player.slotSelect === 6){
if(e.key === Crafty.keys.SPACE){
player.shield = 1;
player.onHit('Enemy', function(e){
player.health += 0.1;
if(player.health > player.maxHealth){player.health = player.maxHealth;}
updateHealth();
e[0].obj.health -= 0.1;
});
player.bind('KeyUp', function(){player.shield = 0;});
}
}
//healing
else if(player.slotSelect === 7){
if(e.key === Crafty.keys.SPACE){
player.health += 10;
if(player.health > player.maxHealth){player.health = player.maxHealth;}
updateHealth();
}
}
//poison darts that slowly decrease an enemy's health until it dies, once hit (THIS NEEDS WORK)
else if(player.slotSelect === 8){
if(e.key === Crafty.keys.SPACE){
Crafty.e('Projectile').attr({x: this._x, y: this._y + 0.5*playerh, w: 15, h: 10, xspeed: 7*player.dir, strength: 5}).color('#2C7A32')
.onHit('Enemy', function(e){
var timer = setInterval(function(){
e[0].obj.health -= 5;
if(e[0].obj.health <= 0){clearInterval(timer);}
}, 1000);
});
}
}
//arrows that do the most damage out of all the projectiles
else if(player.slotSelect === 9){
if(e.key === Crafty.keys.SPACE){
Crafty.e('Projectile').attr({x: this._x, y: this._y + 0.3*playerh, w: 25, h: 5, xspeed: 10*player.dir, strength: 10}).color('#6E5023');
}
}
//double jump
else if(player.slotSelect === 10){
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 or tsunami? can also put out fires and push back enemies
else if(player.slotSelect === 11){
if(e.key === Crafty.keys.SPACE){
Crafty.e('Projectile').attr({x: this._x, y: this._y + 0.3*playerh, w: 25, h: 25, xspeed: 8*player.dir, strength: 4}).color('#008B8B');
}
}
//breathe underwater
});
}
/** ENEMY LOGIC **/
var spawnEnemy = function(xpos, ypos){
Crafty.e('Enemy').attr({x: xpos, y: ypos, w: 30, h:50}).color('#000');
}
</script>
</body>
</html>