mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
replaced all tabs with 4 spaces
This commit is contained in:
parent
5d11540c55
commit
26f3d22db7
30 changed files with 1017 additions and 1011 deletions
|
|
@ -1,50 +1,50 @@
|
|||
define(['Lib/Vendor/Three', 'Game/Config/Settings'], function(Three, Settings) {
|
||||
|
||||
function CameraController(isOrthographic) {
|
||||
function CameraController(isOrthographic) {
|
||||
|
||||
isOrthographic = typeof isOrthographic == 'undefined'
|
||||
? true
|
||||
: isOrthographic;
|
||||
isOrthographic = typeof isOrthographic == 'undefined'
|
||||
? true
|
||||
: isOrthographic;
|
||||
|
||||
|
||||
if(isOrthographic) {
|
||||
|
||||
this.camera = new Three.OrthographicCamera(
|
||||
-Settings.STAGE_WIDTH/2,
|
||||
Settings.STAGE_WIDTH/2,
|
||||
Settings.STAGE_HEIGHT/2,
|
||||
-Settings.STAGE_HEIGHT/2,
|
||||
-2000,
|
||||
1000
|
||||
);
|
||||
if(isOrthographic) {
|
||||
|
||||
this.camera = new Three.OrthographicCamera(
|
||||
-Settings.STAGE_WIDTH/2,
|
||||
Settings.STAGE_WIDTH/2,
|
||||
Settings.STAGE_HEIGHT/2,
|
||||
-Settings.STAGE_HEIGHT/2,
|
||||
-2000,
|
||||
1000
|
||||
);
|
||||
|
||||
} else {
|
||||
} else {
|
||||
|
||||
this.camera = new Three.PerspectiveCamera(
|
||||
45,
|
||||
Settings.STAGE_WIDTH / Settings.STAGE_HEIGHT,
|
||||
-2000,
|
||||
1000
|
||||
);
|
||||
}
|
||||
this.camera = new Three.PerspectiveCamera(
|
||||
45,
|
||||
Settings.STAGE_WIDTH / Settings.STAGE_HEIGHT,
|
||||
-2000,
|
||||
1000
|
||||
);
|
||||
}
|
||||
|
||||
this.camera.position.z = 481;
|
||||
}
|
||||
this.camera.position.z = 481;
|
||||
}
|
||||
|
||||
CameraController.prototype.getCamera = function(){
|
||||
return this.camera;
|
||||
}
|
||||
CameraController.prototype.getCamera = function(){
|
||||
return this.camera;
|
||||
}
|
||||
|
||||
CameraController.prototype.setPosition = function(x, y){
|
||||
this.camera.position.x = x;
|
||||
this.camera.position.y = y;
|
||||
}
|
||||
CameraController.prototype.setPosition = function(x, y){
|
||||
this.camera.position.x = x;
|
||||
this.camera.position.y = y;
|
||||
}
|
||||
|
||||
|
||||
CameraController.prototype.setZoom = function(z){
|
||||
this.camera.position.z = z;
|
||||
}
|
||||
CameraController.prototype.setZoom = function(z){
|
||||
this.camera.position.z = z;
|
||||
}
|
||||
|
||||
return CameraController;
|
||||
|
||||
return CameraController;
|
||||
|
||||
});
|
||||
|
|
@ -1,53 +1,53 @@
|
|||
define(['Game/Config/Settings'], function(Settings) {
|
||||
|
||||
var DomController = {
|
||||
canvas: null,
|
||||
debugCanvas: null
|
||||
};
|
||||
var DomController = {
|
||||
canvas: null,
|
||||
debugCanvas: null
|
||||
};
|
||||
|
||||
DomController.getCanvasContainer = function(){
|
||||
var container = document.getElementById(Settings.CANVAS_DOM_ID);
|
||||
DomController.getCanvasContainer = function(){
|
||||
var container = document.getElementById(Settings.CANVAS_DOM_ID);
|
||||
|
||||
if(container) {
|
||||
return container;
|
||||
} else {
|
||||
throw 'Canvas Container missing: #' + Settings.CANVAS_DOM_ID;
|
||||
}
|
||||
}
|
||||
if(container) {
|
||||
return container;
|
||||
} else {
|
||||
throw 'Canvas Container missing: #' + Settings.CANVAS_DOM_ID;
|
||||
}
|
||||
}
|
||||
|
||||
DomController.getCanvas = function(){
|
||||
return DomController.canvas;
|
||||
}
|
||||
DomController.getCanvas = function(){
|
||||
return DomController.canvas;
|
||||
}
|
||||
|
||||
DomController.setCanvas = function(canvas){
|
||||
|
||||
var container = DomController.getCanvasContainer();
|
||||
if(DomController.canvas){
|
||||
container.removeChild(DomController.canvas);
|
||||
}
|
||||
DomController.setCanvas = function(canvas){
|
||||
|
||||
var container = DomController.getCanvasContainer();
|
||||
if(DomController.canvas){
|
||||
container.removeChild(DomController.canvas);
|
||||
}
|
||||
|
||||
DomController.canvas = canvas;
|
||||
container.appendChild(canvas);
|
||||
}
|
||||
DomController.canvas = canvas;
|
||||
container.appendChild(canvas);
|
||||
}
|
||||
|
||||
DomController.getDebugCanvas = function(){
|
||||
return DomController.debugCanvas;
|
||||
}
|
||||
DomController.getDebugCanvas = function(){
|
||||
return DomController.debugCanvas;
|
||||
}
|
||||
|
||||
DomController.createDebugCanvas = function(){
|
||||
|
||||
var container = DomController.getCanvasContainer();
|
||||
if(DomController.debugCanvas){
|
||||
container.removeChild(DomController.debugCanvas);
|
||||
}
|
||||
DomController.createDebugCanvas = function(){
|
||||
|
||||
var container = DomController.getCanvasContainer();
|
||||
if(DomController.debugCanvas){
|
||||
container.removeChild(DomController.debugCanvas);
|
||||
}
|
||||
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = Settings.STAGE_WIDTH;
|
||||
canvas.height = Settings.STAGE_HEIGHT;
|
||||
DomController.debugCanvas = canvas;
|
||||
container.appendChild(canvas);
|
||||
}
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = Settings.STAGE_WIDTH;
|
||||
canvas.height = Settings.STAGE_HEIGHT;
|
||||
DomController.debugCanvas = canvas;
|
||||
container.appendChild(canvas);
|
||||
}
|
||||
|
||||
return DomController;
|
||||
|
||||
return DomController;
|
||||
|
||||
});
|
||||
|
|
@ -1,59 +1,59 @@
|
|||
var requires = [
|
||||
"Game/Client/View/DomController",
|
||||
"Lib/Vendor/Three",
|
||||
"Game/Config/Settings",
|
||||
"Game/Client/View/CameraController"
|
||||
"Game/Client/View/DomController",
|
||||
"Lib/Vendor/Three",
|
||||
"Game/Config/Settings",
|
||||
"Game/Client/View/CameraController"
|
||||
];
|
||||
|
||||
define(requires, function(DomController, Three, Settings, CameraController){
|
||||
|
||||
function ViewController(){
|
||||
|
||||
function ViewController(){
|
||||
|
||||
this.mesh = null;
|
||||
this.scene = null;
|
||||
this.renderer = null;
|
||||
this.cameraController = new CameraController();
|
||||
this.mesh = null;
|
||||
this.scene = null;
|
||||
this.renderer = null;
|
||||
this.cameraController = new CameraController();
|
||||
|
||||
this.init();
|
||||
}
|
||||
this.init();
|
||||
}
|
||||
|
||||
function isWebGlEnabled () {
|
||||
try {
|
||||
return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' );
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function isWebGlEnabled () {
|
||||
try {
|
||||
return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' );
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ViewController.prototype.init = function(){
|
||||
ViewController.prototype.init = function(){
|
||||
|
||||
var self = this;
|
||||
var self = this;
|
||||
|
||||
var rendererOptions = {
|
||||
antialias: true,
|
||||
preserveDrawingBuffer: true
|
||||
};
|
||||
var rendererOptions = {
|
||||
antialias: true,
|
||||
preserveDrawingBuffer: true
|
||||
};
|
||||
|
||||
if(isWebGlEnabled()) {
|
||||
this.renderer = new Three.WebGLRenderer(rendererOptions);
|
||||
} else {
|
||||
this.renderer = new Three.CanvasRenderer(rendererOptions);
|
||||
}
|
||||
|
||||
this.renderer.setClearColorHex(0x333333, 1);
|
||||
this.renderer.setSize(Settings.STAGE_WIDTH, Settings.STAGE_HEIGHT);
|
||||
if(isWebGlEnabled()) {
|
||||
this.renderer = new Three.WebGLRenderer(rendererOptions);
|
||||
} else {
|
||||
this.renderer = new Three.CanvasRenderer(rendererOptions);
|
||||
}
|
||||
|
||||
this.renderer.setClearColorHex(0x333333, 1);
|
||||
this.renderer.setSize(Settings.STAGE_WIDTH, Settings.STAGE_HEIGHT);
|
||||
|
||||
DomController.setCanvas(this.renderer.domElement);
|
||||
DomController.setCanvas(this.renderer.domElement);
|
||||
|
||||
if(Settings.DEBUG_MODE){
|
||||
DomController.createDebugCanvas();
|
||||
}
|
||||
if(Settings.DEBUG_MODE){
|
||||
DomController.createDebugCanvas();
|
||||
}
|
||||
|
||||
this.scene = new Three.Scene();
|
||||
this.scene.add(this.cameraController.getCamera());
|
||||
this.scene = new Three.Scene();
|
||||
this.scene.add(this.cameraController.getCamera());
|
||||
|
||||
|
||||
var ambientLight = new Three.AmbientLight(0xffffff);
|
||||
var ambientLight = new Three.AmbientLight(0xffffff);
|
||||
this.scene.add(ambientLight);
|
||||
|
||||
var directionalLight = new Three.DirectionalLight(0xffffff);
|
||||
|
|
@ -62,52 +62,52 @@ define(requires, function(DomController, Three, Settings, CameraController){
|
|||
|
||||
|
||||
this.createMesh(100, 100, 100, 100, 'static/img/100.png', function(mesh){
|
||||
self.mesh = mesh;
|
||||
self.scene.add(mesh);
|
||||
self.mesh = mesh;
|
||||
self.scene.add(mesh);
|
||||
});
|
||||
/*
|
||||
this.createMesh(50, 50, 200, 100, 'static/img/100.png', function(mesh){
|
||||
self.scene.add(mesh);
|
||||
this.createMesh(50, 50, 200, 100, 'static/img/100.png', function(mesh){
|
||||
self.scene.add(mesh);
|
||||
});
|
||||
*/
|
||||
|
||||
//this.animate(this);
|
||||
}
|
||||
}
|
||||
|
||||
ViewController.prototype.update = function() {
|
||||
ViewController.prototype.update = function() {
|
||||
|
||||
if(this.mesh) {
|
||||
this.mesh.rotation.z += .01;
|
||||
this.mesh.position.z += 1;
|
||||
this.mesh.position.x += .4;
|
||||
this.mesh.position.y += .4;
|
||||
if(this.mesh) {
|
||||
this.mesh.rotation.z += .01;
|
||||
this.mesh.position.z += 1;
|
||||
this.mesh.position.x += .4;
|
||||
this.mesh.position.y += .4;
|
||||
}
|
||||
|
||||
this.render();
|
||||
}
|
||||
this.render();
|
||||
}
|
||||
|
||||
ViewController.prototype.render = function() {
|
||||
ViewController.prototype.render = function() {
|
||||
|
||||
this.renderer.render(this.scene, this.cameraController.getCamera());
|
||||
}
|
||||
this.renderer.render(this.scene, this.cameraController.getCamera());
|
||||
}
|
||||
|
||||
ViewController.prototype.createMesh = function(width, height, x, y, imgPath, callback) {
|
||||
var textureImg = new Image();
|
||||
ViewController.prototype.createMesh = function(width, height, x, y, imgPath, callback) {
|
||||
var textureImg = new Image();
|
||||
textureImg.onload = function(){
|
||||
var material = new Three.MeshLambertMaterial({
|
||||
map: Three.ImageUtils.loadTexture(imgPath)
|
||||
});
|
||||
var material = new Three.MeshLambertMaterial({
|
||||
map: Three.ImageUtils.loadTexture(imgPath)
|
||||
});
|
||||
|
||||
var mesh = new Three.Mesh(new Three.PlaneGeometry(width, height), material);
|
||||
mesh.overdraw = true;/*
|
||||
mesh.position.z = 0;
|
||||
mesh.position.x = x;
|
||||
mesh.position.y = y;
|
||||
*/
|
||||
callback(mesh);
|
||||
var mesh = new Three.Mesh(new Three.PlaneGeometry(width, height), material);
|
||||
mesh.overdraw = true;/*
|
||||
mesh.position.z = 0;
|
||||
mesh.position.x = x;
|
||||
mesh.position.y = y;
|
||||
*/
|
||||
callback(mesh);
|
||||
};
|
||||
textureImg.src = imgPath;
|
||||
}
|
||||
}
|
||||
|
||||
return ViewController;
|
||||
return ViewController;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue