-
Notifications
You must be signed in to change notification settings - Fork 1
/
game_characters.js
118 lines (106 loc) · 2.22 KB
/
game_characters.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
var player = {
isDown: true,
x: 120,
y: 290,
width:40,
height:40,
draw: function() {
ctx.fillStyle = "#000000";
ctx.fillRect(this.x,this.y-this.width,
this.width,this.height);
},
reverse: function() {
player.isDown = !player.isDown;
if (player.isDown) {
player.y = floor_y;
} else {
player.y = ceil_y
}
}
};
ceil_y = 200;
floor_y = 290
//-------------- Enimies ------------------
var CeilBlocker = function(xStart) {
console.log("creating CeilBlocker");
this.swap = false;
this.width = 50;
this.height = 50;
this.x = xStart;
this.y = this.width;
this.draw = function() {
if (this.swap) {
ctx.fillStyle = "#990000";
ctx.fillRect(this.x,this.y-this.width,
this.width,this.height);
} else {
ctx.clearRect(this.x,this.y-this.width,
this.width,this.height);
}
};
this.update = function(speed) {
this.x += 10 * speed
if (this.x > actualWidth) {
this.x = 0;
this.swap = !this.swap;
} else if (this.x < -this.width) {
this.x = actualWidth;
this.swap = !this.swap;
}
if (this.swap) {
this.y = actualHeight / 2 + this.width;
} else {
this.y = this.width;
}
};
};
var Blocker = function(xStart) {
console.log("creating Blocker");
this.swap = false;
this.width = 50;
this.height = 50;
this.x = xStart;
this.y = actualHeight / 2;
this.draw = function() {
if (this.swap) {
ctx.fillStyle = "#009900";
ctx.fillRect(this.x,this.y-this.width,
this.width,this.height);
} else {
ctx.clearRect(this.x,this.y-this.width,
this.width,this.height);
}
};
this.update = function(speed) {
this.x += 10 * speed
if (this.x > actualWidth) {
this.x = 0;
this.swap = !this. swap;
} else if (this.x < -this.width) {
this.x = actualWidth;
this.swap = !this.swap;
}
if (this.swap) {
this.y = actualHeight;
} else {
this.y = actualHeight / 2
}
};
};
//------------- GameController -----------------
var GameController = {
blockers: [],
draw: function() {
for (var b in this.blockers) {
this.blockers[b].draw();
}
},
update: function() {
for (var b in this.blockers) {
this.blockers[b].update(gameSpeed / 100);
if (collides(player, this.blockers[b])) {
stepsSpentCollided++
}
}
}
}