You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

54 lines
1.3 KiB

"use strict"
class Background{
constructor(world){
this.yScale = height * 0.4;
this.backScale = int(values.backgroundMoveScale);
}
update(){
this.viewPort();
}
display(){
this.show();
}
viewPort(){
this.mountainPoints = [];
this.groundPoints = [];
this.yOff = height / 2 - (viewPort.y / game.world.dim.y - 0.5) * height / 2;
for (let x = 0; x < width; x++){
let y = noise(x / 100 + viewPort.x / this.backScale) - 0.5;
this.mountainPoints.push({x: x, y: y * this.yScale + this.yOff});
this.groundPoints.push({x: x, y: y * this.yScale * 0.1 + this.yOff + this.yScale / 2});
}
}
show(){
//Sky
background(colors.background.sky);
//Mountains
strokeWeight(2);
stroke(colors.background.mountains.stroke);
fill(colors.background.mountains.fill)
beginShape();
for (let p of this.mountainPoints) vertex(p.x, p.y);
vertex(width, height);
vertex(0, height);
vertex(0, this.mountainPoints[0].y);
endShape();
//Ground
fill(colors.background.ground);
beginShape();
for (let p of this.groundPoints) vertex(p.x, p.y);
vertex(width, height);
vertex(0, height);
vertex(0, this.groundPoints[0].y);
endShape();
}
}