mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
implemented gameobject for tiles and doll
This commit is contained in:
parent
fe0d4a66e2
commit
d51c705c1c
15 changed files with 221 additions and 326 deletions
|
|
@ -127,7 +127,6 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
|||
}
|
||||
|
||||
GameController.prototype.onJoinMe = function (playerId) {
|
||||
//this.onSpawnPlayer(options);
|
||||
this.me = this.players[playerId];
|
||||
this.me.setPlayerController(new PlayerController(this.me));
|
||||
this.view.setMe(this.me);
|
||||
|
|
@ -140,15 +139,11 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
|||
|
||||
var player = this.players[playerId];
|
||||
player.spawn(x, y);
|
||||
|
||||
// add to view controller
|
||||
this.view.addPlayer(player);
|
||||
this.gameObjects.animated.push(player.getDoll());
|
||||
}
|
||||
|
||||
GameController.prototype.loadLevel = function (path) {
|
||||
Parent.prototype.loadLevel.call(this, path);
|
||||
var tiles = this.level.levelObject.tiles;
|
||||
this.view.loadMeshes(tiles);
|
||||
}
|
||||
|
||||
return GameController;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
define([
|
||||
"Game/Core/GameObjects/GameObject"
|
||||
"Game/Core/GameObjects/GameObject",
|
||||
"Lib/Utilities/Exception"
|
||||
],
|
||||
|
||||
function(Parent) {
|
||||
function (Parent, Exception) {
|
||||
|
||||
function GameObject(physicsEngine, view) {
|
||||
this.view = view;
|
||||
function GameObject(physicsEngine) {
|
||||
Parent.call(this, physicsEngine);
|
||||
this.createMesh();
|
||||
this.render();
|
||||
|
|
@ -23,7 +23,7 @@ function(Parent) {
|
|||
}
|
||||
|
||||
GameObject.prototype.createMesh = function() {
|
||||
throw new Exception('Abstract method GameObject.getMesh not overwritten');
|
||||
throw new Exception('Abstract method GameObject.createMesh not overwritten');
|
||||
};
|
||||
|
||||
return GameObject;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
define([
|
||||
"Game/Core/GameObjects/Tile",
|
||||
"Game/Config/Settings"
|
||||
"Game/Config/Settings",
|
||||
"Game/Core/NotificationCenter"
|
||||
],
|
||||
|
||||
function (Parent, Settings) {
|
||||
function (Parent, Settings, NotificationCenter) {
|
||||
|
||||
function Tile(physicsEngine, view, options) {
|
||||
Parent.call(this, physicsEngine, view, options);
|
||||
function Tile(physicsEngine, options) {
|
||||
Parent.call(this, physicsEngine, options);
|
||||
}
|
||||
|
||||
Tile.prototype = Object.create(Parent.prototype);
|
||||
|
|
@ -19,28 +20,32 @@ function (Parent, Settings) {
|
|||
+ Settings.GRAPHICS_SUBPATH_TILES
|
||||
+ material + '/'
|
||||
+ this.options.s + ''
|
||||
+ this.options.r + '.gif';
|
||||
+ (this.options.r || 0) + '.gif';
|
||||
|
||||
var callback = function(mesh) {
|
||||
self.mesh = mesh;
|
||||
self.view.addMesh(mesh);
|
||||
NotificationCenter.trigger("view/addMesh", mesh);
|
||||
}
|
||||
|
||||
this.view.createMesh(
|
||||
Settings.TILE_SIZE,
|
||||
Settings.TILE_SIZE,
|
||||
0,
|
||||
0,
|
||||
imgPath,
|
||||
callback
|
||||
);
|
||||
|
||||
NotificationCenter.trigger("view/createMesh",
|
||||
Settings.TILE_SIZE,
|
||||
Settings.TILE_SIZE,
|
||||
0,
|
||||
0,
|
||||
imgPath,
|
||||
callback
|
||||
);
|
||||
};
|
||||
|
||||
Tile.prototype.render = function() {
|
||||
this.view.updateMesh(this.mesh, {
|
||||
x: this.options.x * Settings.TILE_SIZE,
|
||||
y: this.options.y * Settings.TILE_SIZE,
|
||||
})
|
||||
|
||||
NotificationCenter.trigger("view/updateMesh",
|
||||
this.mesh,
|
||||
{
|
||||
x: this.options.x * Settings.TILE_SIZE,
|
||||
y: this.options.y * Settings.TILE_SIZE,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return Tile;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,52 @@
|
|||
define([
|
||||
"Game/Core/Physics/Doll"
|
||||
"Game/Core/Physics/Doll",
|
||||
"Game/Config/Settings",
|
||||
"Game/Core/NotificationCenter"
|
||||
],
|
||||
|
||||
function(Parent) {
|
||||
function (Parent, Settings, NotificationCenter) {
|
||||
|
||||
return Parent;
|
||||
function Doll(physicsEngine, playerId) {
|
||||
Parent.call(this, physicsEngine, playerId);
|
||||
this.height = 36;
|
||||
}
|
||||
|
||||
Doll.prototype = Object.create(Parent.prototype);
|
||||
|
||||
Doll.prototype.createMesh = function() {
|
||||
var self = this;
|
||||
|
||||
var imgPath = Settings.GRAPHICS_PATH
|
||||
+ Settings.GRAPHICS_SUBPATH_CHARACTERS
|
||||
+ 'Chuck' + '/'
|
||||
+ 'chuck.png';
|
||||
|
||||
var callback = function(mesh) {
|
||||
self.mesh = mesh;
|
||||
NotificationCenter.trigger("view/addMesh", mesh);
|
||||
}
|
||||
|
||||
NotificationCenter.trigger("view/createMesh",
|
||||
10,
|
||||
36,
|
||||
0,
|
||||
0,
|
||||
imgPath,
|
||||
callback
|
||||
);
|
||||
};
|
||||
|
||||
Doll.prototype.render = function() {
|
||||
|
||||
NotificationCenter.trigger("view/updateMesh",
|
||||
this.mesh,
|
||||
{
|
||||
x: this.body.GetPosition().x * Settings.RATIO + 4,
|
||||
y: (this.body.GetPosition().y * Settings.RATIO) - 29
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return Doll;
|
||||
|
||||
});
|
||||
|
|
@ -1,14 +1,19 @@
|
|||
define([
|
||||
"Game/Client/View/DomController",
|
||||
"Game/Config/Settings",
|
||||
"Lib/Utilities/Exception"
|
||||
"Lib/Utilities/Exception",
|
||||
"Game/Core/NotificationCenter"
|
||||
],
|
||||
|
||||
function (DomController, Settings, Exception) {
|
||||
function (DomController, Settings, Exception, NotificationCenter) {
|
||||
|
||||
function AbstractView () {
|
||||
this.me = null;
|
||||
this.canvas = null;
|
||||
|
||||
NotificationCenter.on("view/createMesh", this.createMesh, this);
|
||||
NotificationCenter.on("view/addMesh", this.addMesh, this);
|
||||
NotificationCenter.on("view/updateMesh", this.updateMesh, this);
|
||||
}
|
||||
|
||||
AbstractView.prototype.isWebGlEnabled = function () {
|
||||
|
|
@ -29,10 +34,6 @@ function (DomController, Settings, Exception) {
|
|||
}
|
||||
}
|
||||
|
||||
AbstractView.prototype.addMesh = function(mesh) {
|
||||
throw new Exception('Abstract Function addMesh not overwritten ');
|
||||
};
|
||||
|
||||
AbstractView.prototype.loadPlayerMesh = function(player) {
|
||||
throw new Exception('Abstract Function loadPlayerMesh not overwritten ');
|
||||
};
|
||||
|
|
@ -49,6 +50,14 @@ function (DomController, Settings, Exception) {
|
|||
throw new Exception('Abstract Function createMesh not overwritten ');
|
||||
}
|
||||
|
||||
AbstractView.prototype.addMesh = function(mesh) {
|
||||
throw new Exception('Abstract Function addMesh not overwritten ');
|
||||
};
|
||||
|
||||
AbstractView.prototype.updateMesh = function(mesh, options) {
|
||||
throw new Exception('Abstract Function updateMesh not overwritten ');
|
||||
};
|
||||
|
||||
AbstractView.prototype.setMe = function(player) {
|
||||
this.me = player;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -35,42 +35,12 @@ function (Parent, DomController, PIXI, Settings) {
|
|||
this.setCanvas(this.renderer.view);
|
||||
}
|
||||
|
||||
PixiView.prototype.loadMeshes = function(objects) {
|
||||
var self = this;
|
||||
for (var i = 0; i < objects.length; i++) {
|
||||
(function() {
|
||||
var o = objects[i];
|
||||
var x = o.x * Settings.TILE_SIZE;
|
||||
var y = o.y * Settings.TILE_SIZE;
|
||||
var r = o.r ? o.r : 0;
|
||||
var rad = 0.5 * Math.PI * -r;
|
||||
|
||||
var material = self.tileAtPositionExists(objects, o.x, o.y -1) ? "Soil" : "GrassSoil";
|
||||
var callback = function(mesh) {
|
||||
self.addMesh(mesh);
|
||||
//console.log("img height:", mesh.material.map.image.height);
|
||||
//mesh.rotation.z = rad;
|
||||
};
|
||||
self.createMesh(Settings.TILE_SIZE, Settings.TILE_SIZE, x, y, 'static/img/Tiles/' + material + '/' + o.s + '' + o.r + '.gif', callback, true);
|
||||
})();
|
||||
};
|
||||
};
|
||||
|
||||
PixiView.prototype.render = function () {
|
||||
if(this.me) {
|
||||
var pos = this.calculateCameraPosition();
|
||||
this.setCameraPosition(pos.x, pos.y);
|
||||
}
|
||||
|
||||
/*
|
||||
for (var i = 0; i < this.movableObjects.length; i++) {
|
||||
var obj = this.movableObjects[i];
|
||||
var pos = obj.player.getPosition();
|
||||
obj.mesh.position.x = pos.x * Settings.RATIO + 4 ;
|
||||
obj.mesh.position.y = pos.y * Settings.RATIO - 34; // weirdly a different magic number as for three
|
||||
}
|
||||
*/
|
||||
|
||||
this.renderer.render(this.stage);
|
||||
}
|
||||
|
||||
|
|
@ -101,25 +71,6 @@ function (Parent, DomController, PIXI, Settings) {
|
|||
if (options.height) mesh.height = options.height;
|
||||
};
|
||||
|
||||
PixiView.prototype.addPlayer = function(player) {
|
||||
var self = this;
|
||||
var mesh = null;
|
||||
var pos = player.getPosition();
|
||||
var size = {w:10, h:42};
|
||||
var callback = function(mesh) {
|
||||
self.addMesh(mesh);
|
||||
self.movableObjects.push({
|
||||
player: player,
|
||||
mesh: mesh
|
||||
});
|
||||
}
|
||||
this.createMesh(size.w, size.h, pos.x, pos.y, "static/img/Characters/Chuck/chuck.png", callback, false);
|
||||
};
|
||||
|
||||
PixiView.prototype.removPlayer = function(player) {
|
||||
// nothing
|
||||
};
|
||||
|
||||
PixiView.prototype.initCamera = function () {
|
||||
this.container = new PIXI.DisplayObjectContainer();
|
||||
this.stage.addChild(this.container);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue