mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
fixed first animations
This commit is contained in:
parent
caa3945869
commit
142964938c
8 changed files with 159 additions and 53 deletions
|
|
@ -16,7 +16,7 @@ function (Parent, Settings, NotificationCenter) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var material = "Stones";
|
var material = "Stones";
|
||||||
var imgPath = Settings.GRAPHICS_PATH
|
var texturePath = Settings.GRAPHICS_PATH
|
||||||
+ Settings.GRAPHICS_SUBPATH_TILES
|
+ Settings.GRAPHICS_SUBPATH_TILES
|
||||||
+ material + '/'
|
+ material + '/'
|
||||||
+ this.options.s + ''
|
+ this.options.s + ''
|
||||||
|
|
@ -28,12 +28,13 @@ function (Parent, Settings, NotificationCenter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationCenter.trigger("view/createMesh",
|
NotificationCenter.trigger("view/createMesh",
|
||||||
Settings.TILE_SIZE,
|
texturePath,
|
||||||
Settings.TILE_SIZE,
|
callback,
|
||||||
0,
|
{
|
||||||
0,
|
width: Settings.TILE_SIZE,
|
||||||
imgPath,
|
height: Settings.TILE_SIZE,
|
||||||
callback
|
pivot: "mb"
|
||||||
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,45 +7,96 @@ define([
|
||||||
function (Parent, Settings, NotificationCenter) {
|
function (Parent, Settings, NotificationCenter) {
|
||||||
|
|
||||||
function Doll(physicsEngine, playerId) {
|
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);
|
Parent.call(this, physicsEngine, playerId);
|
||||||
this.height = 36;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Doll.prototype = Object.create(Parent.prototype);
|
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() {
|
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 self = this;
|
||||||
|
|
||||||
var imgPath = Settings.GRAPHICS_PATH
|
for (var key in this.animationDef) {
|
||||||
+ Settings.GRAPHICS_SUBPATH_CHARACTERS
|
var start = this.animationDef[key][0];
|
||||||
+ 'Chuck' + '/'
|
var end = this.animationDef[key][1];
|
||||||
+ 'chuck.png';
|
|
||||||
|
var texturePaths = [];
|
||||||
|
for (var i = start; i <= end; i++) {
|
||||||
|
texturePaths.push(Settings.GRAPHICS_PATH + "Animation/WithArms/ChuckAnimations0" + padF(i) + ".png");
|
||||||
|
}
|
||||||
|
|
||||||
var callback = function(mesh) {
|
var callback = function(mesh) {
|
||||||
self.mesh = mesh;
|
self.animatedMeshes[key] = mesh;
|
||||||
NotificationCenter.trigger("view/addMesh", mesh);
|
NotificationCenter.trigger("view/addMesh", mesh);
|
||||||
}
|
|
||||||
|
|
||||||
NotificationCenter.trigger("view/createMesh",
|
|
||||||
10,
|
|
||||||
36,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
imgPath,
|
|
||||||
callback
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Doll.prototype.render = function() {
|
NotificationCenter.trigger("view/createAnimatedMesh", texturePaths, callback, { visible: false, pivot: "mb" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Doll.prototype.render = function() {
|
||||||
|
if(this.actionState) {
|
||||||
NotificationCenter.trigger("view/updateMesh",
|
NotificationCenter.trigger("view/updateMesh",
|
||||||
this.mesh,
|
this.animatedMeshes[this.actionState],
|
||||||
{
|
{
|
||||||
x: this.body.GetPosition().x * Settings.RATIO + 4,
|
x: this.body.GetPosition().x * Settings.RATIO,
|
||||||
y: (this.body.GetPosition().y * Settings.RATIO) - 29
|
y: this.body.GetPosition().y * Settings.RATIO
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
return Doll;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ function (Parent, Settings, DomController, Box2D) {
|
||||||
| Box2D.Dynamics.b2DebugDraw.e_jointBit
|
| Box2D.Dynamics.b2DebugDraw.e_jointBit
|
||||||
//| Box2D.Dynamics.b2DebugDraw.e_coreShapeBit
|
//| Box2D.Dynamics.b2DebugDraw.e_coreShapeBit
|
||||||
//| Box2D.Dynamics.b2DebugDraw.e_aabbBit
|
//| Box2D.Dynamics.b2DebugDraw.e_aabbBit
|
||||||
//| Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit
|
| Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit
|
||||||
//| Box2D.Dynamics.b2DebugDraw.e_obbBit
|
//| Box2D.Dynamics.b2DebugDraw.e_obbBit
|
||||||
//| Box2D.Dynamics.b2DebugDraw.e_pairBit
|
//| Box2D.Dynamics.b2DebugDraw.e_pairBit
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ function (DomController, Settings, Exception, NotificationCenter) {
|
||||||
NotificationCenter.on("view/createMesh", this.createMesh, this);
|
NotificationCenter.on("view/createMesh", this.createMesh, this);
|
||||||
NotificationCenter.on("view/addMesh", this.addMesh, this);
|
NotificationCenter.on("view/addMesh", this.addMesh, this);
|
||||||
NotificationCenter.on("view/updateMesh", this.updateMesh, this);
|
NotificationCenter.on("view/updateMesh", this.updateMesh, this);
|
||||||
|
NotificationCenter.on("view/createAnimatedMesh", this.createAnimatedMesh, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractView.prototype.isWebGlEnabled = function () {
|
AbstractView.prototype.isWebGlEnabled = function () {
|
||||||
|
|
@ -46,7 +47,7 @@ function (DomController, Settings, Exception, NotificationCenter) {
|
||||||
throw new Exception('Abstract Function render not overwritten ');
|
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 ');
|
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 ');
|
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) {
|
AbstractView.prototype.setMe = function(player) {
|
||||||
this.me = player;
|
this.me = player;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -48,15 +48,28 @@ function (Parent, DomController, PIXI, Settings) {
|
||||||
this.container.addChild(mesh);
|
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);
|
var mesh = new PIXI.Sprite(texture);
|
||||||
mesh.width = width;
|
if(options) this.updateMesh(mesh, options);
|
||||||
mesh.height = height;
|
|
||||||
mesh.position.x = x;
|
callback(mesh);
|
||||||
mesh.position.y = y;
|
}
|
||||||
|
|
||||||
|
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);
|
callback(mesh);
|
||||||
}
|
}
|
||||||
|
|
@ -69,7 +82,22 @@ function (Parent, DomController, PIXI, Settings) {
|
||||||
if (options.yScale) mesh.scale.y = options.yScale;
|
if (options.yScale) mesh.scale.y = options.yScale;
|
||||||
if (options.width) mesh.width = options.width;
|
if (options.width) mesh.width = options.width;
|
||||||
if (options.height) mesh.height = options.height;
|
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 () {
|
PixiView.prototype.initCamera = function () {
|
||||||
this.container = new PIXI.DisplayObjectContainer();
|
this.container = new PIXI.DisplayObjectContainer();
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ define({
|
||||||
IS_BROWSER_ENVIRONMENT: typeof window !== 'undefined',
|
IS_BROWSER_ENVIRONMENT: typeof window !== 'undefined',
|
||||||
USE_WEGBL: true,
|
USE_WEGBL: true,
|
||||||
|
|
||||||
DEBUG_MODE: 1,
|
DEBUG_MODE: 0,
|
||||||
|
|
||||||
// NETWORKING
|
// NETWORKING
|
||||||
WORLD_UPDATE_BROADCAST_INTERVAL: 70,
|
WORLD_UPDATE_BROADCAST_INTERVAL: 70,
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,15 @@ function (Parent, Box2D, Settings, CollisionDetector) {
|
||||||
|
|
||||||
function Doll (physicsEngine, playerId) {
|
function Doll (physicsEngine, playerId) {
|
||||||
|
|
||||||
Parent.call(this, physicsEngine);
|
|
||||||
|
|
||||||
this.playerId = playerId;
|
this.playerId = playerId;
|
||||||
|
|
||||||
|
Parent.call(this, physicsEngine);
|
||||||
|
|
||||||
this.standing = false;
|
this.standing = false;
|
||||||
this.moveDirection = 0;
|
this.moveDirection = 0;
|
||||||
this.lookDirection = 0;
|
this.lookDirection = 0;
|
||||||
this.legs;
|
this.legs;
|
||||||
|
this.actionState = null;
|
||||||
|
|
||||||
this.createFixtures();
|
this.createFixtures();
|
||||||
this.body.SetActive(false);
|
this.body.SetActive(false);
|
||||||
|
|
@ -45,20 +46,20 @@ function (Parent, Box2D, Settings, CollisionDetector) {
|
||||||
|
|
||||||
var headShape = new Box2D.Collision.Shapes.b2CircleShape();
|
var headShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||||
headShape.SetRadius(5 / Settings.RATIO);
|
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.shape = headShape;
|
||||||
fixtureDef.isSensor = false;
|
fixtureDef.isSensor = false;
|
||||||
this.body.CreateFixture(fixtureDef);
|
this.body.CreateFixture(fixtureDef);
|
||||||
|
|
||||||
var bodyShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
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.shape = bodyShape;
|
||||||
fixtureDef.isSensor = false;
|
fixtureDef.isSensor = false;
|
||||||
this.body.CreateFixture(fixtureDef);
|
this.body.CreateFixture(fixtureDef);
|
||||||
|
|
||||||
var legsShape = new Box2D.Collision.Shapes.b2CircleShape();
|
var legsShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||||
legsShape.SetRadius(5 / Settings.RATIO);
|
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.shape = legsShape;
|
||||||
fixtureDef.friction = Settings.PLAYER_FRICTION;
|
fixtureDef.friction = Settings.PLAYER_FRICTION;
|
||||||
fixtureDef.isSensor = false;
|
fixtureDef.isSensor = false;
|
||||||
|
|
@ -67,7 +68,7 @@ function (Parent, Box2D, Settings, CollisionDetector) {
|
||||||
|
|
||||||
var feetShape = new Box2D.Collision.Shapes.b2CircleShape();
|
var feetShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||||
feetShape.SetRadius(4 / Settings.RATIO);
|
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.shape = feetShape;
|
||||||
fixtureDef.isSensor = true;
|
fixtureDef.isSensor = true;
|
||||||
|
|
||||||
|
|
@ -78,9 +79,18 @@ function (Parent, Box2D, Settings, CollisionDetector) {
|
||||||
this.body.CreateFixture(fixtureDef);
|
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) {
|
Doll.prototype.spawn = function (x, y) {
|
||||||
this.body.SetPosition(new Box2D.Common.Math.b2Vec2(x / Settings.RATIO, y / Settings.RATIO));
|
this.body.SetPosition(new Box2D.Common.Math.b2Vec2(x / Settings.RATIO, y / Settings.RATIO));
|
||||||
this.body.SetActive(true);
|
this.body.SetActive(true);
|
||||||
|
this.setActionState("fall");
|
||||||
}
|
}
|
||||||
|
|
||||||
Doll.prototype.getPosition = function() {
|
Doll.prototype.getPosition = function() {
|
||||||
|
|
@ -118,6 +128,14 @@ function (Parent, Box2D, Settings, CollisionDetector) {
|
||||||
this.body.SetAwake(true);
|
this.body.SetAwake(true);
|
||||||
var vector = new Box2D.Common.Math.b2Vec2(speed * direction, this.body.GetLinearVelocity().y);
|
var vector = new Box2D.Common.Math.b2Vec2(speed * direction, this.body.GetLinearVelocity().y);
|
||||||
this.body.SetLinearVelocity(vector);
|
this.body.SetLinearVelocity(vector);
|
||||||
|
|
||||||
|
if(this.isStanding()) {
|
||||||
|
if(this.moveDirection == this.lookDirection) {
|
||||||
|
this.setActionState("run");
|
||||||
|
} else {
|
||||||
|
this.setActionState("walkback");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Doll.prototype.stop = function () {
|
Doll.prototype.stop = function () {
|
||||||
|
|
@ -133,6 +151,8 @@ function (Parent, Box2D, Settings, CollisionDetector) {
|
||||||
this.body.ApplyImpulse(vector, this.body.GetPosition());
|
this.body.ApplyImpulse(vector, this.body.GetPosition());
|
||||||
|
|
||||||
this.setStanding(false);
|
this.setStanding(false);
|
||||||
|
|
||||||
|
this.setActionState("jump");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,6 +162,7 @@ function (Parent, Box2D, Settings, CollisionDetector) {
|
||||||
|
|
||||||
Doll.prototype.setStanding = function (isStanding) {
|
Doll.prototype.setStanding = function (isStanding) {
|
||||||
this.standing = isStanding;
|
this.standing = isStanding;
|
||||||
|
this.setActionState("stand");
|
||||||
}
|
}
|
||||||
|
|
||||||
Doll.prototype.isStanding = function () {
|
Doll.prototype.isStanding = function () {
|
||||||
|
|
@ -180,7 +201,7 @@ function (Parent, Box2D, Settings, CollisionDetector) {
|
||||||
|
|
||||||
Doll.prototype.update = function() {
|
Doll.prototype.update = function() {
|
||||||
|
|
||||||
if (this.body.GetLinearVelocity().x == 0) {
|
if (this.body.GetLinearVelocity().x == 0 && this.isWalking()) {
|
||||||
this.stop();
|
this.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@ define([
|
||||||
"Game/Config/Settings"
|
"Game/Config/Settings"
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
||||||
function (Doll, Settings) {
|
function (Doll, Settings) {
|
||||||
|
|
||||||
function Player (id, physicsEngine) {
|
function Player (id, physicsEngine) {
|
||||||
this.physicsEngine = physicsEngine;
|
this.physicsEngine = physicsEngine;
|
||||||
this.playerController = null;
|
this.playerController = null;
|
||||||
this.doll;
|
this.doll;
|
||||||
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.isSpawned = false;
|
this.isSpawned = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue