Tidied up method names
This commit is contained in:
parent
2eade7a21b
commit
2c88c9ce20
2
dist/es5.js
vendored
2
dist/es5.js
vendored
File diff suppressed because one or more lines are too long
2
dist/es5.js.map
vendored
2
dist/es5.js.map
vendored
File diff suppressed because one or more lines are too long
@ -42,7 +42,7 @@ window.onload = function () {
|
|||||||
mainScene.addChildEntity(rightPaddle);
|
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.state.speed = new MomentumEngine.Classes.Vector2D(0.1, 0.05); // Current ball speed
|
||||||
|
|
||||||
ball.update = function () {
|
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 () {
|
leftPaddle.update = function () {
|
||||||
|
|
||||||
if (pong.inputs.keyboard.isPressed(KeyConsts.CHAR_Q) || pong.inputs.keyboard.isPressed(KeyConsts.UP)) {
|
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;
|
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;
|
ball.state.speed.x = -ball.state.speed.x;
|
||||||
console.log(ball.state.speed.length());
|
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 () {
|
rightPaddle.update = function () {
|
||||||
|
|
||||||
if (pong.inputs.keyboard.isPressed(KeyConsts.CHAR_O)) {
|
if (pong.inputs.keyboard.isPressed(KeyConsts.CHAR_O)) {
|
||||||
@ -106,7 +106,7 @@ window.onload = function () {
|
|||||||
rightPaddle.pos.y = baseSize;
|
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;
|
ball.state.speed.x = -ball.state.speed.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +63,7 @@ class Entity {
|
|||||||
|
|
||||||
this._calculatedPos.x = this.pos.x + parentPos.x;
|
this._calculatedPos.x = this.pos.x + parentPos.x;
|
||||||
this._calculatedPos.y = this.pos.y + parentPos.y;
|
this._calculatedPos.y = this.pos.y + parentPos.y;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this._calculatedPos.x = this.pos.x;
|
this._calculatedPos.x = this.pos.x;
|
||||||
this._calculatedPos.y = this.pos.y;
|
this._calculatedPos.y = this.pos.y;
|
||||||
@ -90,6 +91,8 @@ class Entity {
|
|||||||
|
|
||||||
_updateEntity () {
|
_updateEntity () {
|
||||||
|
|
||||||
|
this._recalculatePos();
|
||||||
|
|
||||||
if ((this.update && this.update()) || (typeof this.update === "undefined")) {
|
if ((this.update && this.update()) || (typeof this.update === "undefined")) {
|
||||||
|
|
||||||
this.children.forEach((child) => {
|
this.children.forEach((child) => {
|
||||||
|
@ -19,7 +19,7 @@ class Rect extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
isColliding (entity) {
|
isCollidingWith (entity) {
|
||||||
|
|
||||||
if (entity instanceof Rect) {
|
if (entity instanceof Rect) {
|
||||||
return CollisionMethods.AABB(this, entity);
|
return CollisionMethods.AABB(this, entity);
|
||||||
@ -30,8 +30,6 @@ class Rect extends Entity {
|
|||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
|
||||||
this._recalculatePos();
|
|
||||||
|
|
||||||
if (this._game) {
|
if (this._game) {
|
||||||
|
|
||||||
this._game.context.fillStyle = this.color;
|
this._game.context.fillStyle = this.color;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user