mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
fixed problems with first world update
This commit is contained in:
parent
283a1ef48b
commit
93e8133c89
13 changed files with 353 additions and 166 deletions
|
|
@ -36,25 +36,6 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
|||
document.body.appendChild(this.stats.domElement);
|
||||
};
|
||||
|
||||
GameController.prototype.makeMouseJoint = function(p) {
|
||||
var ground = this.physicsEngine.getGround();
|
||||
var body = this.me.getBody();
|
||||
|
||||
var def = new Box2D.Dynamics.Joints.b2MouseJointDef();
|
||||
|
||||
def.bodyA = ground;
|
||||
def.bodyB = body;
|
||||
def.target = p;
|
||||
|
||||
def.collideConnected = false;
|
||||
def.maxForce = 100;
|
||||
def.dampingRatio = 0.99;
|
||||
|
||||
this.mouse_joint = this.physicsEngine.world.CreateJoint(def);
|
||||
|
||||
body.SetAwake(true);
|
||||
}
|
||||
|
||||
GameController.prototype.destruct = function() {
|
||||
//destroy box2d world etc.
|
||||
};
|
||||
|
|
@ -128,5 +109,13 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
|||
Parent.prototype.loadLevel.call(this, path);
|
||||
}
|
||||
|
||||
GameController.prototype.userLeft = function(user) {
|
||||
var doll = this.players[user.id].doll;
|
||||
var i = this.gameObjects.animated.indexOf(doll);
|
||||
if(i>=0) this.gameObjects.animated.splice(i, 1);
|
||||
|
||||
Parent.prototype.userLeft.call(this, user);
|
||||
}
|
||||
|
||||
return GameController;
|
||||
});
|
||||
|
|
|
|||
53
app/Game/Client/GameObjects/Item.js
Normal file
53
app/Game/Client/GameObjects/Item.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
define([
|
||||
"Game/Core/GameObjects/Item",
|
||||
"Game/Config/Settings",
|
||||
"Game/Core/NotificationCenter"
|
||||
],
|
||||
|
||||
function (Parent, Settings, NotificationCenter) {
|
||||
|
||||
function Item(physicsEngine, uid, options) {
|
||||
Parent.call(this, physicsEngine, uid, options);
|
||||
}
|
||||
|
||||
Item.prototype = Object.create(Parent.prototype);
|
||||
|
||||
Item.prototype.createMesh = function() {
|
||||
var self = this;
|
||||
|
||||
var texturePath = Settings.GRAPHICS_PATH
|
||||
+ Settings.GRAPHICS_SUBPATH_ITEMS
|
||||
+ this.options.category + '/'
|
||||
+ this.options.image;
|
||||
|
||||
var callback = function(mesh) {
|
||||
self.mesh = mesh;
|
||||
NotificationCenter.trigger("view/addMesh", mesh);
|
||||
}
|
||||
|
||||
NotificationCenter.trigger("view/createMesh",
|
||||
texturePath,
|
||||
callback,
|
||||
{
|
||||
width: this.options.width,
|
||||
height: this.options.height,
|
||||
pivot: "mb"
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
Item.prototype.render = function() {
|
||||
|
||||
NotificationCenter.trigger("view/updateMesh",
|
||||
this.mesh,
|
||||
{
|
||||
x: this.body.GetPosition().x * Settings.RATIO,
|
||||
y: this.body.GetPosition().y * Settings.RATIO,
|
||||
rotation: this.body.GetAngle()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return Item;
|
||||
|
||||
});
|
||||
|
|
@ -15,10 +15,9 @@ function (Parent, Settings, NotificationCenter) {
|
|||
Tile.prototype.createMesh = function() {
|
||||
var self = this;
|
||||
|
||||
var material = "Stones";
|
||||
var texturePath = Settings.GRAPHICS_PATH
|
||||
+ Settings.GRAPHICS_SUBPATH_TILES
|
||||
+ material + '/'
|
||||
+ this.options.m + '/'
|
||||
+ this.options.s + ''
|
||||
+ (this.options.r || 0) + '.gif';
|
||||
|
||||
|
|
|
|||
|
|
@ -63,11 +63,13 @@ function (ProtocolHelper, GameController, User, NotificationCenter, Settings) {
|
|||
if (options.spawnedPlayers) {
|
||||
for(var i = 0; i < options.spawnedPlayers.length; i++) {
|
||||
this.gameController.onSpawnPlayer(options.spawnedPlayers[i]);
|
||||
|
||||
console.log("already spawned player, options: ", options.spawnedPlayers[i])
|
||||
}
|
||||
}
|
||||
|
||||
if (options.worldUpdate) {
|
||||
this.gameController.onWorldUpdate(options.worldUpdate);
|
||||
}
|
||||
|
||||
this.initPing();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -83,26 +83,6 @@ function (Parent, Settings, NotificationCenter, Exception) {
|
|||
|
||||
}
|
||||
|
||||
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.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;
|
||||
|
||||
|
|
@ -140,6 +120,26 @@ function (Parent, Settings, NotificationCenter, Exception) {
|
|||
|
||||
Parent.prototype.destroy.call(this);
|
||||
}
|
||||
|
||||
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.headMesh,
|
||||
{
|
||||
x: this.body.GetPosition().x * Settings.RATIO,
|
||||
y: this.body.GetPosition().y * Settings.RATIO - 31
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return Doll;
|
||||
|
||||
|
|
|
|||
|
|
@ -104,16 +104,5 @@ function (DomController, Settings, Exception, NotificationCenter) {
|
|||
throw new Exception('Abstract Function setCameraZoom not overwritten ');
|
||||
}
|
||||
|
||||
// TODO Move to Level
|
||||
AbstractView.prototype.tileAtPositionExists = function(objects, x, y) {
|
||||
|
||||
for (var i = 0; i < objects.length; i++) {
|
||||
var o = objects[i];
|
||||
if(o.x == x && o.y == y) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
return AbstractView;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue