implemented gameobject for tiles and doll

This commit is contained in:
jeena 2013-12-23 02:39:05 +01:00
parent fe0d4a66e2
commit d51c705c1c
15 changed files with 221 additions and 326 deletions

View file

@ -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;
};

View file

@ -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);