Permalink
Browse files

Merge branch 'master' of github.com:lauxley/ProtoGL

  • Loading branch information...
2 parents 067d145 + 1b76da2 commit 872b392489af9e4926c01f63b1526ab6d2f50286 @lauxley committed Oct 27, 2011
Showing with 78 additions and 4 deletions.
  1. +11 −1 client/index.html
  2. +4 −2 client/js/Game.js
  3. +33 −0 client/js/Mesh.js
  4. +30 −1 client/js/Player.js
View
@@ -27,6 +27,8 @@
var movingUp0 = false;
var movingLeft0 = false;
var movingRight0 = false;
+ var shooting = false;
+ var bombing = false;
// key listeners
var keydown = function(e){
@@ -38,6 +40,10 @@
movingRight0 = true;
if(e.keyCode == 40)
movingDown0 = true;
+ if(e.keyCode == 32)
+ shooting = true;
+ if(e.keyCode == 17)
+ bombing = true;
}
var keyup = function(e){
if(e.keyCode == 37)
@@ -48,6 +54,10 @@
movingRight0 = false;
if(e.keyCode == 40)
movingDown0 = false;
+ if(e.keyCode == 32)
+ shooting = false;
+ if(e.keyCode == 17)
+ bombing = false;
}
document.addEventListener("keydown",keydown,false);
@@ -58,7 +68,7 @@
// update de l etat du jeu
function gameUpdate()
{
- game.players.moveMe(movingUp0, movingDown0, movingLeft0, movingRight0);
+ game.players.moveMe(movingUp0, movingDown0, movingLeft0, movingRight0, shooting, bombing);
frameCount++;
if(frameCount%4 == 0) {
game.move(game.players.me.position.x, game.players.me.position.y, game.players.me.rotation.y);
View
@@ -39,9 +39,11 @@ function Game() {
this.socket.on('players', function (data) {
if (Object.keys(game.players.particles).length)
- game.players.updateOtherParticles(data);
+ game.players.updateOtherParticles(data);
else
- game.players.makePlayersParticles(data);
+ game.players.makePlayersParticles(data);
+ game.players.updateShoot();
+ game.players.updateBomb();
});
this.socket.on('this.info', function (data) {
View
@@ -120,5 +120,38 @@ function Scene() {
return 4;
return false;
};
+
+
+ this.shoot = function(particle)
+ {
+ material = new THREE.ParticleCanvasMaterial( { color: 0xff0000, program: this.particleRender } );
+ shoot = new THREE.Particle(material);
+ shoot.position.x = particle.position.x
+ shoot.position.y = particle.position.y
+ shoot.position.z = 50;
+ shoot.rotation.z = particle.rotation.z;
+ shoot.rotation.x = particle.rotation.x;
+ shoot.rotation.y = particle.rotation.y;
+ shoot.scale.x = shoot.scale.y = 3;
+ this.scene.addObject(shoot);
+ return shoot;
+ }
+
+ this.bomb = function(particle)
+ {
+ material = new THREE.ParticleCanvasMaterial( { color: 0x00ff00, program: this.particleRender } );
+ bomb = new THREE.Particle(material);
+ bomb.position.x = particle.position.x
+ bomb.position.y = particle.position.y
+ bomb.position.z = 50;
+ bomb.scale.x = bomb.scale.y = 3;
+ this.scene.addObject(bomb);
+ return bomb;
+ }
+
+ this.explodeBomb = function(bomb)
+ {
+ this.scene.removeObject(bomb);
+ }
}
View
@@ -2,6 +2,8 @@
function players() {
this.particles = [],
this.me = null,
+ this.shoots = [],
+ this.bombs = []
this.makeMe = function(data)
{
@@ -30,7 +32,7 @@ function players() {
};
// déplacement de la particule du joueur
- this.moveMe = function (movingUp0, movingDown0, movingLeft0, movingRight0)
+ this.moveMe = function (movingUp0, movingDown0, movingLeft0, movingRight0, shooting, bombing)
{
var collision = scene.detectCollision(this.me);
@@ -42,6 +44,10 @@ function players() {
this.me.rotation.y += 0.1;
if(movingRight0 == true && collision != 2)
this.me.rotation.y -= 0.1;
+ if(shooting == true)
+ this.shoots.push(scene.shoot(this.me));
+ if(bombing == true)
+ this.bombs.push(scene.bomb(this.me));
this.me.updateMatrix();
};
@@ -60,5 +66,28 @@ function players() {
}
}
};
+
+ // gestion des projectiles
+ this.updateShoot = function()
+ {
+ for(var i=0; i<this.shoots.length; i++)
+ {
+ this.shoots[i].translateX(5);
+ }
+ }
+
+ // gestion des bombes
+ this.updateBomb = function()
+ {
+ for(var i=0; i<this.bombs.length; i++)
+ {
+ this.bombs[i].scale.x++;
+ this.bombs[i].scale.y++;
+ if(this.bombs[i].scale.x == 150)
+ {
+ scene.explodeBomb(this.bombs[i]);
+ }
+ }
+ }
};

0 comments on commit 872b392

Please sign in to comment.