diff --git a/frontend/game.ts b/frontend/game.ts index fdeda1b..cfa2b5c 100644 --- a/frontend/game.ts +++ b/frontend/game.ts @@ -1,13 +1,19 @@ +let obstacle: Obstacle; + function setup() { createCanvas(400, 400) background(187) 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() { - + background(187) + // obstacle.draw() + // obstacle.update() } - -function keyPressed() { - -} \ No newline at end of file +// +// function keyPressed() { +// +// } \ No newline at end of file diff --git a/frontend/models/Entity.ts b/frontend/models/Entity.ts index b753b28..9108ef4 100644 --- a/frontend/models/Entity.ts +++ b/frontend/models/Entity.ts @@ -35,7 +35,7 @@ abstract class Entity { this._fill = fill; } - public abstract update(); + public abstract update(): void; public draw() { fill(this._fill); rect(this.position.x, this.position.y, this.width, this.height); diff --git a/frontend/models/Obstacle.ts b/frontend/models/Obstacle.ts index ebbe0f9..4ab8a10 100644 --- a/frontend/models/Obstacle.ts +++ b/frontend/models/Obstacle.ts @@ -1,11 +1,17 @@ -class Obstacle { +class Obstacle extends Entity { private pipeTop: Entity; private pipeBottom: Entity; - private distanceBetweenPipes: number; - private padding: number; - private speed: number; + private distanceBetweenPipes: number = 50; + private padding: number = 50; + private speed: number = 10; private static startX: number; + constructor(pipeTop: Entity, pipeBottom: Entity) { + super(pipeTop.position, pipeTop.width, height, 0); + this.pipeTop = pipeTop; + this.pipeBottom = pipeBottom; + } + private resetPosition(){ let randomY = Math.random() * (height - this.padding) + this.padding; diff --git a/frontend/models/Pipe.ts b/frontend/models/Pipe.ts new file mode 100644 index 0000000..a86bec0 --- /dev/null +++ b/frontend/models/Pipe.ts @@ -0,0 +1,5 @@ +class Pipe extends Entity { + update() { + + } +} \ No newline at end of file diff --git a/frontend/models/Position.ts b/frontend/models/Position.ts index 72d19bc..99ca835 100644 --- a/frontend/models/Position.ts +++ b/frontend/models/Position.ts @@ -17,4 +17,9 @@ class Position { set y(value: number) { this._y = value; } + + constructor(x: number, y: number) { + this._x = x; + this._y = y; + } } \ No newline at end of file