wosn do los
This commit is contained in:
parent
04ef8a872d
commit
43390fe7ce
5 changed files with 32 additions and 10 deletions
|
|
@ -1,13 +1,19 @@
|
||||||
|
let obstacle: Obstacle;
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
createCanvas(400, 400)
|
createCanvas(400, 400)
|
||||||
background(187)
|
background(187)
|
||||||
line(0,0, 400,400)
|
line(0,0, 400,400)
|
||||||
|
|
||||||
|
obstacle = new Obstacle(new Pipe(new Position(width, 0), 20, 50, 0), new Pipe(new Position(width, 300), 20, 50, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
|
background(187)
|
||||||
}
|
// obstacle.draw()
|
||||||
|
// obstacle.update()
|
||||||
function keyPressed() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
// function keyPressed() {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
@ -35,7 +35,7 @@ abstract class Entity {
|
||||||
this._fill = fill;
|
this._fill = fill;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract update();
|
public abstract update(): void;
|
||||||
public draw() {
|
public draw() {
|
||||||
fill(this._fill);
|
fill(this._fill);
|
||||||
rect(this.position.x, this.position.y, this.width, this.height);
|
rect(this.position.x, this.position.y, this.width, this.height);
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,17 @@
|
||||||
class Obstacle {
|
class Obstacle extends Entity {
|
||||||
private pipeTop: Entity;
|
private pipeTop: Entity;
|
||||||
private pipeBottom: Entity;
|
private pipeBottom: Entity;
|
||||||
private distanceBetweenPipes: number;
|
private distanceBetweenPipes: number = 50;
|
||||||
private padding: number;
|
private padding: number = 50;
|
||||||
private speed: number;
|
private speed: number = 10;
|
||||||
private static startX: number;
|
private static startX: number;
|
||||||
|
|
||||||
|
constructor(pipeTop: Entity, pipeBottom: Entity) {
|
||||||
|
super(pipeTop.position, pipeTop.width, height, 0);
|
||||||
|
this.pipeTop = pipeTop;
|
||||||
|
this.pipeBottom = pipeBottom;
|
||||||
|
}
|
||||||
|
|
||||||
private resetPosition(){
|
private resetPosition(){
|
||||||
let randomY = Math.random() * (height - this.padding) + this.padding;
|
let randomY = Math.random() * (height - this.padding) + this.padding;
|
||||||
|
|
||||||
|
|
|
||||||
5
frontend/models/Pipe.ts
Normal file
5
frontend/models/Pipe.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
class Pipe extends Entity {
|
||||||
|
update() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -17,4 +17,9 @@ class Position {
|
||||||
set y(value: number) {
|
set y(value: number) {
|
||||||
this._y = value;
|
this._y = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor(x: number, y: number) {
|
||||||
|
this._x = x;
|
||||||
|
this._y = y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue