multiple obstacles spawning
This commit is contained in:
parent
8e19fb7cfb
commit
4d22976621
1 changed files with 29 additions and 10 deletions
|
|
@ -1,27 +1,46 @@
|
||||||
let obstacle: Obstacle;
|
const obstacleWidth: number = 42;
|
||||||
|
let obstacleOffset: number;
|
||||||
|
|
||||||
|
let obstacles: Obstacle[] = [];
|
||||||
let raspberry: Raspberry;
|
let raspberry: Raspberry;
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
createCanvas(1000, 1000);
|
createCanvas(1000, 1000);
|
||||||
|
obstacleOffset = width / 4;
|
||||||
|
|
||||||
raspberry = new Raspberry();
|
raspberry = new Raspberry();
|
||||||
|
|
||||||
obstacle = new Obstacle(
|
obstacles.push(new Obstacle(
|
||||||
new Pipe(new Position(width, 0), 32, height),
|
new Pipe(new Position(width, 0), obstacleWidth, height),
|
||||||
new Pipe(new Position(width, height - (height / 3)), 32, height),
|
new Pipe(new Position(width, height - (height / 3)), obstacleWidth, height),
|
||||||
);
|
));
|
||||||
|
obstacles.push(new Obstacle(
|
||||||
|
new Pipe(new Position(width + obstacleOffset, 0), obstacleWidth, height),
|
||||||
|
new Pipe(new Position(width + obstacleOffset, height - (height / 3)), obstacleWidth, height)
|
||||||
|
));
|
||||||
|
obstacles.push(new Obstacle(
|
||||||
|
new Pipe(new Position(width + obstacleOffset * 2, 0), obstacleWidth, height),
|
||||||
|
new Pipe(new Position(width + obstacleOffset * 2, height - (height / 3)), obstacleWidth, height)
|
||||||
|
));
|
||||||
|
obstacles.push(new Obstacle(
|
||||||
|
new Pipe(new Position(width + obstacleOffset * 3, 0), obstacleWidth, height),
|
||||||
|
new Pipe(new Position(width + obstacleOffset * 3, height - (height / 3)), obstacleWidth, height)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
background(187)
|
background(187)
|
||||||
raspberry.draw();
|
raspberry.draw();
|
||||||
raspberry.update();
|
raspberry.update();
|
||||||
obstacle.draw();
|
|
||||||
obstacle.update();
|
|
||||||
|
|
||||||
if (obstacle.position.x < 0) {
|
obstacles.forEach((obstacle) => {
|
||||||
obstacle.resetPosition();
|
obstacle.draw();
|
||||||
}
|
obstacle.update();
|
||||||
|
|
||||||
|
if(obstacle.position.x < -obstacleWidth) {
|
||||||
|
obstacle.resetPosition();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue