RaspberryRocketeer/frontend/model/Entity.ts
2023-01-10 08:45:34 +01:00

65 lines
1.4 KiB
TypeScript

abstract class Entity {
private _position: Position;
private _width: number;
private _height: number;
private fill: number;
private _showHitbox: boolean;
//region Getter & Setter
get position(): Position {
return this._position;
}
set position(value: Position) {
this._position = value;
}
get width(): number {
return this._width;
}
set width(value: number) {
this._width = value;
}
get height(): number {
return this._height;
}
set height(value: number) {
this._height = value;
}
get showHitbox(): boolean {
return this._showHitbox;
}
set showHitbox(value: boolean) {
this._showHitbox = value;
}
//endregion
/**
* Constructs the Entity
* @param position starting Position
* @param width entity width
* @param height entity height
* @param fill fill color
*/
protected constructor(position: Position, width: number, height: number, fill: number) {
this.position = position;
this.width = width;
this.height = height;
this.fill = fill;
this._showHitbox = false;
}
public abstract update(): void;
public draw(): void {
push();
fill(this.fill);
rect(this.position.x, this.position.y, this.width, this.height);
pop();
}
}