fixes for animations with head and jump, etc.

This commit is contained in:
jeena 2013-12-25 00:28:28 +01:00
parent 142964938c
commit 283a1ef48b
16 changed files with 147 additions and 109 deletions

View file

@ -29,8 +29,8 @@ define(function () {
this.player.jump();
}
PlayerController.prototype.lookAt = function (x, y) {
this.player.lookAt(x, y);
PlayerController.prototype.lookAt = function (options) {
if(options) this.player.lookAt(options.x, options.y);
}
PlayerController.prototype.update = function () {

View file

@ -5,8 +5,11 @@ define([
function (Box2D, Exception) {
function GameObject(physicsEngine) {
function GameObject(physicsEngine, uid) {
this.uid = uid;
var def = this.getBodyDef();
def.userData = this;
this.body = physicsEngine.getWorld().CreateBody(def);
}

View file

@ -7,9 +7,9 @@ define([
function (Parent, Box2D, Settings, CollisionDetector) {
function Tile(physicsEngine, options) {
function Tile(physicsEngine, uid, options) {
this.options = options;
Parent.call(this, physicsEngine);
Parent.call(this, physicsEngine, uid);
this.createPhysicTile(this.options);
}

View file

@ -34,7 +34,7 @@ define([
var tiles = this.levelObject.tiles;
for (var i = 0; i < tiles.length; i++) {
this.gameObjects.fixed.push(new Tile(this.engine, tiles[i]));
this.gameObjects.fixed.push(new Tile(this.engine, "tile-" + i, tiles[i]));
}
}

View file

@ -7,17 +7,16 @@ define([
function (Parent, Box2D, Settings, CollisionDetector) {
function Doll (physicsEngine, playerId) {
function Doll (physicsEngine, uid) {
this.playerId = playerId;
Parent.call(this, physicsEngine);
Parent.call(this, physicsEngine, uid);
this.standing = false;
this.moveDirection = 0;
this.lookDirection = 0;
this.legs;
this.actionState = null;
this.lookAtXY = {x:0, y:0};
this.createFixtures();
this.body.SetActive(false);
@ -32,8 +31,6 @@ function (Parent, Box2D, Settings, CollisionDetector) {
bodyDef.fixedRotation = true;
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
bodyDef.userData = CollisionDetector.IDENTIFIER.PLAYER + '-' + this.playerId;
return bodyDef;
};
@ -83,6 +80,10 @@ function (Parent, Box2D, Settings, CollisionDetector) {
this.actionState = state;
}
Doll.prototype.getActionState = function() {
return this.actionState;
}
Doll.prototype.isWalking = function() {
return ["walk", "walkback", "run"].indexOf(this.actionState) >= 0;
}
@ -141,6 +142,7 @@ function (Parent, Box2D, Settings, CollisionDetector) {
Doll.prototype.stop = function () {
this.moveDirection = 0;
this.setFriction(Settings.PLAYER_FRICTION);
if(this.isStanding()) this.setActionState("stand");
}
Doll.prototype.jump = function () {
@ -157,12 +159,13 @@ function (Parent, Box2D, Settings, CollisionDetector) {
}
Doll.prototype.destroy = function () {
this.body.GetWorld().DestroyBody(this.body);
Parent.prototype.destroy.call(this);
}
Doll.prototype.setStanding = function (isStanding) {
if (this.standing == isStanding) return;
this.standing = isStanding;
this.setActionState("stand");
if(isStanding) this.setActionState("stand");
}
Doll.prototype.isStanding = function () {
@ -170,33 +173,30 @@ function (Parent, Box2D, Settings, CollisionDetector) {
}
Doll.prototype.lookAt = function(x, y) {
var lastLookDirection = this.lookDirection;
/*
var degree = Math.atan2(Settings.STAGE_WIDTH / 2 - x, Settings.STAGE_HEIGHT / 2 - 25 - y) / (Math.PI / 180);
if (x < Settings.STAGE_WIDTH / 2) {
this.mc.scaleX = -1;
this.lookDirection = -1;
degree = (-45 + degree / 2);
this.mc.head.rotation = degree;
} else if (x >= Settings.STAGE_WIDTH / 2) {
this.mc.scaleX = 1;
this.lookDirection = 1;
degree = (45 + -degree / 2) - 90;
this.mc.head.rotation = degree;
}
*/
this.body.SetAwake(true);
if(x < 0) {
this.lookDirection = -1;
} else {
this.lookDirection = 1;
}
this.lookAtXY.x = x;
this.lookAtXY.y = y;
};
Doll.prototype.onFootSensorDetection = function(isColliding) {
if(isColliding && !(this.body.GetLinearVelocity().y < -Settings.JUMP_SPEED && !this.isStanding())) {
//if(isColliding && !(this.body.GetLinearVelocity().y < -Settings.JUMP_SPEED && !this.isStanding())) {
// this.setStanding(true);
//}
var hasJumpStartVelocity = this.body.GetLinearVelocity().y < -Settings.JUMP_SPEED;
if(isColliding && !hasJumpStartVelocity) {
this.setStanding(true);
}
};
Doll.prototype.update = function() {

View file

@ -19,7 +19,7 @@ function (Doll, Settings) {
};
Player.prototype.spawn = function (x, y) {
this.doll = new Doll(this.physicsEngine, this.id);
this.doll = new Doll(this.physicsEngine, "doll-" + this.id);
this.doll.spawn(x, y);
this.isSpawned = true;
}