-
Notifications
You must be signed in to change notification settings - Fork 0
/
paddle.js
39 lines (32 loc) · 1022 Bytes
/
paddle.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
(function () {
'use strict';
if (typeof window.PongGame === "undefined") {
window.PongGame = {};
}
var Paddle = window.PongGame.Paddle = function (context, position) {
this.context = context;
this.position = position;
this.width = 10;
this.height = 70;
}
Paddle.prototype.render = function () {
this.context.beginPath();
this.context.rect(this.position[0], this.position[1], this.width, this.height);
this.context.fillStyle = "white"
this.context.fill();
}
Paddle.prototype.move = function (direction) {
this.position[1] += direction;
if (this.position[1] < 0) {
this.position[1] = 0;
} else if (this.position[1] + this.height > this.context.canvas.height) {
this.position[1] = this.context.canvas.height - this.height;
}
}
Paddle.prototype.isTop = function () {
return (this.position[1] <= 0)
}
Paddle.prototype.isBottom = function () {
return (this.position[1] + this.height >= this.context.canvas.height)
}
})();