-
Notifications
You must be signed in to change notification settings - Fork 0
/
Paddle.js
39 lines (35 loc) · 811 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 Paddle(yPos){
/*=========
Variables
=========*/
var that; // pointer to "this" [Private]
this.x; // x-coordinate of paddle's position [Public]
this.y; // y-coordinate of paddle's position [Public]
/*===========
Constructor
===========*/
that = this; // Unused in Paddle
this.x = Pong.WIDTH/2;
this.y = yPos - Paddle.HEIGHT/2;
}
/*================
Static Variables
================*/
Paddle.WIDTH = 60;
Paddle.HEIGHT = 16;
Paddle.R1 = 5;
Paddle.R2 = 10;
Paddle.R3 = 25;
/*=============
move [Public]
=============*/
Paddle.prototype.move = function(newx) {
if (newx < Paddle.WIDTH/2)
this.x = Paddle.WIDTH/2;
else if (newx > Pong.WIDTH - Paddle.WIDTH/2)
this.x = Pong.WIDTH - Paddle.WIDTH/2;
else
this.x = newx;
}
// For node.js require
global.Paddle = Paddle;