fixed first animations

This commit is contained in:
jeena 2013-12-24 04:46:54 +01:00
parent caa3945869
commit 142964938c
8 changed files with 159 additions and 53 deletions

View file

@ -16,7 +16,7 @@ function (Parent, Settings, NotificationCenter) {
var self = this;
var material = "Stones";
var imgPath = Settings.GRAPHICS_PATH
var texturePath = Settings.GRAPHICS_PATH
+ Settings.GRAPHICS_SUBPATH_TILES
+ material + '/'
+ this.options.s + ''
@ -28,12 +28,13 @@ function (Parent, Settings, NotificationCenter) {
}
NotificationCenter.trigger("view/createMesh",
Settings.TILE_SIZE,
Settings.TILE_SIZE,
0,
0,
imgPath,
callback
texturePath,
callback,
{
width: Settings.TILE_SIZE,
height: Settings.TILE_SIZE,
pivot: "mb"
}
);
};

View file

@ -6,46 +6,97 @@ define([
function (Parent, Settings, NotificationCenter) {
function Doll(physicsEngine, playerId) {
Parent.call(this, physicsEngine, playerId);
this.height = 36;
function Doll(physicsEngine, playerId) {
this.animationDef = {
"stand": [1,1],
"walk": [2,28],
"walkback": [29,55],
//"jump": [56,80],
"jump": [81,91],
"fall": [81,91],
"duck": [92,97],
"standup": [98,103],
"run": [104,126]
}
this.animatedMeshes = {};
Parent.call(this, physicsEngine, playerId);
}
Doll.prototype = Object.create(Parent.prototype);
Doll.prototype.setActionState = function(state) {
if(this.actionState == state) return;
if(this.animatedMeshes[this.actionState]) {
NotificationCenter.trigger("view/updateMesh", this.animatedMeshes[this.actionState], { visible: false });
}
Parent.prototype.setActionState.call(this, state);
NotificationCenter.trigger("view/updateMesh", this.animatedMeshes[this.actionState], { visible: true });
}
Doll.prototype.createMesh = function() {
var padF = function(n) {
if(n<10) return "00" + n;
if(n<100) return "0" + n;
return n;
}
var self = this;
var imgPath = Settings.GRAPHICS_PATH
+ Settings.GRAPHICS_SUBPATH_CHARACTERS
+ 'Chuck' + '/'
+ 'chuck.png';
for (var key in this.animationDef) {
var start = this.animationDef[key][0];
var end = this.animationDef[key][1];
var callback = function(mesh) {
self.mesh = mesh;
NotificationCenter.trigger("view/addMesh", mesh);
var texturePaths = [];
for (var i = start; i <= end; i++) {
texturePaths.push(Settings.GRAPHICS_PATH + "Animation/WithArms/ChuckAnimations0" + padF(i) + ".png");
}
var callback = function(mesh) {
self.animatedMeshes[key] = mesh;
NotificationCenter.trigger("view/addMesh", mesh);
};
NotificationCenter.trigger("view/createAnimatedMesh", texturePaths, callback, { visible: false, pivot: "mb" });
}
NotificationCenter.trigger("view/createMesh",
10,
36,
0,
0,
imgPath,
callback
);
};
}
Doll.prototype.render = function() {
if(this.actionState) {
NotificationCenter.trigger("view/updateMesh",
this.animatedMeshes[this.actionState],
{
x: this.body.GetPosition().x * Settings.RATIO,
y: this.body.GetPosition().y * Settings.RATIO
}
);
NotificationCenter.trigger("view/updateMesh",
this.mesh,
{
x: this.body.GetPosition().x * Settings.RATIO + 4,
y: (this.body.GetPosition().y * Settings.RATIO) - 29
}
);
}
}
Doll.prototype.lookAt = function(x, y) {
var oldLookDirection = this.lookDirection;
Parent.prototype.lookAt.call(this, x, y);
if(oldLookDirection != this.lookDirection) {
for(var key in this.animatedMeshes) {
NotificationCenter.trigger("view/updateMesh",
this.animatedMeshes[key],
{
xScale: this.lookDirection
}
);
}
}
};
// TODO: implement destroy
return Doll;

View file

@ -34,7 +34,7 @@ function (Parent, Settings, DomController, Box2D) {
| Box2D.Dynamics.b2DebugDraw.e_jointBit
//| Box2D.Dynamics.b2DebugDraw.e_coreShapeBit
//| Box2D.Dynamics.b2DebugDraw.e_aabbBit
//| Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit
| Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit
//| Box2D.Dynamics.b2DebugDraw.e_obbBit
//| Box2D.Dynamics.b2DebugDraw.e_pairBit
);

View file

@ -14,6 +14,7 @@ function (DomController, Settings, Exception, NotificationCenter) {
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);
}
AbstractView.prototype.isWebGlEnabled = function () {
@ -46,7 +47,7 @@ function (DomController, Settings, Exception, NotificationCenter) {
throw new Exception('Abstract Function render not overwritten ');
}
AbstractView.prototype.createMesh = function (width, height, x, y, imgPath, callback) {
AbstractView.prototype.createMesh = function (texturePath, callback, options) {
throw new Exception('Abstract Function createMesh not overwritten ');
}
@ -58,6 +59,10 @@ function (DomController, Settings, Exception, NotificationCenter) {
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,15 +48,28 @@ function (Parent, DomController, PIXI, Settings) {
this.container.addChild(mesh);
};
PixiView.prototype.createMesh = function (width, height, x, y, imgPath, callback) {
PixiView.prototype.createMesh = function (texturePath, callback, options) {
var texture = PIXI.Texture.fromImage(imgPath);
var texture = PIXI.Texture.fromImage(texturePath);
var mesh = new PIXI.Sprite(texture);
mesh.width = width;
mesh.height = height;
mesh.position.x = x;
mesh.position.y = y;
if(options) this.updateMesh(mesh, options);
callback(mesh);
}
PixiView.prototype.createAnimatedMesh = function (texturePaths, callback, options) {
var textures = [];
for (var i = 0; i < texturePaths.length; i++) {
var texture = PIXI.Texture.fromImage(texturePaths[i]);
textures.push(texture);
}
var mesh = new PIXI.MovieClip(textures);
if(options) this.updateMesh(mesh, options);
mesh.animationSpeed = 0.5;
mesh.play();
callback(mesh);
}
@ -69,7 +82,22 @@ function (Parent, DomController, PIXI, Settings) {
if (options.yScale) mesh.scale.y = options.yScale;
if (options.width) mesh.width = options.width;
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":
default:
mesh.pivot.x = mesh.width / 2;
mesh.pivot.y = mesh.height / 2;
break;
}
};
}
PixiView.prototype.initCamera = function () {
this.container = new PIXI.DisplayObjectContainer();

View file

@ -47,7 +47,7 @@ define({
IS_BROWSER_ENVIRONMENT: typeof window !== 'undefined',
USE_WEGBL: true,
DEBUG_MODE: 1,
DEBUG_MODE: 0,
// NETWORKING
WORLD_UPDATE_BROADCAST_INTERVAL: 70,

View file

@ -9,14 +9,15 @@ function (Parent, Box2D, Settings, CollisionDetector) {
function Doll (physicsEngine, playerId) {
Parent.call(this, physicsEngine);
this.playerId = playerId;
Parent.call(this, physicsEngine);
this.standing = false;
this.moveDirection = 0;
this.lookDirection = 0;
this.legs;
this.actionState = null;
this.createFixtures();
this.body.SetActive(false);
@ -45,20 +46,20 @@ function (Parent, Box2D, Settings, CollisionDetector) {
var headShape = new Box2D.Collision.Shapes.b2CircleShape();
headShape.SetRadius(5 / Settings.RATIO);
headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -37 / Settings.RATIO));
headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -35 / Settings.RATIO));
fixtureDef.shape = headShape;
fixtureDef.isSensor = false;
this.body.CreateFixture(fixtureDef);
var bodyShape = new Box2D.Collision.Shapes.b2PolygonShape();
bodyShape.SetAsOrientedBox(5 / Settings.RATIO, 16 / Settings.RATIO, new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -21 / Settings.RATIO));
bodyShape.SetAsOrientedBox(5 / Settings.RATIO, 16 / Settings.RATIO, new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -19 / Settings.RATIO));
fixtureDef.shape = bodyShape;
fixtureDef.isSensor = false;
this.body.CreateFixture(fixtureDef);
var legsShape = new Box2D.Collision.Shapes.b2CircleShape();
legsShape.SetRadius(5 / Settings.RATIO);
legsShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -5 / Settings.RATIO));
legsShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -3 / Settings.RATIO));
fixtureDef.shape = legsShape;
fixtureDef.friction = Settings.PLAYER_FRICTION;
fixtureDef.isSensor = false;
@ -67,7 +68,7 @@ function (Parent, Box2D, Settings, CollisionDetector) {
var feetShape = new Box2D.Collision.Shapes.b2CircleShape();
feetShape.SetRadius(4 / Settings.RATIO);
feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, 0 / Settings.RATIO));
feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, 2 / Settings.RATIO));
fixtureDef.shape = feetShape;
fixtureDef.isSensor = true;
@ -78,9 +79,18 @@ function (Parent, Box2D, Settings, CollisionDetector) {
this.body.CreateFixture(fixtureDef);
}
Doll.prototype.setActionState = function(state) {
this.actionState = state;
}
Doll.prototype.isWalking = function() {
return ["walk", "walkback", "run"].indexOf(this.actionState) >= 0;
}
Doll.prototype.spawn = function (x, y) {
this.body.SetPosition(new Box2D.Common.Math.b2Vec2(x / Settings.RATIO, y / Settings.RATIO));
this.body.SetActive(true);
this.setActionState("fall");
}
Doll.prototype.getPosition = function() {
@ -118,6 +128,14 @@ function (Parent, Box2D, Settings, CollisionDetector) {
this.body.SetAwake(true);
var vector = new Box2D.Common.Math.b2Vec2(speed * direction, this.body.GetLinearVelocity().y);
this.body.SetLinearVelocity(vector);
if(this.isStanding()) {
if(this.moveDirection == this.lookDirection) {
this.setActionState("run");
} else {
this.setActionState("walkback");
}
}
}
Doll.prototype.stop = function () {
@ -133,6 +151,8 @@ function (Parent, Box2D, Settings, CollisionDetector) {
this.body.ApplyImpulse(vector, this.body.GetPosition());
this.setStanding(false);
this.setActionState("jump");
}
}
@ -142,6 +162,7 @@ function (Parent, Box2D, Settings, CollisionDetector) {
Doll.prototype.setStanding = function (isStanding) {
this.standing = isStanding;
this.setActionState("stand");
}
Doll.prototype.isStanding = function () {
@ -180,7 +201,7 @@ function (Parent, Box2D, Settings, CollisionDetector) {
Doll.prototype.update = function() {
if (this.body.GetLinearVelocity().x == 0) {
if (this.body.GetLinearVelocity().x == 0 && this.isWalking()) {
this.stop();
}

View file

@ -3,13 +3,13 @@ define([
"Game/Config/Settings"
],
function (Doll, Settings) {
function Player (id, physicsEngine) {
this.physicsEngine = physicsEngine;
this.playerController = null;
this.doll;
this.id = id;
this.isSpawned = false;
}