Ive made a Flappy bird Clone. It works fine when i play in normal screen mode. (1920×1080). However, when i play in potrait mode, my Array is getting a 'undefined' Error.
I tought theres a problem, since i use windowHeight and windowWidth. Iam doing it in the p5 framework.
this.hits = function (bird) {
if (bird.y < this.top || bird.y > windowHeight - this.bottom) {
if (bird.x > this.x && bird.x < this.x + this.w) {
return true;
}
}
return false;
}
Here are the used variables: (not actual code)
Bird:
bird.y = windowHeight/2;
bird.x = windowWidth*0.2;
Pipes:
var pipeSpace = random(250,600);
var centerY = random(0,windowHeight/3.5);
pipes.top = centerY - pipeSpace/2;
pipes.bottom = windowHeight - centerY - (centerY + pipeSpace/2);
pipes.x = windowWidth*1.5; (this is the x position(starting position) of the pipes)
this.w = 40; (this is the width of the pipes)
This function gets called every frame, to see if a collision is happening, but after i pass the first "pipe", the game breaks and says the error said above.
Edit: the Error: pipes[i] is undefined
this is the part where it occurs: Theres actually more code, but it has nothing to do with my problem.
var pipes = [];
function setup() {
bird = new Bird();
pipes.push(new Pipe());
}
function draw(){
for (var i = pipes.length-1; i >= 0; i--){
if(pipes[i].hits(bird)){
gameOver = true;
}
}
}