Skip to content

Commit

Permalink
fixed merge errors
Browse files Browse the repository at this point in the history
  • Loading branch information
numso committed Mar 15, 2013
2 parents a729a5a + bf7b959 commit 3739877
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 57 deletions.
91 changes: 91 additions & 0 deletions client/collision.js
@@ -0,0 +1,91 @@
function Mush(mushrooms, thisBullet){
for(var n = 0; n < mushrooms.length; ++n)
{
if(thisBullet.x > mushrooms[n].x && thisBullet.x < mushrooms[n].x + mushrooms[n].width)
if(thisBullet.y < mushrooms[n].y + mushrooms[n].height)
{
--mushrooms[n].size;
if(mushrooms[n].size == 0)
mushrooms.splice(n, 1);
return true;
}
}
return false;
};

function Poison(poison, thisBullet){
for(var n = 0; n < poison.length; ++n)
{
if(thisBullet.x > poison[n].x && thisBullet.x < poison[n].x + poison[n].width)
if(thisBullet.y < poison[n].y + poison[n].height)
{
--poison[n].size;
if(poison[n].size == 0)
poison.splice(n, 1);
return true;
}
}
return false;
};


function Spider(spider, thisBullet){
if(thisBullet.x > spider.x && thisBullet.x < spider.x + spider.width)
if(thisBullet.y < spider.y + spider.height)
return true;
return false;
};

function Scorpion(scorpion, thisBullet){
if(thisBullet.x > scorpion.x && thisBullet.x < scorpion.x + scorpion.width)
if(thisBullet.y < scorpion.y + scorpion.height)
return true;
return false;
};

function checkPoison(mushrooms, poison, thisScorpion){
for(var n = 0; n < mushrooms.length; ++n)
{
if( mushrooms[n].x < thisScorpion.x + thisScorpion.width && thisScorpion.x < mushrooms[n].x + mushrooms[n].width)
if(mushrooms[n].y < thisScorpion.y + thisScorpion.height && thisScorpion.y < mushrooms[n].y + mushrooms[n].height)
{
poison.push(mushrooms[n]);
mushrooms.splice(n, 1);
}
}
};


function isDead(scorpion, spider, thisChar){
if(charVSSpider(spider, thisChar))
return true;
else if(charVSScorpion(scorpion, thisChar))
return true;

else
return false;
};

function charVSSpider(spider, thisChar){
if(thisChar.x + thisChar.width > spider.x && thisChar.x < spider.x + spider.width)
if(thisChar.y + thisChar.height > spider.y && thisChar.y < spider.y + spider.height)

return true;

return false;
};

function charVSScorpion(scorpion, thisChar){
if(thisChar.x + thisChar.width > scorpion.x && thisChar.x < scorpion.x + scorpion.width)
if(thisChar.y + thisChar.height > scorpion.y && thisChar.y < scorpion.y + scorpion.height)
return true;

return false;
};

exports.Mush = Mush;
exports.Poison = Poison;
exports.Spider = Spider;
exports.Scorpion = Scorpion;
exports.checkPoison = checkPoison;
exports.isDead = isDead;
8 changes: 4 additions & 4 deletions client/graphics.js
Expand Up @@ -28,13 +28,13 @@ function drawScorpion(ctx, x, y){
};

function drawPoison(num, ctx, x, y){
if(num = 4)
if(num == 4)
ctx.drawImage(spriteSheet, 0, 50, 50, 50, x, y, 20, 20);
if(num = 3)
if(num == 3)
ctx.drawImage(spriteSheet, 100, 50, 50, 50, x, y, 20, 20);
if(num = 2)
if(num == 2)
ctx.drawImage(spriteSheet, 50, 50, 50, 50, x, y, 20, 20);
if(num = 1)
if(num == 1)
ctx.drawImage(spriteSheet, 150, 50, 50, 50, x, y, 20, 20);
};

Expand Down
17 changes: 17 additions & 0 deletions client/sounds.js
@@ -0,0 +1,17 @@
var sound;
var click;
function playMusic(){
sound = new Howl({urls: ['/snd/tron.mp3'], autoplay: true, loop: true, volume: .5});
}

function stopMusic(){
sound.stop();
}

function playClick(){
click = new Howl({});
}

exports.playMusic = playMusic;
exports.stopMusic = stopMusic;
exports.playClick = playClick;
73 changes: 20 additions & 53 deletions client/states/game.js
Expand Up @@ -2,6 +2,8 @@ var jadify = require('../requires/render')
, shared = require('../shared')
, g = require('../graphics')
, inp = require('../input')
, snd = require('../sounds')
, collision = require('../collision')
;

var characters = [];
Expand All @@ -13,6 +15,7 @@ var spider, scorpion;
function start() {
$('.gameScreen').html(jadify('game'));
shared.bindBackButton();
//snd.playMusic();
};

function init(){
Expand Down Expand Up @@ -71,23 +74,35 @@ function update(dTime){
characters[n].y += characters[n].dy * dTime;
if(inp.fire())
addBullet(characters[n]);
if(collision.isDead(scorpion, spider, characters[n]))
{
console.log("your dead dude");
//snd.stopMusic();
}
}

//bullet position
for(var n = 0; n < bullets.length; ++n)
{
bullets[n].y -= bullets[n].dy * dTime;
if(checkCollisionSpider(bullets[n]) && scorpion.visible)
if(collision.Spider(spider, bullets[n]) && spider.visible)
{
spider.visible = false;
bullets.splice(n, 1);
--n;
}
if(checkCollisionScorpion(bullets[n]) && scorpion.visible)
if(collision.Scorpion(scorpion, bullets[n]) && scorpion.visible)
{
scorpion.visible = false;
bullets.splice(n, 1);
--n;
}
if(checkMushroomCollision(bullets[n]))
if(collision.Mush(mushrooms, bullets[n]))
{
bullets.splice(n, 1);
--n;
}
if(collision.Poison(poison, bullets[n]))
{
bullets.splice(n, 1);
--n;
Expand All @@ -99,7 +114,7 @@ function update(dTime){
if(scorpion.x > 0 && scorpion.x < (500 - scorpion.width))
{
scorpion.x += scorpion.dx * dTime;
checkPoison(scorpion);
collision.checkPoison(mushrooms, poison, scorpion);
}
else
{
Expand All @@ -110,7 +125,7 @@ function update(dTime){
}

//spider position
if(scorpion.visible){
if(spider.visible){
if(spider.x > 0 && spider.x < (500 - spider.width))
spider.x += spider.dx * dTime;
else
Expand All @@ -131,54 +146,6 @@ function addBullet(thisChar){
});
};

function checkMushroomCollision(thisBullet){
for(var n = 0; n < mushrooms.length; ++n)
{
if(thisBullet.x > mushrooms[n].x && thisBullet.x < mushrooms[n].x + mushrooms[n].width)
if(thisBullet.y < mushrooms[n].y + mushrooms[n].height)
{
--mushrooms[n].size;
if(mushrooms[n].size == 0)
mushrooms.splice(n, 1);
return true;
}
}
return false;
};

function checkCollisionSpider(thisBullet){
if(thisBullet.x > spider.x && thisBullet.x < spider.x + spider.width)
if(thisBullet.y < spider.y + spider.height)
{
spider.visible = false;
return true;
}

return false;
};

function checkCollisionScorpion(thisBullet){
if(thisBullet.x > scorpion.x && thisBullet.x < scorpion.x + scorpion.width)
if(thisBullet.y < scorpion.y + scorpion.height)
{
scorpion.visible = false;
return true;
}

return false;
};

function checkPoison(thisScorpion){
for(var n = 0; n < mushrooms.length; ++n)
{
if( mushrooms[n].x < thisScorpion.x + thisScorpion.width && thisScorpion.x < mushrooms[n].x + mushrooms[n].width)
if(mushrooms[n].y < thisScorpion.y + thisScorpion.height && thisScorpion.y < mushrooms[n].y + mushrooms[n].height)
{
poison.push(mushrooms[n]);
mushrooms.splice(n, 1);
}
}
};

function render(ctx){
ctx.fillStyle = 'blue';
Expand Down
Binary file added public/snd/tron.mp3
Binary file not shown.
1 change: 1 addition & 0 deletions views/layout.jade
Expand Up @@ -10,6 +10,7 @@ html
block content
block scripts
script(src='/js/lib/jquery.js')
script(src='/js/lib/howler.js')
script(src='/js/lib/impress.js')
script
impress().init();
Expand Down

0 comments on commit 3739877

Please sign in to comment.