Skip to content

Commit

Permalink
15 minutes - tweaking player movement
Browse files Browse the repository at this point in the history
  • Loading branch information
Armen138 committed Jun 22, 2012
1 parent 3f52e8d commit 3b16b8c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
19 changes: 14 additions & 5 deletions a2d.dinostreetfreak/js/dino.js
Expand Up @@ -62,14 +62,23 @@ var game = {
console.log(game.level.getTiles());
})

document.addEventListener("keydown", function() {
document.addEventListener("keydown", function(e) {
//game.player.right = true;
game.player.right();
switch(e.keyCode) {
case a2d.key.ARROW_LEFT:
game.player.left();
break;
case a2d.key.ARROW_RIGHT:
game.player.right();
break
case a2d.key.SPACE:
game.player.jump();
break;
}
});

document.addEventListener("keyup", function() {
//game.player.right = false;
//game.player.stop();
document.addEventListener("keyup", function() {
game.player.stop();
});
/*a2d.canvas.addEventListener("click", function(e) {
game.level.push(new game.Player(new a2d.Position(e.clientX, e.clientY)));
Expand Down
19 changes: 17 additions & 2 deletions a2d.dinostreetfreak/js/player.js
Expand Up @@ -15,7 +15,7 @@ game.Player = function(pos) {
fixDef.restitution = 0.2;
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
fixDef.shape = new Box2D.Collision.Shapes.b2PolygonShape;
fixDef.shape.SetAsBox(3.2, 3.2);
fixDef.shape.SetAsBox(3.0, 3.0);
bodyDef.position.Set(pPos.x, pPos.y);
bodyDef.allowSleep = false;
body = game.world.CreateBody(bodyDef);
Expand All @@ -29,9 +29,24 @@ game.Player = function(pos) {
$draw();
};

this.jump = function() {
//body.SetLinearVelocity(new Box2D.Common.Math.b2Vec2(0, 0));
var f = new Box2D.Common.Math.b2Vec2(150, -500);
body.ApplyImpulse(f, body.GetPosition());
};

this.left = function() {
var f = new Box2D.Common.Math.b2Vec2(-50, 0);
//body.SetLinearVelocity(f);
body.ApplyImpulse(f, body.GetPosition());
};
this.right = function() {
var f = new Box2D.Common.Math.b2Vec2(500, 0);
var f = new Box2D.Common.Math.b2Vec2(50, 0);
//body.SetLinearVelocity(f);
body.ApplyImpulse(f, body.GetPosition());
};
this.stop = function() {
var f = new Box2D.Common.Math.b2Vec2(0, 0);
//body.SetLinearVelocity(f);
};
};

0 comments on commit 3b16b8c

Please sign in to comment.