Skip to content

Commit

Permalink
Update and refactor algebra to prepare for physics
Browse files Browse the repository at this point in the history
* Delete ex.Point from all files
* Convert actors to vector position, velocity, acceleration, update all files
* Fix broken tests that relied on native ex.Actor.x and ex.Actor.y instead of ex.Actor.pos
  • Loading branch information
eonarheim committed May 29, 2016
1 parent 59c77b2 commit 9f22b7d
Show file tree
Hide file tree
Showing 43 changed files with 1,676 additions and 1,674 deletions.
Binary file modified dist/Excalibur.0.6.0.nupkg
Binary file not shown.
209 changes: 100 additions & 109 deletions dist/Excalibur.d.ts

Large diffs are not rendered by default.

649 changes: 323 additions & 326 deletions dist/Excalibur.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/Excalibur.min.js

Large diffs are not rendered by default.

209 changes: 100 additions & 109 deletions dist/excalibur-0.6.0.d.ts

Large diffs are not rendered by default.

649 changes: 323 additions & 326 deletions dist/excalibur-0.6.0.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/excalibur-0.6.0.min.js

Large diffs are not rendered by default.

649 changes: 323 additions & 326 deletions sandbox/web/Excalibur.js

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions sandbox/web/src/game.js
Expand Up @@ -173,25 +173,25 @@ player.on('update', function () {
player.setDrawing(Animations.Left);
}
if (inAir) {
player.dx = -airSpeed;
player.vel.x = -airSpeed;
return;
}
player.dx = -groundSpeed;
player.vel.x = -groundSpeed;
}
else if (game.input.keyboard.isHeld(ex.Input.Keys.Right)) {
direction = 1;
if (!inAir) {
player.setDrawing(Animations.Right);
}
if (inAir) {
player.dx = airSpeed;
player.vel.x = airSpeed;
return;
}
player.dx = groundSpeed;
player.vel.x = groundSpeed;
}
if (game.input.keyboard.isHeld(ex.Input.Keys.Up)) {
if (!inAir) {
player.dy = -jumpSpeed;
player.vel.y = -jumpSpeed;
inAir = true;
if (direction === 1) {
player.setDrawing(Animations.JumpRight);
Expand Down Expand Up @@ -231,9 +231,9 @@ newScene.on('deactivate', function (evt) {
game.addScene('label', newScene);
game.input.keyboard.on('down', function (keyDown) {
if (keyDown.key === ex.Input.Keys.F) {
var a = new ex.Actor(player.x + 10, player.y - 50, 10, 10, new ex.Color(222, 222, 222));
a.dx = 200 * direction;
a.dy = 0;
var a = new ex.Actor(player.pos.x + 10, player.pos.y - 50, 10, 10, new ex.Color(222, 222, 222));
a.vel.x = 200 * direction;
a.vel.y = 0;
a.collisionType = ex.CollisionType.Elastic;
var inAir = true;
a.on('collision', function (data) {
Expand All @@ -244,10 +244,10 @@ game.input.keyboard.on('down', function (keyDown) {
});
a.on('update', function (data) {
if (inAir) {
a.ay = 400; // * data.delta/1000;
a.acc.y = 400; // * data.delta/1000;
}
else {
a.ay = 0;
a.acc.y = 0;
}
inAir = true;
});
Expand All @@ -270,20 +270,20 @@ player.on('collision', function (data) {
}
inAir = false;
if (data.other && !(game.input.keyboard.isHeld(ex.Input.Keys.Left) || game.input.keyboard.isHeld(ex.Input.Keys.Right) || game.input.keyboard.isHeld(ex.Input.Keys.Up) || game.input.keyboard.isHeld(ex.Input.Keys.Down))) {
player.dx = data.other.dx;
player.dy = data.other.dy;
player.vel.x = data.other.vel.x;
player.vel.y = data.other.vel.y;
}
if (!data.other) {
player.dx = 0;
player.dy = 0;
player.vel.x = 0;
player.vel.y = 0;
}
}
if (data.side === ex.Side.Top) {
if (data.other) {
player.dy = data.other.dy - player.dy;
player.vel.y = data.other.vel.y - player.vel.y;
}
else {
player.dy = 0;
player.vel.y = 0;
}
}
});
Expand Down Expand Up @@ -350,7 +350,7 @@ emitter.acceleration = new ex.Vector(0, 460);
emitter.beginColor = ex.Color.Red;
emitter.endColor = ex.Color.Yellow;
emitter.particleSprite = blockSprite.clone();
emitter.particleSprite.anchor = new ex.Point(.5, .5);
emitter.particleSprite.anchor = new ex.Vector(.5, .5);
emitter.particleRotationalVelocity = Math.PI / 10;
emitter.randomRotation = true;
emitter.particleSprite.addEffect(new ex.Effects.Grayscale());
Expand Down
34 changes: 17 additions & 17 deletions sandbox/web/src/game.ts
Expand Up @@ -211,10 +211,10 @@ player.on('update', () => {
player.setDrawing(Animations.Left);
}
if (inAir) {
player.dx = -airSpeed;
player.vel.x = -airSpeed;
return;
}
player.dx = -groundSpeed;
player.vel.x = -groundSpeed;

// TODO: When platform is moving in same direction, add its dx

Expand All @@ -224,17 +224,17 @@ player.on('update', () => {
player.setDrawing(Animations.Right);
}
if (inAir) {
player.dx = airSpeed;
player.vel.x = airSpeed;
return;
}
player.dx = groundSpeed;
player.vel.x = groundSpeed;

// TODO: When platform is moving in same direction, add its dx
}

if (game.input.keyboard.isHeld(ex.Input.Keys.Up)) {
if (!inAir) {
player.dy = -jumpSpeed;
player.vel.y = -jumpSpeed;
inAir = true;
if (direction === 1) {
player.setDrawing(Animations.JumpRight);
Expand Down Expand Up @@ -282,9 +282,9 @@ game.addScene('label', newScene);

game.input.keyboard.on('down', (keyDown?: ex.Input.KeyEvent) => {
if (keyDown.key === ex.Input.Keys.F) {
var a = new ex.Actor(player.x + 10, player.y - 50, 10, 10, new ex.Color(222, 222, 222));
a.dx = 200 * direction;
a.dy = 0;
var a = new ex.Actor(player.pos.x + 10, player.pos.y - 50, 10, 10, new ex.Color(222, 222, 222));
a.vel.x = 200 * direction;
a.vel.y = 0;
a.collisionType = ex.CollisionType.Elastic;
var inAir = true;
a.on('collision', (data?: ex.CollisionEvent) => {
Expand All @@ -295,9 +295,9 @@ game.input.keyboard.on('down', (keyDown?: ex.Input.KeyEvent) => {
});
a.on('update', (data?: ex.UpdateEvent) => {
if (inAir) {
a.ay = 400;// * data.delta/1000;
a.acc.y = 400;// * data.delta/1000;
} else {
a.ay = 0;
a.acc.y = 0;
}
inAir = true;
});
Expand All @@ -321,22 +321,22 @@ player.on('collision', (data?: ex.CollisionEvent) => {
}
inAir = false;
if (data.other && !(game.input.keyboard.isHeld(ex.Input.Keys.Left) || game.input.keyboard.isHeld(ex.Input.Keys.Right) || game.input.keyboard.isHeld(ex.Input.Keys.Up) || game.input.keyboard.isHeld(ex.Input.Keys.Down))) {
player.dx = data.other.dx;
player.dy = data.other.dy;
player.vel.x = data.other.vel.x;
player.vel.y = data.other.vel.y;
}

if (!data.other) {
player.dx = 0;
player.dy = 0;
player.vel.x = 0;
player.vel.y = 0;
}

}

if (data.side === ex.Side.Top) {
if (data.other) {
player.dy = data.other.dy - player.dy;
player.vel.y = data.other.vel.y - player.vel.y;
} else {
player.dy = 0;
player.vel.y = 0;
}

}
Expand Down Expand Up @@ -411,7 +411,7 @@ emitter.acceleration = new ex.Vector(0, 460);
emitter.beginColor = ex.Color.Red;
emitter.endColor = ex.Color.Yellow;
emitter.particleSprite = blockSprite.clone();
emitter.particleSprite.anchor = new ex.Point(.5, .5);
emitter.particleSprite.anchor = new ex.Vector(.5, .5);
emitter.particleRotationalVelocity = Math.PI / 10;
emitter.randomRotation = true;
emitter.particleSprite.addEffect(new ex.Effects.Grayscale());
Expand Down
6 changes: 3 additions & 3 deletions sandbox/web/tests/collision/index.js
@@ -1,8 +1,8 @@
var engine = new ex.Engine(600, 400);
var active = new ex.Actor(0, -50, 100, 100, ex.Color.Cyan);
active.collisionType = ex.CollisionType.Active;
active.dy = 100;
active.ay = 900;
active.vel.y = 100;
active.acc.y = 900;
active.on('update', function () {
//console.log('current dy', active.dy);
});
Expand All @@ -13,7 +13,7 @@ engine.add(active);
engine.add(fixed);
engine.input.keyboard.on('down', function () {
console.log('jump');
active.dy = -300;
active.vel.y = -300;
});
engine.start().then(function () {
console.log("loaded");
Expand Down
6 changes: 3 additions & 3 deletions sandbox/web/tests/collision/index.ts
Expand Up @@ -3,8 +3,8 @@

var active = new ex.Actor(0, -50, 100, 100, ex.Color.Cyan);
active.collisionType = ex.CollisionType.Active;
active.dy = 100;
active.ay = 900;
active.vel.y = 100;
active.acc.y = 900;
active.on('update',() => {
//console.log('current dy', active.dy);
});
Expand All @@ -20,7 +20,7 @@ engine.add(fixed);

engine.input.keyboard.on('down',() => {
console.log('jump');
active.dy = -300;
active.vel.y = -300;
});

engine.start().then(() => {
Expand Down
18 changes: 9 additions & 9 deletions sandbox/web/tests/culling/culling.js
Expand Up @@ -7,38 +7,38 @@ engine.backgroundColor = ex.Color.Black;
var player = new ex.Actor(width / 2, height / 2, 30, 30, ex.Color.Red);
var playerSprite = playerTexture.asSprite();
player.addDrawing("default", playerSprite);
player.currentDrawing.anchor = new ex.Point(0.5, 0.5); //TODO what if we don't do this?
player.currentDrawing.anchor = new ex.Vector(0.5, 0.5); //TODO what if we don't do this?
//player.currentDrawing.scale = new ex.Point(0.5, 0.5);
engine.currentScene.add(player);
engine.input.keyboard.on('down', function (keyDown) {
if (keyDown.key === ex.Input.Keys.D) {
engine.isDebug = !engine.isDebug;
}
else if (keyDown.key === ex.Input.Keys.Up) {
player.dy = -speed;
player.vel.y = -speed;
}
else if (keyDown.key === ex.Input.Keys.Down) {
player.dy = speed;
player.vel.y = speed;
}
else if (keyDown.key === ex.Input.Keys.Left) {
player.dx = -speed;
player.vel.x = -speed;
}
else if (keyDown.key === ex.Input.Keys.Right) {
player.dx = speed;
player.vel.x = speed;
}
});
engine.input.keyboard.on('up', function (keyUp) {
if (keyUp.key === ex.Input.Keys.Up) {
player.dy = 0;
player.vel.y = 0;
}
else if (keyUp.key === ex.Input.Keys.Down) {
player.dy = 0;
player.vel.y = 0;
}
else if (keyUp.key === ex.Input.Keys.Left) {
player.dx = 0;
player.vel.x = 0;
}
else if (keyUp.key === ex.Input.Keys.Right) {
player.dx = 0;
player.vel.x = 0;
}
});
engine.start(new ex.Loader([playerTexture])).then(function () {
Expand Down
18 changes: 9 additions & 9 deletions sandbox/web/tests/culling/culling.ts
Expand Up @@ -10,33 +10,33 @@ engine.backgroundColor = ex.Color.Black;
var player = new ex.Actor(width / 2, height / 2, 30, 30, ex.Color.Red);
var playerSprite = playerTexture.asSprite();
player.addDrawing("default", playerSprite);
player.currentDrawing.anchor = new ex.Point(0.5, 0.5); //TODO what if we don't do this?
player.currentDrawing.anchor = new ex.Vector(0.5, 0.5); //TODO what if we don't do this?
//player.currentDrawing.scale = new ex.Point(0.5, 0.5);
engine.currentScene.add(player);

engine.input.keyboard.on('down', (keyDown?: ex.Input.KeyEvent) => {
if (keyDown.key === ex.Input.Keys.D) {
engine.isDebug = !engine.isDebug;
} else if (keyDown.key === ex.Input.Keys.Up) {
player.dy = -speed;
player.vel.y = -speed;
} else if (keyDown.key === ex.Input.Keys.Down) {
player.dy = speed;
player.vel.y = speed;
} else if (keyDown.key === ex.Input.Keys.Left) {
player.dx = -speed;
player.vel.x = -speed;
} else if (keyDown.key === ex.Input.Keys.Right) {
player.dx = speed;
player.vel.x = speed;
}
});

engine.input.keyboard.on('up', (keyUp?: ex.Input.KeyEvent) => {
if (keyUp.key === ex.Input.Keys.Up) {
player.dy = 0;
player.vel.y = 0;
} else if (keyUp.key === ex.Input.Keys.Down) {
player.dy = 0;
player.vel.y = 0;
} else if (keyUp.key === ex.Input.Keys.Left) {
player.dx = 0;
player.vel.x = 0;
} else if (keyUp.key === ex.Input.Keys.Right) {
player.dx = 0;
player.vel.x = 0;
}
});

Expand Down
20 changes: 10 additions & 10 deletions sandbox/web/tests/group/group.js
Expand Up @@ -17,24 +17,24 @@ for (var i = 0; i < numActors; i++) {
actor.addDrawing("default", blockSprite);
actor.collisionType = ex.CollisionType.Elastic;
actor.on('update', function (e) {
if (this.x < 0) {
this.dx = Math.abs(this.dx);
if (this.pos.x < 0) {
this.vel.x = Math.abs(this.vel.x);
}
if (this.y < 0) {
this.dy = Math.abs(this.dy);
if (this.pos.y < 0) {
this.vel.y = Math.abs(this.vel.y);
}
if (this.x > width) {
this.dx = -1 * Math.abs(this.dx);
if (this.pos.x > width) {
this.vel.x = -1 * Math.abs(this.vel.x);
}
if (this.y > height) {
this.dy = -1 * Math.abs(this.dy);
if (this.pos.y > height) {
this.vel.y = -1 * Math.abs(this.vel.y);
}
});
actor.on('collision', function () {
//console.log('inner collision');
});
actor.dx = ex.Util.randomInRange(minVel, maxVel);
actor.dy = ex.Util.randomInRange(minVel, maxVel);
actor.vel.x = ex.Util.randomInRange(minVel, maxVel);
actor.vel.y = ex.Util.randomInRange(minVel, maxVel);
blockGroup.add(actor);
}
blockGroup.on('collision', function (e) {
Expand Down
20 changes: 10 additions & 10 deletions sandbox/web/tests/group/group.ts
Expand Up @@ -24,28 +24,28 @@ for (var i = 0; i < numActors; i++) {

actor.collisionType = ex.CollisionType.Elastic;
actor.on('update', function (e: ex.UpdateEvent) {
if (this.x < 0) {
this.dx = Math.abs(this.dx);
if (this.pos.x < 0) {
this.vel.x = Math.abs(this.vel.x);
}

if (this.y < 0) {
this.dy = Math.abs(this.dy);
if (this.pos.y < 0) {
this.vel.y = Math.abs(this.vel.y);
}

if (this.x > width) {
this.dx = -1 * Math.abs(this.dx);
if (this.pos.x > width) {
this.vel.x = -1 * Math.abs(this.vel.x);
}

if (this.y > height) {
this.dy = -1 * Math.abs(this.dy);
if (this.pos.y > height) {
this.vel.y = -1 * Math.abs(this.vel.y);
}
});
actor.on('collision', function () {
//console.log('inner collision');
});

actor.dx = ex.Util.randomInRange(minVel, maxVel);
actor.dy = ex.Util.randomInRange(minVel, maxVel);
actor.vel.x = ex.Util.randomInRange(minVel, maxVel);
actor.vel.y = ex.Util.randomInRange(minVel, maxVel);

blockGroup.add(actor);
}
Expand Down

0 comments on commit 9f22b7d

Please sign in to comment.