Tidied up method names
This commit is contained in:
parent
c8777e6556
commit
9d0f3db412
@ -42,7 +42,7 @@ window.onload = function () {
|
||||
mainScene.addChildEntity(rightPaddle);
|
||||
|
||||
|
||||
// Update and render the ball
|
||||
// Update the ball position
|
||||
ball.state.speed = new MomentumEngine.Classes.Vector2D(0.1, 0.05); // Current ball speed
|
||||
|
||||
ball.update = function () {
|
||||
@ -60,7 +60,7 @@ window.onload = function () {
|
||||
};
|
||||
|
||||
|
||||
// Update and render the left paddle
|
||||
// Update the left paddle according to keyboard input
|
||||
leftPaddle.update = function () {
|
||||
|
||||
if (pong.inputs.keyboard.isPressed(KeyConsts.CHAR_Q) || pong.inputs.keyboard.isPressed(KeyConsts.UP)) {
|
||||
@ -79,7 +79,7 @@ window.onload = function () {
|
||||
leftPaddle.pos.y = baseSize;
|
||||
}
|
||||
|
||||
if (leftPaddle.isColliding(ball) && ball.state.speed.x < 0) {
|
||||
if (leftPaddle.isCollidingWith(ball) && ball.state.speed.x < 0) {
|
||||
ball.state.speed.x = -ball.state.speed.x;
|
||||
console.log(ball.state.speed.length());
|
||||
}
|
||||
@ -87,7 +87,7 @@ window.onload = function () {
|
||||
};
|
||||
|
||||
|
||||
// Render the right paddle
|
||||
// Update the right paddle according to keyboard input
|
||||
rightPaddle.update = function () {
|
||||
|
||||
if (pong.inputs.keyboard.isPressed(KeyConsts.CHAR_O)) {
|
||||
@ -106,7 +106,7 @@ window.onload = function () {
|
||||
rightPaddle.pos.y = baseSize;
|
||||
}
|
||||
|
||||
if (rightPaddle.isColliding(ball) && ball.state.speed.x > 0) {
|
||||
if (rightPaddle.isCollidingWith(ball) && ball.state.speed.x > 0) {
|
||||
ball.state.speed.x = -ball.state.speed.x;
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,7 @@ class Entity {
|
||||
|
||||
this._calculatedPos.x = this.pos.x + parentPos.x;
|
||||
this._calculatedPos.y = this.pos.y + parentPos.y;
|
||||
|
||||
} else {
|
||||
this._calculatedPos.x = this.pos.x;
|
||||
this._calculatedPos.y = this.pos.y;
|
||||
@ -90,6 +91,8 @@ class Entity {
|
||||
|
||||
_updateEntity () {
|
||||
|
||||
this._recalculatePos();
|
||||
|
||||
if ((this.update && this.update()) || (typeof this.update === "undefined")) {
|
||||
|
||||
this.children.forEach((child) => {
|
||||
|
@ -19,7 +19,7 @@ class Rect extends Entity {
|
||||
}
|
||||
|
||||
|
||||
isColliding (entity) {
|
||||
isCollidingWith (entity) {
|
||||
|
||||
if (entity instanceof Rect) {
|
||||
return CollisionMethods.AABB(this, entity);
|
||||
@ -30,8 +30,6 @@ class Rect extends Entity {
|
||||
|
||||
render () {
|
||||
|
||||
this._recalculatePos();
|
||||
|
||||
if (this._game) {
|
||||
|
||||
this._game.context.fillStyle = this.color;
|
||||
|
Loading…
x
Reference in New Issue
Block a user