added images

pipes and background now have images
This commit is contained in:
dhain 2022-12-06 11:33:45 +01:00
parent f272d3a44f
commit d43cfbe9e7
6 changed files with 74 additions and 38 deletions

View file

@ -1,35 +1,47 @@
const pipeImagePath: string = "resources/raspberry-low-res.png";
const obstacleWidth: number = 42;
let obstacleOffset: number;
const backgroundImagePath: string = "resources/raspberry-low-res.png";
let backgroundImage: any;
let obstacles: Obstacle[] = [];
let raspberry: Raspberry;
function setup() {
backgroundImage = loadImage(backgroundImagePath);
createCanvas(1000, 1000);
obstacleOffset = width / 4;
raspberry = new Raspberry();
obstacles.push(new Obstacle(
new Pipe(new Position(width, 0), obstacleWidth, height),
new Pipe(new Position(width, height - (height / 3)), obstacleWidth, height),
new Pipe(width, obstacleWidth, height),
new Pipe(width, obstacleWidth, height),
pipeImagePath
));
obstacles.push(new Obstacle(
new Pipe(new Position(width + obstacleOffset, 0), obstacleWidth, height),
new Pipe(new Position(width + obstacleOffset, height - (height / 3)), obstacleWidth, height)
new Pipe(width + obstacleOffset, obstacleWidth, height),
new Pipe(width + obstacleOffset, obstacleWidth, height),
pipeImagePath
));
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)
new Pipe(width + obstacleOffset * 2, obstacleWidth, height),
new Pipe(width + obstacleOffset * 2, obstacleWidth, height),
pipeImagePath
));
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)
new Pipe(width + obstacleOffset * 3, obstacleWidth, height),
new Pipe(width + obstacleOffset * 3, obstacleWidth, height),
pipeImagePath
));
obstacles.forEach((obstacle) => obstacle.resetPosition(false));
}
function draw() {
background(187)
background(backgroundImage)
raspberry.draw();
raspberry.update();
@ -38,7 +50,7 @@ function draw() {
obstacle.update();
if(obstacle.position.x < -obstacleWidth) {
obstacle.resetPosition();
obstacle.resetPosition(true);
}
});
}