mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
first attempt to implement GameObject
This commit is contained in:
parent
aa30a23ca1
commit
fe0d4a66e2
14 changed files with 328 additions and 129 deletions
|
|
@ -29,6 +29,10 @@ 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 ');
|
||||
};
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ function (Parent, DomController, PIXI, Settings) {
|
|||
|
||||
var material = self.tileAtPositionExists(objects, o.x, o.y -1) ? "Soil" : "GrassSoil";
|
||||
var callback = function(mesh) {
|
||||
self.container.addChild(mesh);
|
||||
self.addMesh(mesh);
|
||||
//console.log("img height:", mesh.material.map.image.height);
|
||||
//mesh.rotation.z = rad;
|
||||
};
|
||||
|
|
@ -62,48 +62,56 @@ function (Parent, DomController, PIXI, Settings) {
|
|||
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);
|
||||
}
|
||||
|
||||
PixiView.prototype.createMesh = function (width, height, x, y, imgPath, callback, isTile) {
|
||||
PixiView.prototype.addMesh = function(mesh) {
|
||||
this.container.addChild(mesh);
|
||||
};
|
||||
|
||||
PixiView.prototype.createMesh = function (width, height, x, y, imgPath, callback) {
|
||||
|
||||
var texture = PIXI.Texture.fromImage(imgPath);
|
||||
var mesh;
|
||||
|
||||
//if(isTile) {
|
||||
// mesh = new PIXI.TilingSprite(texture, width, height);
|
||||
//} else {
|
||||
|
||||
mesh = new PIXI.Sprite(texture);
|
||||
var mesh = new PIXI.Sprite(texture);
|
||||
mesh.width = width;
|
||||
mesh.height = height;
|
||||
|
||||
//}
|
||||
|
||||
mesh.position.x = x;
|
||||
mesh.position.y = y;
|
||||
|
||||
callback(mesh);
|
||||
}
|
||||
|
||||
PixiView.prototype.updateMesh = function(mesh, options) {
|
||||
if (options.x) mesh.position.x = options.x;
|
||||
if (options.y) mesh.position.y = options.y;
|
||||
if (options.rotation) mesh.rotation = options.rotation;
|
||||
if (options.xScale) mesh.scale.x = options.xScale;
|
||||
if (options.yScale) mesh.scale.y = options.yScale;
|
||||
if (options.width) mesh.width = options.width;
|
||||
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.container.addChild(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);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ function (Parent, DomController, Three, Settings) {
|
|||
var material = self.tileAtPositionExists(objects, o.x, o.y -1) ? "Soil" : "GrassSoil";
|
||||
|
||||
self.createMesh(Settings.TILE_SIZE, Settings.TILE_SIZE, x, y, 'static/img/Tiles/' + material + '/' + o.s + '' + o.r + '.gif', function(mesh) {
|
||||
self.scene.add(mesh);
|
||||
self.addMesh(mesh);
|
||||
//console.log("img height:", mesh.material.map.image.height);
|
||||
//mesh.rotation.z = rad;
|
||||
});
|
||||
|
|
@ -86,6 +86,10 @@ function (Parent, DomController, Three, Settings) {
|
|||
this.renderer.render(this.scene, this.camera);
|
||||
}
|
||||
|
||||
ThreeView.prototype.addMesh = function(mesh) {
|
||||
this.scene.add(mesh);
|
||||
};
|
||||
|
||||
ThreeView.prototype.createMesh = function (width, height, x, y, imgPath, callback) {
|
||||
var mesh;
|
||||
var material = new Three.MeshLambertMaterial({
|
||||
|
|
@ -101,13 +105,24 @@ function (Parent, DomController, Three, Settings) {
|
|||
mesh.position.y = y;
|
||||
}
|
||||
|
||||
ThreeView.prototype.updateMesh = function(mesh, options) {
|
||||
if (options.x) mesh.position.x = options.x;
|
||||
if (options.y) mesh.position.y = options.y;
|
||||
if (options.rotation) mesh.rotation.z = options.rotation * (Math.PI / 180);
|
||||
if (options.xScale) mesh.width *= options.xScale;
|
||||
if (options.yScale) mesh.height *= options.yScale;
|
||||
if (options.width) mesh.width = options.width;
|
||||
if (options.height) mesh.height = options.height;
|
||||
};
|
||||
|
||||
|
||||
ThreeView.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.scene.add(mesh);
|
||||
self.addMesh(mesh);
|
||||
self.movableObjects.push({
|
||||
player: player,
|
||||
mesh: mesh
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue