-
Notifications
You must be signed in to change notification settings - Fork 3
/
ball.js
35 lines (31 loc) · 909 Bytes
/
ball.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
// ************************************************
// Teugg Soccer Physics
// Rip-off of the once popular Soccer Physics game
// Horribly coded by : Kevin Le Teugg, 2020
// File : ball.js
// Description : Ball class
// ************************************************
class Ball {
constructor(options) {
// ATTRIBUTES
this.x = options.startPosX;
this.y = options.startPosY;
this.r = options.radius;
this.body = Bodies.circle(this.x, this.y, this.r, options);
// Adding the body to the world
World.add(world, this.body);
}
// DRAWING FUNCTION
show() {
push();
translate(this.body.position.x, this.body.position.y);
rotate(this.body.angle);
image(spriteSoccerBall, -this.r, -this.r, 2 * this.r, 2 * this.r);
stroke(0, 0, 0);
fill(255);
pop();
};
isOnGround(ground) {
return Matter.SAT.collides(this.body, ground.body).collided;
};
}