Skip to content

Instantly share code, notes, and snippets.

@caubry
Created January 18, 2014 21:50
Show Gist options
  • Save caubry/8497139 to your computer and use it in GitHub Desktop.
Save caubry/8497139 to your computer and use it in GitHub Desktop.
GameEngineClass = Class.extend({
move_dir: new Vec2(0,0),
dirVec: new Vec2(0,0),
gPlayer0: {
pos: {
x: 100,
y: 100
},
walkSpeed: 1,
mpPhysBody: new BodyDef()
},
//-----------------------------
setup: function () {
gInputEngine.setup();
},
update: function () {
if (gInputEngine.actions['move-up']) {
gGameEngine.move_dir.y -= 1;
}
if (gInputEngine.actions['move-down']) {
gGameEngine.move_dir.y += 1;
}
if (gInputEngine.actions['move-left']) {
gGameEngine.move_dir.x -= 1;
}
if (gInputEngine.actions['move-right']) {
gGameEngine.move_dir.x += 1;
}
if (gGameEngine.move_dir.LengthSquared()) {
gGameEngine.move_dir.Normalize();
gGameEngine.move_dir.Multiply(gGameEngine.gPlayer0.walkSpeed);
}
gGameEngine.gPlayer0.mpPhysBody.setLinearVelocity(gGameEngine.move_dir.x, gGameEngine.move_dir.y);
if (gInputEngine.actions.fire0 || gInputEngine.actions.fire1) {
var value = gGameEngine.gRenderEngine.getScreenPosition(
gGameEngine.gPlayer0.pos.x, gGameEngine.gPlayer0.pos.y
);
gGameEngine.dirVec.x = gGameEngine.move_dir.x - gGameEngine.gPlayer0.pos.x;
gGameEngine.dirVec.y = gGameEngine.move_dir.y - gGameEngine.gPlayer0.pos.y;
gGameEngine.dirVec.Normalize();
}
}
});
gGameEngine = new GameEngineClass();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment