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

@ -66,8 +66,9 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
}
PlayerController.prototype.setXY = function(x, y) {
Parent.prototype.lookAt.call(this, x, y);
NotificationCenter.trigger('sendGameCommand', 'lookAt', x, y); // implement that x and y are received
var options = {x:x, y:y};
Parent.prototype.lookAt.call(this, options);
NotificationCenter.trigger('sendGameCommand', 'lookAt', options);
};
PlayerController.prototype.update = function () {

View file

@ -7,10 +7,12 @@ define([
"Game/Core/NotificationCenter",
"Lib/Utilities/RequestAnimFrame",
"Game/Config/Settings",
"Lib/Vendor/Stats"
"Lib/Vendor/Stats",
"Game/Client/GameObjects/GameObject",
"Game/Client/Physics/Doll"
],
function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, NotificationCenter, requestAnimFrame, Settings, Stats) {
function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, NotificationCenter, requestAnimFrame, Settings, Stats, GameObject, Doll) {
function GameController () {
this.view = ViewManager.createView();
@ -85,41 +87,21 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
var body = this.physicsEngine.world.GetBodyList();
do {
var bodyName = body.GetUserData();
if(bodyName && updateData[bodyName]) {
var update = updateData[bodyName];
body.SetAwake(true);
if(false && this.me && this.me.getBody() == body) {
var p = body.GetPosition();
var x = update.p.x - p.x;
var y = update.p.y - p.y;
var max = 0.5;
var factor = 0.2;
//if(x > max || x < -max || y > max || y < -max) {
if(!this.mouse_joint) this.makeMouseJoint(update.p);
else this.mouse_joint.SetTarget(update.p);
var self = this;
/*setTimeout(function() {
self.physicsEngine.world.DestroyJoint(self.mouse_joint);
self.mouse_joint = null;
}, Settings.WORLD_UPDATE_BROADCAST_INTERVAL / 2)*/
//} else {
//this.physicsEngine.world.DestroyJoint(this.mouse_joint);
//this.mouse_joint = null;
//}
// NEXT TIME, try to create a simple body, that gets position and velocities from server doll
// and connect the joint to that.
} else {
var userData = body.GetUserData();
if (userData instanceof GameObject) {
var gameObject = userData;
if(updateData[gameObject.uid]) {
var update = updateData[gameObject.uid];
body.SetAwake(true);
body.SetPosition(update.p);
body.SetAngle(update.a);
body.SetLinearVelocity(update.lv);
body.SetAngularVelocity(update.av);
body.SetAngularVelocity(update.av);
if (gameObject instanceof Doll) {
gameObject.setActionState(update.as);
gameObject.lookAt(update.laxy.x, update.laxy.y);
}
}
}
} while (body = body.GetNext());

View file

@ -5,8 +5,8 @@ define([
function (Parent, Exception) {
function GameObject(physicsEngine) {
Parent.call(this, physicsEngine);
function GameObject(physicsEngine, uid) {
Parent.call(this, physicsEngine, uid);
this.createMesh();
this.render();
}

View file

@ -6,8 +6,8 @@ define([
function (Parent, Settings, NotificationCenter) {
function Tile(physicsEngine, options) {
Parent.call(this, physicsEngine, options);
function Tile(physicsEngine, uid, options) {
Parent.call(this, physicsEngine, uid, options);
}
Tile.prototype = Object.create(Parent.prototype);

View file

@ -1,10 +1,11 @@
define([
"Game/Core/Physics/Doll",
"Game/Config/Settings",
"Game/Core/NotificationCenter"
"Game/Core/NotificationCenter",
"Lib/Utilities/Exception"
],
function (Parent, Settings, NotificationCenter) {
function (Parent, Settings, NotificationCenter, Exception) {
function Doll(physicsEngine, playerId) {
this.animationDef = {
@ -20,6 +21,7 @@ function (Parent, Settings, NotificationCenter) {
}
this.animatedMeshes = {};
this.headMesh = null;
Parent.call(this, physicsEngine, playerId);
}
@ -30,6 +32,8 @@ function (Parent, Settings, NotificationCenter) {
if(this.actionState == state) return;
if(!state) throw new Exception("action state is undefined");
if(this.animatedMeshes[this.actionState]) {
NotificationCenter.trigger("view/updateMesh", this.animatedMeshes[this.actionState], { visible: false });
}
@ -41,6 +45,8 @@ function (Parent, Settings, NotificationCenter) {
Doll.prototype.createMesh = function() {
// Body
var padF = function(n) {
if(n<10) return "00" + n;
if(n<100) return "0" + n;
@ -65,6 +71,16 @@ function (Parent, Settings, NotificationCenter) {
NotificationCenter.trigger("view/createAnimatedMesh", texturePaths, callback, { visible: false, pivot: "mb" });
}
// Head
var texturePath = Settings.GRAPHICS_PATH + "Characters/Chuck/head.png";
var callback = function (mesh) {
self.headMesh = mesh;
NotificationCenter.trigger("view/addMesh", mesh);
}
NotificationCenter.trigger("view/createMesh", texturePath, callback, { pivot: "mb" });
}
Doll.prototype.render = function() {
@ -77,11 +93,19 @@ function (Parent, Settings, NotificationCenter) {
}
);
NotificationCenter.trigger("view/updateMesh",
this.headMesh,
{
x: this.body.GetPosition().x * Settings.RATIO,
y: this.body.GetPosition().y * Settings.RATIO - 31
}
)
}
}
Doll.prototype.lookAt = function(x, y) {
var oldLookDirection = this.lookDirection;
Parent.prototype.lookAt.call(this, x, y);
if(oldLookDirection != this.lookDirection) {
@ -94,9 +118,28 @@ function (Parent, Settings, NotificationCenter) {
);
}
}
};
// TODO: implement destroy
var angle = Math.atan2(this.lookAtXY.x, this.lookAtXY.y) / 2 - 0.7855 * this.lookDirection; // 0.7855 = 45°
NotificationCenter.trigger("view/updateMesh",
this.headMesh,
{
xScale: this.lookDirection,
rotation: angle
}
);
}
Doll.prototype.destroy = function () {
for (var key in this.animatedMeshes) {
NotificationCenter.trigger("view/removeMesh", this.animatedMeshes[key]);
}
NotificationCenter.trigger("view/removeMesh", this.headMesh);
Parent.prototype.destroy.call(this);
}
return Doll;

View file

@ -12,9 +12,10 @@ function (DomController, Settings, Exception, NotificationCenter) {
this.canvas = null;
NotificationCenter.on("view/createMesh", this.createMesh, this);
NotificationCenter.on("view/addMesh", this.addMesh, this);
NotificationCenter.on("view/updateMesh", this.updateMesh, this);
NotificationCenter.on("view/createAnimatedMesh", this.createAnimatedMesh, this);
NotificationCenter.on("view/addMesh", this.addMesh, this);
NotificationCenter.on("view/removeMesh", this.removeMesh, this);
NotificationCenter.on("view/updateMesh", this.updateMesh, this);
}
AbstractView.prototype.isWebGlEnabled = function () {
@ -51,18 +52,22 @@ function (DomController, Settings, Exception, NotificationCenter) {
throw new Exception('Abstract Function createMesh not overwritten ');
}
AbstractView.prototype.createAnimatedMesh = function (texturePaths, callback, options) {
throw new Exception('Abstract Function createAnimatedMesh not overwritten ');
}
AbstractView.prototype.addMesh = function(mesh) {
throw new Exception('Abstract Function addMesh not overwritten ');
};
AbstractView.prototype.removeMesh = function(mesh) {
throw new Exception('Abstract Function removeMesh not overwritten ');
};
AbstractView.prototype.updateMesh = function(mesh, options) {
throw new Exception('Abstract Function updateMesh not overwritten ');
};
AbstractView.prototype.createAnimatedMesh = function (texturePaths, callback, options) {
throw new Exception('Abstract Function createAnimatedMesh not overwritten ');
}
AbstractView.prototype.setMe = function(player) {
this.me = player;
};

View file

@ -48,6 +48,10 @@ function (Parent, DomController, PIXI, Settings) {
this.container.addChild(mesh);
};
PixiView.prototype.removeMesh = function(mesh) {
this.container.removeChild(mesh);
};
PixiView.prototype.createMesh = function (texturePath, callback, options) {
var texture = PIXI.Texture.fromImage(texturePath);
@ -84,15 +88,10 @@ function (Parent, DomController, PIXI, Settings) {
if (options.height) mesh.height = options.height;
if (options.visible === true || options.visible === false) mesh.visible = options.visible;
if (options.pivot) {
switch(options.pivot) {
case "mb":
mesh.pivot.x = mesh.width / 2;
mesh.pivot.y = mesh.height;
break;
case "mm":
switch(options.pivot.length) {
default:
mesh.pivot.x = mesh.width / 2;
mesh.pivot.y = mesh.height / 2;
mesh.pivot.y = mesh.height;
break;
}