forked from marler8997/SlimeJavascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Slime.js
48 lines (42 loc) · 1.12 KB
/
Slime.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
// Objects rendered in the slime engine
// need an x and a y parameter
function newBall(radius,color) {
return {
radius:radius,
color:color,
x:0,
y:0,
velocityX:0,
velocityY:0,
render: function() {
var xPix = this.x * pixelsPerUnit;
var yPix = courtY - (this.y * pixelsPerUnit);
// The original game's ball looked bigger then
// it was, so we add 2 pixels here to the radius
var radiusPix = this.radius * pixelsPerUnit + 2;
ctx.fillStyle = this.color;
ctx.beginPath();
ctx.arc(xPix, yPix, radiusPix, 0, 2*Math.PI);
ctx.fill();
}
};
}
function newSlime(radius,color) {
return {
radius:radius,
color:color,
x:0,
y:0,
velocityX:0,
velocityY:0,
render: function() {
var xPix = this.x * pixelsPerUnit;
var yPix = courtY - (this.y * pixelsPerUnit);
var radiusPix = this.radius * pixelsPerUnit;
ctx.fillStyle = this.color;
ctx.beginPath();
ctx.arc(xPix, yPix, radiusPix, Math.PI, 2*Math.PI);
ctx.fill();
}
};
}