From 9d0f3db4128f19e8e30f4c0f9a269e58db81ccfe Mon Sep 17 00:00:00 2001 From: Nathan Kunicki Date: Mon, 21 Dec 2015 16:56:24 +0000 Subject: [PATCH] Tidied up method names --- examples/pong/pong.js | 10 +++++----- src/classes/entity.js | 3 +++ src/classes/rect.js | 4 +--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/pong/pong.js b/examples/pong/pong.js index 65a3d63..6b94175 100644 --- a/examples/pong/pong.js +++ b/examples/pong/pong.js @@ -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; } diff --git a/src/classes/entity.js b/src/classes/entity.js index d6cf91d..97fd892 100644 --- a/src/classes/entity.js +++ b/src/classes/entity.js @@ -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) => { diff --git a/src/classes/rect.js b/src/classes/rect.js index 7a8ae92..5f4ae97 100644 --- a/src/classes/rect.js +++ b/src/classes/rect.js @@ -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;