Skip to content

Commit

Permalink
Revert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
janewang committed Jul 21, 2012
1 parent ab432f5 commit 1b2a90c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 40 deletions.
12 changes: 6 additions & 6 deletions assets/js/views/icaruseView.js
Expand Up @@ -17,7 +17,7 @@ var PlayerListView = Backbone.View.extend({
});
this.socket.on('collision', function(data){
self.playerStatus(data);
self.impactSound.play();
// self.impactSound.play();
});

this.canvas = $('#particles')[0];
Expand All @@ -26,16 +26,16 @@ var PlayerListView = Backbone.View.extend({
this.context.font = '30pt Helvetica';
this.context.textAligh = 'center';
this.context.textBaseline = 'center';
this.context.fillText('Press Any Key to Start Game', self.canvas.width/2-250, self.canvas.height/2);
this.context.fillText('Press Any Key to Start Game', self.canvas.width/2-250, self.canvas.height/2);
this.img = new Image();
this.img.src = '/images/kid_icarus.png';
this.impactSound = new Audio('/audios/impact.wav');
this.backgroundMusic = new Audio('/audios/SusanFantasticDamage.mp3');
this.img.src = '../../images/kid_icarus.png';
// this.impactSound = new Audio('../../audios/impact.wav');
this.backgroundMusic = new Audio('../../audios/SusanFantasticDamage.mp3');
},

start: function(x, y) {
this.socket.emit('start game');
this.fly();
// this.socket.emit('start game');
this.backgroundMusic.play();
clearInterval(this.newGameTimer);
},
Expand Down
11 changes: 1 addition & 10 deletions assets/js/views/particleView.js
Expand Up @@ -9,24 +9,15 @@ var UniverseView = Backbone.View.extend({
_.bindAll(this, 'start');
this.canvas = $('#particles')[0];
this.context = this.canvas.getContext('2d');
this.spirit = 100;

this.particleCollection = new ParticleCollection();
var self = this;

this.socket = io.connect('http://' + window.location.hostname);

this.socket.on('collision', function(data){
if (data.sessionId === _.pluck(io.sockets, 'sessionid')[0]) {
this.spirit = data.spirit;
}
});

// only render universe when this icarus is still alive
this.socket.on('particle position', function (data) {
if (this.spirit > 0) {
self.particleCollection.reset(data);
}
self.particleCollection.reset(data);
});
},

Expand Down
37 changes: 13 additions & 24 deletions gameLogic.js
Expand Up @@ -12,14 +12,10 @@ var playerList = [];
io.sockets.on('connection', function (socket) {
console.log('Player ' + socket.id + ' has joined.');

socket.on('start game', function(){
icarusApp = new IcarusApp(io);
});

socket.on('icarus position', function(data){

socket.broadcast.emit('other icarus position', data);

socket.broadcast.emit('other icarus position', data);

// add new Icarus to playerList
if ( _.chain(playerList).pluck('sessionId').include(data.sessionId).value() === false || playerList.length === 0 ) {
playerList.push(new Icarus(data.x, data.y, data.sessionId));
Expand Down Expand Up @@ -50,10 +46,6 @@ io.sockets.on('connection', function (socket) {
playerList = _(playerList).without(icarus);
}
});

if (playerList.length === 0) {
icarusApp = null;
}
});
});

Expand Down Expand Up @@ -158,27 +150,24 @@ var Particle = function(){
}
}

function checkCollision(particles) {
function checkCollision(a) {
if (playerList.length !== 0) {
_.each(playerList, function(icarus) {
_.each(particles, function(a) {
if (Math.abs(a.position.x - icarus.x) < 10 && (Math.abs(a.position.y - icarus.y) < 16)) {
icarus.spirit -= 4;
io.sockets.emit('collision', icarus);
}
});
});
if (Math.abs(a.position.x - icarus.x) < 10 && (Math.abs(a.position.y - icarus.y) < 16)) {
icarus.spirit -= 4;
io.sockets.emit('collision', icarus);
}
});
}
}

var IcarusApp = function(io) {
var self = this;
this.particles = [];
_(150).times(_.bind(function() { this.particles.push(new Particle()); }, this));

this.timer = setInterval(function() {
this.particles = self.update();
checkCollision(this.particles);

var timer = setInterval(function() {
self.update();
io.sockets.emit('particle position', _.pluck(self.particles, 'position'));
}, 50);
}
Expand All @@ -203,8 +192,8 @@ IcarusApp.prototype.update = function() {
}
});
a.step();
checkCollision(a);
});
return this.particles;
}

var icarusApp;
var icarusApp = new IcarusApp(io);

0 comments on commit 1b2a90c

Please sign in to comment.