Permalink
Browse files

some more refacto

  • Loading branch information...
1 parent 756df73 commit dc86f4b7fb7d239595f31ff34b98270eaff662ed @lauxley committed Oct 27, 2011
Showing with 36 additions and 27 deletions.
  1. +6 −6 client/index.html
  2. +23 −18 client/js/Mesh.js
  3. +7 −3 client/js/Player.js
View
@@ -18,7 +18,8 @@
</style>
<script type="text/javascript">
- jQuery(function(){
+
+
function init() {
@@ -59,18 +60,17 @@
// update de l etat du jeu
function update()
{
- players.moveMe(movingUp0, movingDown0, movingLeft0, movingRight0);
+ game.players.moveMe(movingUp0, movingDown0, movingLeft0, movingRight0);
frameCount++;
if(!frameCount%5) {
Game.move(players.me.position.x, players.me.position.y);
}
- renderer.render( scene, camera );
+ scene.renderer.render( scene, camera );
}
}
-});
-
-game = new Game();
+var scene = new Scene();
+var game = new Game();
game.init();
/*
View
@@ -1,28 +1,32 @@
// the main three.js components
-var camera, scene, renderer;
-function initScene()
-{
+function Scene() {
+ this.camera = null;
+ this.scene = null;
+ this.renderer = null;
+
+ this.init = function()
+ {
// Camera params :
// field of view, aspect ratio for render output, near and far clipping plane.
- camera = new THREE.Camera(80, window.innerWidth / window.innerHeight, 1, 4000 );
+ this.camera = new THREE.Camera(80, window.innerWidth / window.innerHeight, 1, 4000 );
// move the camera backwards so we can see stuff!
// default position is 0,0,0.
- camera.position.z = 1000;
+ this.camera.position.z = 1000;
- scene = new THREE.Scene();
+ this.scene = new THREE.Scene();
- renderer = new THREE.CanvasRenderer();
- renderer.setSize( window.innerWidth, window.innerHeight );
+ this.renderer = new THREE.CanvasRenderer();
+ this.renderer.setSize( window.innerWidth, window.innerHeight );
- document.body.appendChild( renderer.domElement );
-}
+ document.body.appendChild( this.renderer.domElement );
+ }
-function makeParticle(playerInfo)
-{
- material = new THREE.ParticleCanvasMaterial( { color: 0xffffff, program: particleRender } );
+ this.makeParticle = function(playerInfo)
+ {
+ material = new THREE.ParticleCanvasMaterial( { color: 0xffffff, program: this.particleRender } );
particle = new THREE.Particle(material);
particle.id = playerInfo['id'];
@@ -31,13 +35,14 @@ function makeParticle(playerInfo)
particle.position.z = 50;
particle.scale.x = particle.scale.y = 10;
- scene.addObject(particle);
+ this.scene.addObject(particle);
return particle;
-}
+ };
-function particleRender( context )
-{
+ this.particleRender = function ( context )
+ {
context.beginPath();
context.arc( 0, 0, 1, 0, Math.PI * 2, true );
context.fill();
-};
+ };
+}
View
@@ -5,14 +5,18 @@ function players() {
this.makeMe = function(data)
{
- this.me = makeParticle(data);
+ this.me = scene.makeParticle(data);
},
- this.makePlayerParticles = function(data)
+ this.makePlayerParticle = function(data) {
+ return scene.makeParticle(data);
+ }
+
+ this.makePlayersParticles = function(data)
{
for(var i = 0; i < data.length ; i++)
{
- this.particles[data[i].id] = makeParticle(data[i]);
+ this.makePlayerParticle(data[i]);
}
},

0 comments on commit dc86f4b

Please sign in to comment.