added images
pipes and background now have images
This commit is contained in:
parent
f272d3a44f
commit
d43cfbe9e7
6 changed files with 74 additions and 38 deletions
|
|
@ -1,35 +1,47 @@
|
||||||
|
const pipeImagePath: string = "resources/raspberry-low-res.png";
|
||||||
const obstacleWidth: number = 42;
|
const obstacleWidth: number = 42;
|
||||||
let obstacleOffset: number;
|
let obstacleOffset: number;
|
||||||
|
|
||||||
|
const backgroundImagePath: string = "resources/raspberry-low-res.png";
|
||||||
|
let backgroundImage: any;
|
||||||
|
|
||||||
let obstacles: Obstacle[] = [];
|
let obstacles: Obstacle[] = [];
|
||||||
let raspberry: Raspberry;
|
let raspberry: Raspberry;
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
|
backgroundImage = loadImage(backgroundImagePath);
|
||||||
|
|
||||||
createCanvas(1000, 1000);
|
createCanvas(1000, 1000);
|
||||||
obstacleOffset = width / 4;
|
obstacleOffset = width / 4;
|
||||||
|
|
||||||
raspberry = new Raspberry();
|
raspberry = new Raspberry();
|
||||||
|
|
||||||
obstacles.push(new Obstacle(
|
obstacles.push(new Obstacle(
|
||||||
new Pipe(new Position(width, 0), obstacleWidth, height),
|
new Pipe(width, obstacleWidth, height),
|
||||||
new Pipe(new Position(width, height - (height / 3)), obstacleWidth, height),
|
new Pipe(width, obstacleWidth, height),
|
||||||
|
pipeImagePath
|
||||||
));
|
));
|
||||||
obstacles.push(new Obstacle(
|
obstacles.push(new Obstacle(
|
||||||
new Pipe(new Position(width + obstacleOffset, 0), obstacleWidth, height),
|
new Pipe(width + obstacleOffset, obstacleWidth, height),
|
||||||
new Pipe(new Position(width + obstacleOffset, height - (height / 3)), obstacleWidth, height)
|
new Pipe(width + obstacleOffset, obstacleWidth, height),
|
||||||
|
pipeImagePath
|
||||||
));
|
));
|
||||||
obstacles.push(new Obstacle(
|
obstacles.push(new Obstacle(
|
||||||
new Pipe(new Position(width + obstacleOffset * 2, 0), obstacleWidth, height),
|
new Pipe(width + obstacleOffset * 2, obstacleWidth, height),
|
||||||
new Pipe(new Position(width + obstacleOffset * 2, height - (height / 3)), obstacleWidth, height)
|
new Pipe(width + obstacleOffset * 2, obstacleWidth, height),
|
||||||
|
pipeImagePath
|
||||||
));
|
));
|
||||||
obstacles.push(new Obstacle(
|
obstacles.push(new Obstacle(
|
||||||
new Pipe(new Position(width + obstacleOffset * 3, 0), obstacleWidth, height),
|
new Pipe(width + obstacleOffset * 3, obstacleWidth, height),
|
||||||
new Pipe(new Position(width + obstacleOffset * 3, height - (height / 3)), obstacleWidth, height)
|
new Pipe(width + obstacleOffset * 3, obstacleWidth, height),
|
||||||
|
pipeImagePath
|
||||||
));
|
));
|
||||||
|
|
||||||
|
obstacles.forEach((obstacle) => obstacle.resetPosition(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
background(187)
|
background(backgroundImage)
|
||||||
raspberry.draw();
|
raspberry.draw();
|
||||||
raspberry.update();
|
raspberry.update();
|
||||||
|
|
||||||
|
|
@ -38,7 +50,7 @@ function draw() {
|
||||||
obstacle.update();
|
obstacle.update();
|
||||||
|
|
||||||
if(obstacle.position.x < -obstacleWidth) {
|
if(obstacle.position.x < -obstacleWidth) {
|
||||||
obstacle.resetPosition();
|
obstacle.resetPosition(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,38 @@
|
||||||
class Obstacle extends Entity {
|
class Obstacle extends Entity {
|
||||||
private pipeTop: Entity;
|
private pipeTop: Pipe;
|
||||||
private pipeBottom: Entity;
|
private pipeBottom: Pipe;
|
||||||
private distanceBetweenPipes: number;
|
private distanceBetweenPipes: number;
|
||||||
private padding: number = 300;
|
private padding: number = 300;
|
||||||
private speed: number = 8;
|
private speed: number = 8;
|
||||||
|
|
||||||
private static startX: number;
|
private static startX: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the Obstacle using the top and bottom Pipe
|
* Constructs the Obstacle using the top and bottom Pipe
|
||||||
* (fill is not used here)
|
* (fill is not used here)
|
||||||
* @param pipeTop
|
|
||||||
* @param pipeBottom
|
|
||||||
*/
|
*/
|
||||||
constructor(pipeTop: Entity, pipeBottom: Entity) {
|
constructor(pipeTop: Pipe, pipeBottom: Pipe, pipeImagePath: string) {
|
||||||
super(pipeTop.position, pipeTop.width, pipeBottom.height, 0);
|
super(pipeTop.position, pipeTop.width, pipeBottom.height, 0);
|
||||||
this.pipeTop = pipeTop;
|
this.pipeTop = pipeTop;
|
||||||
this.pipeBottom = pipeBottom;
|
this.pipeBottom = pipeBottom;
|
||||||
|
this.pipeTop.image = pipeImagePath;
|
||||||
|
this.pipeBottom.image = pipeImagePath;
|
||||||
|
|
||||||
this.distanceBetweenPipes = height / 4;
|
this.distanceBetweenPipes = height / 4;
|
||||||
Obstacle.startX = width;
|
Obstacle.startX = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public resetPosition(): void {
|
public resetPosition(resetX: boolean): void {
|
||||||
this.pipeBottom.position.y = this.distanceBetweenPipes + this.randomRange(0, height - this.padding - 1.2 * this.distanceBetweenPipes);
|
this.pipeBottom.position.y =
|
||||||
this.pipeBottom.position.x = Obstacle.startX;
|
this.distanceBetweenPipes + this.randomRange(0, height - this.padding - 1.2 * this.distanceBetweenPipes);
|
||||||
|
|
||||||
this.pipeTop.position.y = this.pipeBottom.position.y - this.distanceBetweenPipes - this.pipeTop.height;
|
this.pipeTop.position.y =
|
||||||
this.pipeTop.position.x = Obstacle.startX;
|
this.pipeBottom.position.y - this.distanceBetweenPipes - this.pipeTop.height;
|
||||||
|
|
||||||
|
if(resetX){
|
||||||
|
this.pipeBottom.position.x = Obstacle.startX;
|
||||||
|
this.pipeTop.position.x = Obstacle.startX;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private randomRange(min: number, max: number): number {
|
private randomRange(min: number, max: number): number {
|
||||||
|
|
@ -39,18 +45,8 @@ class Obstacle extends Entity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public draw(): void {
|
public draw(): void {
|
||||||
fill(10, 200, 100); //TODO do not make static
|
noFill();
|
||||||
rect(
|
this.pipeTop.draw();
|
||||||
this.pipeTop.position.x,
|
this.pipeBottom.draw();
|
||||||
this.pipeTop.position.y,
|
|
||||||
this.pipeTop.width,
|
|
||||||
this.pipeTop.height
|
|
||||||
);
|
|
||||||
rect(
|
|
||||||
this.pipeBottom.position.x,
|
|
||||||
this.pipeBottom.position.y,
|
|
||||||
this.pipeBottom.width,
|
|
||||||
this.pipeBottom.height
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,8 +1,31 @@
|
||||||
class Pipe extends Entity {
|
class Pipe extends Entity {
|
||||||
constructor(position: Position, width: number, height: number) {
|
private _image: any;
|
||||||
super(position, width, height, 0);
|
|
||||||
|
//region Getter & Setter
|
||||||
|
get image() {
|
||||||
|
return this._image;
|
||||||
}
|
}
|
||||||
|
|
||||||
public update(): void {
|
set image(path: string) {
|
||||||
|
this._image = loadImage(path);
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
constructor(positionX: number, width: number, height: number) {
|
||||||
|
super(new Position(positionX, 0), width, height, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public update(): void {}
|
||||||
|
|
||||||
|
public draw(): void {
|
||||||
|
// @ts-ignore
|
||||||
|
image(this.image, this.position.x, this.position.y, this.width, this.height);
|
||||||
|
noFill();
|
||||||
|
rect(
|
||||||
|
this.position.x,
|
||||||
|
this.position.y,
|
||||||
|
this.width,
|
||||||
|
this.height
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BIN
frontend/resources/raspberry-low-res.png
Normal file
BIN
frontend/resources/raspberry-low-res.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 99 KiB |
BIN
frontend/resources/raspberry-rocket.png
Normal file
BIN
frontend/resources/raspberry-rocket.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 586 KiB |
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"module": "none",
|
"module": "ES2020",
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"outFile": "./build/build.js",
|
"outFile": "./build/build.js",
|
||||||
"preserveConstEnums": true,
|
"preserveConstEnums": true,
|
||||||
|
|
@ -8,6 +8,11 @@
|
||||||
"rootDir": ".",
|
"rootDir": ".",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
"moduleResolution": "node"
|
"moduleResolution": "node",
|
||||||
|
"lib": [
|
||||||
|
"dom",
|
||||||
|
"es5",
|
||||||
|
"scripthost"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue