-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentities.js
96 lines (96 loc) · 2.51 KB
/
entities.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var PlayerEntity = me.ObjectEntity.extend({
init: function(x, y, settings) {
this.parent(x, y, settings);
me.game.viewport.fadeIn("#B70000", 200);
me.game.viewport.follow(this.pos, me.game.viewport.AXIS.BOTH);
this.setVelocity(4,14);
},
update: function() {
if (me.input.isKeyPressed('left')) { this.doWalk(true); }
else if (me.input.isKeyPressed('right')) { this.doWalk(false); }
else { this.vel.x = 0; };
if (me.input.isKeyPressed('jump')) { this.doJump(); }
me.game.collide(this);
this.updateMovement();
if (this.bottom > 960){ this.gameOver();}
if (this.vel.x!=0 || this.vel.y!=0) {
this.parent(this);
return true;
}
return false;
},
gameOver: function() {
me.state.change(me.state.PLAY);
},
youWin: function() {
me.state.change(me.state.GAME_END);
}
});
var CoinEntity = me.CollectableEntity.extend({
init: function(x, y, settings) {
this.parent(x, y, settings);
},
onCollision : function (res, obj) {
me.gamestat.updateValue("coins", 1);
this.collidable = false;
me.game.remove(this);
if(me.gamestat.getItemValue("coins") === me.gamestat.getItemValue("totalCoins")){
obj.youWin();
}
}
});
var EnemyEntity = me.ObjectEntity.extend({
init: function(x, y, settings) {
settings.image = "enemy";
settings.spritewidth = 16;
this.parent(x, y, settings);
this.startX = x;
this.endX = x + settings.width - settings.spritewidth;
this.pos.x = this.endX;
this.walkLeft = true;
this.setVelocity(1.5);
this.collidable = true;
},
onCollision: function(res, obj) {
obj.gameOver();
},
update: function() {
if (!this.visible){
return false;
}
if (this.alive) {
if (this.walkLeft && this.pos.x <= this.startX) {
this.walkLeft = false;
}
else if (!this.walkLeft && this.pos.x >= this.endX){
this.walkLeft = true;
}
this.doWalk(this.walkLeft);
}
else { this.vel.x = 0; }
this.updateMovement();
if (this.vel.x!=0 || this.vel.y!=0) {
this.parent(this);
return true;
}
return false;
}
});
var thornEntity = me.ObjectEntity.extend({
init: function(x, y, settings) {
this.parent(x, y, settings);
this.collidable = true;
},
onCollision: function (res, obj) {
obj.gameOver();
}
});
var thornEntity2 = me.ObjectEntity.extend({
init: function(x, y, settings) {
this.parent(x, y, settings);
this.collidable = true;
},
onCollision: function (res, obj) {
obj.gameOver();
}
});