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;
|
||||
|
||||
function setup() {
|
||||
createCanvas(1000, 1000);
|
||||
obstacleOffset = width / 4;
|
||||
|
||||
raspberry = new Raspberry();
|
||||
|
||||
obstacle = new Obstacle(
|
||||
new Pipe(new Position(width, 0), 32, height),
|
||||
new Pipe(new Position(width, height - (height / 3)), 32, height),
|
||||
);
|
||||
obstacles.push(new Obstacle(
|
||||
new Pipe(new Position(width, 0), obstacleWidth, 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() {
|
||||
background(187)
|
||||
raspberry.draw();
|
||||
raspberry.update();
|
||||
|
||||
obstacles.forEach((obstacle) => {
|
||||
obstacle.draw();
|
||||
obstacle.update();
|
||||
|
||||
if (obstacle.position.x < 0) {
|
||||
if(obstacle.position.x < -obstacleWidth) {
|
||||
obstacle.resetPosition();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue