Skip to content

Commit

Permalink
improved obstacles
Browse files Browse the repository at this point in the history
  • Loading branch information
lundstrj committed Feb 22, 2012
1 parent 4f8e081 commit 61eceff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
4 changes: 4 additions & 0 deletions copter.js
Expand Up @@ -53,6 +53,10 @@ Copter.prototype.moveTo = function(x, y) {
}

Copter.prototype.getHeight = function() {
console.log("copter.getHeight is depricated. Use getLowerHeight instead");
return constants.HEIGHT - this.y - 56;
}
Copter.prototype.getLowerHeight = function() {
return constants.HEIGHT - this.y - 56;
}

Expand Down
10 changes: 5 additions & 5 deletions obstacle.js
@@ -1,10 +1,10 @@
exports.Obstacle = Obstacle;

function Obstacle(x,y) {
this.height = 5;
this.width = 5;
this.x = x
this.y = y
function Obstacle(y,exist) {
this.exist = exist;
this.height = 10;
this.width = 10;
this.y = y;
}

Obstacle.prototype.update = function() {
Expand Down
18 changes: 6 additions & 12 deletions world.js
Expand Up @@ -5,33 +5,25 @@ var constants = sp.require("constants");
var box = sp.require("box");
var spectrum = sp.require('spectrum');
var bands = spectrum.BAND10;
var obstacle = sp.require('obstacle')
var obstacle = sp.require('obstacle');

function World() {
this.upper = new Array();
this.lower = new Array();
this.lastSounds = new Array();
this.lastSum = 0;
this.songBPM = constants.DEFAULT_BPM;

this.obstacles = new Array();
for(var i = 0; i<constants.STEPS; ++i) {
this.upper[i] = new box.Box(5);
this.lower[i] = new box.Box(5);
if (i % 50 == 0){
this.obstacles[i] = new obstacle.Obstacle(400,180);
}
else{
this.obstacles[i] = new obstacle.Obstacle(0,0);
}
this.obstacles[i] = new obstacle.Obstacle(0,false);
}

this.mapGeneratorValue = 0;
this.upperDB = 0;
this.offset = 0;
this.lightningEffectValue = 0;
this.amplitude = 1;

this.sinoffset = 0;

console.log("adding event handler");
Expand Down Expand Up @@ -133,8 +125,8 @@ World.prototype.render = function(context) {
context.fillStyle = "rgb("+red+","+green+","+blue+")";
context.fillRect(dx*i,0,dx, this.upper[i].height);
context.fillRect(dx*i,constants.HEIGHT-this.lower[i].height,dx,this.lower[i].height);
if ((i % 50) == 0){
context.fillRect(dx*i,180,5,5)
if (this.obstacles[i].exist) {
context.fillRect(dx*i,this.obstacles[i].y, this.obstacles[i].width, this.obstacles[i].height);
}
}
}
Expand Down Expand Up @@ -176,8 +168,10 @@ World.prototype.fetchValues = function() {
// update values
delete this.upper.shift();
delete this.lower.shift();
delete this.obstacles.shift();
this.upper.push(newUpper);
this.lower.push(newLower);
this.obstacles.push(newObstacle);

// console.log("lower len: "+this.lower.length);
}
Expand Down

0 comments on commit 61eceff

Please sign in to comment.