Skip to content

Commit

Permalink
fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
numso committed Mar 24, 2013
2 parents 516bbf6 + eaaaaa4 commit e49980c
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 13 deletions.
21 changes: 14 additions & 7 deletions client/bullets.js
@@ -1,11 +1,13 @@
var bullets = [];
var spider = require('./spider')
, scorpion = require('./scorpion')
, peed = require('./centipede')
, collision = require('./collision')

var spider = require('./spider')
, scorpion = require('./scorpion')
, peed = require('./centipede')
, collision = require('./collision')
, shrooms = require('./shrooms')
, playa = require('./playa')
;
, flea = require('./flea')
;

function add(x, y){
bullets.push({
Expand All @@ -15,7 +17,7 @@ function add(x, y){
y: y,
dy: .3
});
};
}

function update(dTime){
for(var n = 0; n < bullets.length; ++n)
Expand All @@ -32,11 +34,16 @@ function update(dTime){
if(collision.Scorpion(scorpion.pos(), bullets[n]) && scorpion.visible())
{
bullets.splice(n--, 1);
--n;
scorpion.hide();
playa.addScore(30);
continue;
}
if(collision.Flea(flea.pos(), bullets[n]) && flea.visible()){
console.log("flea collision");
bullets.splice(n--, 1);
flea.hide();
continue;
}

var centipeed = peed.getPeed();
var ind = collision.Peed(bullets[n], centipeed);
Expand Down
6 changes: 4 additions & 2 deletions client/collision.js
@@ -1,3 +1,4 @@
var spider = require('./spider'), flea = require('./flea');
function collides(obj1, obj2){
if(obj2.x + obj2.width > obj1.x && obj2.x < obj1.x + obj1.width)
if(obj2.y + obj2.height > obj1.y && obj2.y < obj1.y + obj1.height)
Expand Down Expand Up @@ -65,8 +66,8 @@ function checkPoison(mushrooms, poison, scorpion){
}
};

function isDead(spider, thisChar){
return (collides(spider, thisChar) && spider.visible);
function isDead(thisChar){
return (collides(spider.pos(), thisChar) && spider.visible || collides(flea.pos(), thisChar) && flea.visible);
};

function cantMove(mushrooms, thisChar){
Expand All @@ -81,6 +82,7 @@ exports.Mush = Mush;
exports.Poison = Poison;
exports.Spider = collides;
exports.Scorpion = collides;
exports.Flea = collides;
exports.Peed = Peed
exports.checkPoison = checkPoison;
exports.isDead = isDead;
Expand Down
92 changes: 92 additions & 0 deletions client/flea.js
@@ -0,0 +1,92 @@
var flea;
function init(){
flea = {
dir: "right",
visible: true,
deathTimer: 0,
time: 0,
width: 20,
height: 20,
x: Math.floor(Math.random() * 25) * 20,
y: 550,
dx: .1,
dy: .1
};
}
//to place a mushroom send in Math.floor x / 20 and y /20;

function update(dTime){
flea.x += flea.dx * dTime;
flea.y += flea.dy * dTime;
flea.time += dTime;

if (flea.x < 0) {
flea.x = 0;
flea.dx *= -1;
}

if (flea.x > 500 - flea.width) {
flea.x = 500 - flea.width;
flea.dx *= -1;
}

if (flea.y > 700 - flea.height) {
flea.y = 700 - flea.height;
flea.dy *= -1;
}

if (flea.y < 550) {
flea.y = 550;
flea.dy *= -1;
}

if (flea.time >= 2000) {
flea.time = 0;
flea.dx = (Math.random() * .2) - .1;
flea.dy = (Math.random() * .2) - .1;
}

if (!flea.visible) {
flea.deathTimer += dTime;
if (flea.deathTimer >= 10000) {
flea.visible = true;
flea.deathTimer = 0;
flea.y = 350;
flea.x = Math.floor(Math.random() * (500 - flea.width));
}
}

// if (flea.visible && flea.hungry >= 5000) {
// var tileX = Math.floor(flea.x / 20) + 1;
// var tileY = Math.floor(flea.y / 20) + 1;
// if (shrooms.existsAt(tileX, tileY)) {
// shrooms.eatAt(tileX, tileY);
// flea.hungry = 0;
// }
//}
};

function render(ctx, g){
if(flea.visible)
g.drawFlea(ctx, flea.dir, flea.x, flea.y);
};

function pos(){
return{x: flea.x, y: flea.y, width: flea.width, height: flea.height};
}

function hide(){
flea.visible = false;
}

function visible(){
return flea.visible;
}


exports.init = init;
exports.update = update;
exports.render = render;
exports.pos = pos;
exports.hide = hide;
exports.visible = visible;
8 changes: 8 additions & 0 deletions client/graphics.js
Expand Up @@ -41,6 +41,13 @@ function drawScorpion(LtoR, ctx, x, y){
ctx.drawImage(spriteSheet, 300, 0, 50, 50, x, y, 20, 20);
}

function drawFlea(ctx, dir, x, y){
if(dir == 'right')
ctx.drawImage(spriteSheet, 350, 150, 50, 50, x, y, 20, 20);
if(dir == 'left')
ctx.drawImage(spriteSheet, 400, 150, 50, 50, x, y, 20, 20);
};

function drawPeed(ctx, isHead, RtoL, x, y, state) {
if (RtoL) {
if (isHead)
Expand All @@ -64,4 +71,5 @@ exports.drawMushrooms = drawMushrooms;
exports.drawSpider = drawSpider;
exports.drawScorpion = drawScorpion;
exports.drawPeed = drawPeed;
exports.drawFlea = drawFlea;
exports.init = init;
9 changes: 5 additions & 4 deletions client/playa.js
Expand Up @@ -49,10 +49,11 @@ function update(dTime){
snd.playEffect('shoot');
bullets.add(player.x, player.y);
}
// if (collision.isDead(spider, player)) {
// players[n].x = 0;
// players[n].y = 650;
// }

if (collision.isDead(player)) {
player.x = 0;
player.y = 650;
}
}

function render(ctx, g){
Expand Down
3 changes: 3 additions & 0 deletions client/states/game.js
Expand Up @@ -22,6 +22,7 @@ function start() {
scorpion.init();
centipede.init();
shrooms.init();
flea.init();
}

function stop() {
Expand All @@ -36,6 +37,7 @@ function update(dTime){
spider.update(dTime);
scorpion.update(dTime);
centipede.update(dTime);
flea.update(dTime);
};


Expand All @@ -48,6 +50,7 @@ function render(ctx){
spider.render(ctx, g);
scorpion.render(ctx, g);
centipede.render(ctx, g);
flea.render(ctx, g);
};

exports.start = start;
Expand Down
Binary file modified public/img/spriteSheet.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e49980c

Please sign in to comment.