mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
fixes for animations with head and jump, etc.
This commit is contained in:
parent
142964938c
commit
283a1ef48b
16 changed files with 147 additions and 109 deletions
|
|
@ -66,8 +66,9 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerController.prototype.setXY = function(x, y) {
|
PlayerController.prototype.setXY = function(x, y) {
|
||||||
Parent.prototype.lookAt.call(this, x, y);
|
var options = {x:x, y:y};
|
||||||
NotificationCenter.trigger('sendGameCommand', 'lookAt', x, y); // implement that x and y are received
|
Parent.prototype.lookAt.call(this, options);
|
||||||
|
NotificationCenter.trigger('sendGameCommand', 'lookAt', options);
|
||||||
};
|
};
|
||||||
|
|
||||||
PlayerController.prototype.update = function () {
|
PlayerController.prototype.update = function () {
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,12 @@ define([
|
||||||
"Game/Core/NotificationCenter",
|
"Game/Core/NotificationCenter",
|
||||||
"Lib/Utilities/RequestAnimFrame",
|
"Lib/Utilities/RequestAnimFrame",
|
||||||
"Game/Config/Settings",
|
"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 () {
|
function GameController () {
|
||||||
this.view = ViewManager.createView();
|
this.view = ViewManager.createView();
|
||||||
|
|
@ -85,41 +87,21 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
||||||
|
|
||||||
var body = this.physicsEngine.world.GetBodyList();
|
var body = this.physicsEngine.world.GetBodyList();
|
||||||
do {
|
do {
|
||||||
var bodyName = body.GetUserData();
|
var userData = body.GetUserData();
|
||||||
if(bodyName && updateData[bodyName]) {
|
if (userData instanceof GameObject) {
|
||||||
var update = updateData[bodyName];
|
var gameObject = userData;
|
||||||
|
if(updateData[gameObject.uid]) {
|
||||||
|
var update = updateData[gameObject.uid];
|
||||||
body.SetAwake(true);
|
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 {
|
|
||||||
body.SetPosition(update.p);
|
body.SetPosition(update.p);
|
||||||
body.SetAngle(update.a);
|
body.SetAngle(update.a);
|
||||||
body.SetLinearVelocity(update.lv);
|
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());
|
} while (body = body.GetNext());
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ define([
|
||||||
|
|
||||||
function (Parent, Exception) {
|
function (Parent, Exception) {
|
||||||
|
|
||||||
function GameObject(physicsEngine) {
|
function GameObject(physicsEngine, uid) {
|
||||||
Parent.call(this, physicsEngine);
|
Parent.call(this, physicsEngine, uid);
|
||||||
this.createMesh();
|
this.createMesh();
|
||||||
this.render();
|
this.render();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ define([
|
||||||
|
|
||||||
function (Parent, Settings, NotificationCenter) {
|
function (Parent, Settings, NotificationCenter) {
|
||||||
|
|
||||||
function Tile(physicsEngine, options) {
|
function Tile(physicsEngine, uid, options) {
|
||||||
Parent.call(this, physicsEngine, options);
|
Parent.call(this, physicsEngine, uid, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tile.prototype = Object.create(Parent.prototype);
|
Tile.prototype = Object.create(Parent.prototype);
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
define([
|
define([
|
||||||
"Game/Core/Physics/Doll",
|
"Game/Core/Physics/Doll",
|
||||||
"Game/Config/Settings",
|
"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) {
|
function Doll(physicsEngine, playerId) {
|
||||||
this.animationDef = {
|
this.animationDef = {
|
||||||
|
|
@ -20,6 +21,7 @@ function (Parent, Settings, NotificationCenter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.animatedMeshes = {};
|
this.animatedMeshes = {};
|
||||||
|
this.headMesh = null;
|
||||||
|
|
||||||
Parent.call(this, physicsEngine, playerId);
|
Parent.call(this, physicsEngine, playerId);
|
||||||
}
|
}
|
||||||
|
|
@ -30,6 +32,8 @@ function (Parent, Settings, NotificationCenter) {
|
||||||
|
|
||||||
if(this.actionState == state) return;
|
if(this.actionState == state) return;
|
||||||
|
|
||||||
|
if(!state) throw new Exception("action state is undefined");
|
||||||
|
|
||||||
if(this.animatedMeshes[this.actionState]) {
|
if(this.animatedMeshes[this.actionState]) {
|
||||||
NotificationCenter.trigger("view/updateMesh", this.animatedMeshes[this.actionState], { visible: false });
|
NotificationCenter.trigger("view/updateMesh", this.animatedMeshes[this.actionState], { visible: false });
|
||||||
}
|
}
|
||||||
|
|
@ -41,6 +45,8 @@ function (Parent, Settings, NotificationCenter) {
|
||||||
|
|
||||||
Doll.prototype.createMesh = function() {
|
Doll.prototype.createMesh = function() {
|
||||||
|
|
||||||
|
// Body
|
||||||
|
|
||||||
var padF = function(n) {
|
var padF = function(n) {
|
||||||
if(n<10) return "00" + n;
|
if(n<10) return "00" + n;
|
||||||
if(n<100) return "0" + 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" });
|
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() {
|
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) {
|
Doll.prototype.lookAt = function(x, y) {
|
||||||
var oldLookDirection = this.lookDirection;
|
var oldLookDirection = this.lookDirection;
|
||||||
|
|
||||||
Parent.prototype.lookAt.call(this, x, y);
|
Parent.prototype.lookAt.call(this, x, y);
|
||||||
|
|
||||||
if(oldLookDirection != this.lookDirection) {
|
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;
|
return Doll;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,10 @@ function (DomController, Settings, Exception, NotificationCenter) {
|
||||||
this.canvas = null;
|
this.canvas = null;
|
||||||
|
|
||||||
NotificationCenter.on("view/createMesh", this.createMesh, this);
|
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/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 () {
|
AbstractView.prototype.isWebGlEnabled = function () {
|
||||||
|
|
@ -51,18 +52,22 @@ function (DomController, Settings, Exception, NotificationCenter) {
|
||||||
throw new Exception('Abstract Function createMesh not overwritten ');
|
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) {
|
AbstractView.prototype.addMesh = function(mesh) {
|
||||||
throw new Exception('Abstract Function addMesh not overwritten ');
|
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) {
|
AbstractView.prototype.updateMesh = function(mesh, options) {
|
||||||
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,6 +48,10 @@ function (Parent, DomController, PIXI, Settings) {
|
||||||
this.container.addChild(mesh);
|
this.container.addChild(mesh);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PixiView.prototype.removeMesh = function(mesh) {
|
||||||
|
this.container.removeChild(mesh);
|
||||||
|
};
|
||||||
|
|
||||||
PixiView.prototype.createMesh = function (texturePath, callback, options) {
|
PixiView.prototype.createMesh = function (texturePath, callback, options) {
|
||||||
|
|
||||||
var texture = PIXI.Texture.fromImage(texturePath);
|
var texture = PIXI.Texture.fromImage(texturePath);
|
||||||
|
|
@ -84,15 +88,10 @@ function (Parent, DomController, PIXI, Settings) {
|
||||||
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.visible === true || options.visible === false) mesh.visible = options.visible;
|
||||||
if (options.pivot) {
|
if (options.pivot) {
|
||||||
switch(options.pivot) {
|
switch(options.pivot.length) {
|
||||||
case "mb":
|
|
||||||
mesh.pivot.x = mesh.width / 2;
|
|
||||||
mesh.pivot.y = mesh.height;
|
|
||||||
break;
|
|
||||||
case "mm":
|
|
||||||
default:
|
default:
|
||||||
mesh.pivot.x = mesh.width / 2;
|
mesh.pivot.x = mesh.width / 2;
|
||||||
mesh.pivot.y = mesh.height / 2;
|
mesh.pivot.y = mesh.height;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ define(function () {
|
||||||
this.player.jump();
|
this.player.jump();
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerController.prototype.lookAt = function (x, y) {
|
PlayerController.prototype.lookAt = function (options) {
|
||||||
this.player.lookAt(x, y);
|
if(options) this.player.lookAt(options.x, options.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerController.prototype.update = function () {
|
PlayerController.prototype.update = function () {
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,11 @@ define([
|
||||||
|
|
||||||
function (Box2D, Exception) {
|
function (Box2D, Exception) {
|
||||||
|
|
||||||
function GameObject(physicsEngine) {
|
function GameObject(physicsEngine, uid) {
|
||||||
|
this.uid = uid;
|
||||||
|
|
||||||
var def = this.getBodyDef();
|
var def = this.getBodyDef();
|
||||||
|
def.userData = this;
|
||||||
this.body = physicsEngine.getWorld().CreateBody(def);
|
this.body = physicsEngine.getWorld().CreateBody(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@ define([
|
||||||
|
|
||||||
function (Parent, Box2D, Settings, CollisionDetector) {
|
function (Parent, Box2D, Settings, CollisionDetector) {
|
||||||
|
|
||||||
function Tile(physicsEngine, options) {
|
function Tile(physicsEngine, uid, options) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
Parent.call(this, physicsEngine);
|
Parent.call(this, physicsEngine, uid);
|
||||||
this.createPhysicTile(this.options);
|
this.createPhysicTile(this.options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ define([
|
||||||
var tiles = this.levelObject.tiles;
|
var tiles = this.levelObject.tiles;
|
||||||
|
|
||||||
for (var i = 0; i < tiles.length; i++) {
|
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]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,17 +7,16 @@ define([
|
||||||
|
|
||||||
function (Parent, Box2D, Settings, CollisionDetector) {
|
function (Parent, Box2D, Settings, CollisionDetector) {
|
||||||
|
|
||||||
function Doll (physicsEngine, playerId) {
|
function Doll (physicsEngine, uid) {
|
||||||
|
|
||||||
this.playerId = playerId;
|
Parent.call(this, physicsEngine, uid);
|
||||||
|
|
||||||
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.actionState = null;
|
||||||
|
this.lookAtXY = {x:0, y:0};
|
||||||
|
|
||||||
this.createFixtures();
|
this.createFixtures();
|
||||||
this.body.SetActive(false);
|
this.body.SetActive(false);
|
||||||
|
|
@ -32,8 +31,6 @@ function (Parent, Box2D, Settings, CollisionDetector) {
|
||||||
bodyDef.fixedRotation = true;
|
bodyDef.fixedRotation = true;
|
||||||
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
|
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
|
||||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
||||||
bodyDef.userData = CollisionDetector.IDENTIFIER.PLAYER + '-' + this.playerId;
|
|
||||||
|
|
||||||
return bodyDef;
|
return bodyDef;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -83,6 +80,10 @@ function (Parent, Box2D, Settings, CollisionDetector) {
|
||||||
this.actionState = state;
|
this.actionState = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Doll.prototype.getActionState = function() {
|
||||||
|
return this.actionState;
|
||||||
|
}
|
||||||
|
|
||||||
Doll.prototype.isWalking = function() {
|
Doll.prototype.isWalking = function() {
|
||||||
return ["walk", "walkback", "run"].indexOf(this.actionState) >= 0;
|
return ["walk", "walkback", "run"].indexOf(this.actionState) >= 0;
|
||||||
}
|
}
|
||||||
|
|
@ -141,6 +142,7 @@ function (Parent, Box2D, Settings, CollisionDetector) {
|
||||||
Doll.prototype.stop = function () {
|
Doll.prototype.stop = function () {
|
||||||
this.moveDirection = 0;
|
this.moveDirection = 0;
|
||||||
this.setFriction(Settings.PLAYER_FRICTION);
|
this.setFriction(Settings.PLAYER_FRICTION);
|
||||||
|
if(this.isStanding()) this.setActionState("stand");
|
||||||
}
|
}
|
||||||
|
|
||||||
Doll.prototype.jump = function () {
|
Doll.prototype.jump = function () {
|
||||||
|
|
@ -157,12 +159,13 @@ function (Parent, Box2D, Settings, CollisionDetector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Doll.prototype.destroy = function () {
|
Doll.prototype.destroy = function () {
|
||||||
this.body.GetWorld().DestroyBody(this.body);
|
Parent.prototype.destroy.call(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Doll.prototype.setStanding = function (isStanding) {
|
Doll.prototype.setStanding = function (isStanding) {
|
||||||
|
if (this.standing == isStanding) return;
|
||||||
this.standing = isStanding;
|
this.standing = isStanding;
|
||||||
this.setActionState("stand");
|
if(isStanding) this.setActionState("stand");
|
||||||
}
|
}
|
||||||
|
|
||||||
Doll.prototype.isStanding = function () {
|
Doll.prototype.isStanding = function () {
|
||||||
|
|
@ -170,33 +173,30 @@ function (Parent, Box2D, Settings, CollisionDetector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Doll.prototype.lookAt = function(x, y) {
|
Doll.prototype.lookAt = function(x, y) {
|
||||||
var lastLookDirection = this.lookDirection;
|
this.body.SetAwake(true);
|
||||||
/*
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(x < 0) {
|
if(x < 0) {
|
||||||
this.lookDirection = -1;
|
this.lookDirection = -1;
|
||||||
} else {
|
} else {
|
||||||
this.lookDirection = 1;
|
this.lookDirection = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.lookAtXY.x = x;
|
||||||
|
this.lookAtXY.y = y;
|
||||||
};
|
};
|
||||||
|
|
||||||
Doll.prototype.onFootSensorDetection = function(isColliding) {
|
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);
|
this.setStanding(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Doll.prototype.update = function() {
|
Doll.prototype.update = function() {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ function (Doll, Settings) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Player.prototype.spawn = function (x, y) {
|
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.doll.spawn(x, y);
|
||||||
this.isSpawned = true;
|
this.isSpawned = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,12 @@ define([
|
||||||
"Game/Server/Control/PlayerController",
|
"Game/Server/Control/PlayerController",
|
||||||
"Lib/Utilities/RequestAnimFrame",
|
"Lib/Utilities/RequestAnimFrame",
|
||||||
"Game/Core/NotificationCenter",
|
"Game/Core/NotificationCenter",
|
||||||
"Game/Server/Player"
|
"Game/Server/Player",
|
||||||
|
"Game/Server/GameObjects/GameObject",
|
||||||
|
"Game/Server/Physics/Doll"
|
||||||
],
|
],
|
||||||
|
|
||||||
function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, NotificationCenter, Player) {
|
function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, NotificationCenter, Player, GameObject, Doll) {
|
||||||
|
|
||||||
function GameController (channel) {
|
function GameController (channel) {
|
||||||
Parent.call(this, new PhysicsEngine());
|
Parent.call(this, new PhysicsEngine());
|
||||||
|
|
@ -74,17 +76,28 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
||||||
|
|
||||||
var body = this.physicsEngine.world.GetBodyList();
|
var body = this.physicsEngine.world.GetBodyList();
|
||||||
do {
|
do {
|
||||||
|
if(body.IsAwake()) {
|
||||||
var userData = body.GetUserData();
|
var userData = body.GetUserData();
|
||||||
|
|
||||||
if(userData && body.IsAwake()) {
|
if (userData instanceof GameObject) {
|
||||||
update[userData] = {
|
var gameObject = userData;
|
||||||
|
|
||||||
|
update[gameObject.uid] = {
|
||||||
p: body.GetPosition(),
|
p: body.GetPosition(),
|
||||||
a: body.GetAngle(),
|
a: body.GetAngle(),
|
||||||
lv: body.GetLinearVelocity(),
|
lv: body.GetLinearVelocity(),
|
||||||
av: body.GetAngularVelocity()
|
av: body.GetAngularVelocity()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if(gameObject instanceof Doll) {
|
||||||
|
update[gameObject.uid].as = gameObject.getActionState();
|
||||||
|
update[gameObject.uid].laxy = gameObject.lookAtXY;
|
||||||
|
}
|
||||||
|
|
||||||
isUpdateNeeded = true;
|
isUpdateNeeded = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} while (body = body.GetNext());
|
} while (body = body.GetNext());
|
||||||
|
|
||||||
if(isUpdateNeeded) {
|
if(isUpdateNeeded) {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
define([
|
|
||||||
"Game/Core/GameObject"
|
|
||||||
],
|
|
||||||
|
|
||||||
function(Parent) {
|
|
||||||
|
|
||||||
return Parent;
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
<title>Chuck</title>
|
<title>Chuck</title>
|
||||||
<style>
|
<style>
|
||||||
html, body {
|
html, body {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue