messages draw on canvas

+ bugfix: vector.assign() Uncaught TypeError
This commit is contained in:
LuckyLaszlo
2022-11-28 04:40:03 +01:00
parent 7f248b5449
commit 5325c8b9ee
7 changed files with 48 additions and 27 deletions

View File

@@ -7,7 +7,7 @@ class Rectangle implements Component {
width: number;
height: number;
constructor(pos: VectorInteger, width: number, height: number) {
this.pos = Object.assign({}, pos);
this.pos = new VectorInteger(pos.x, pos.y);
this.width = width;
this.height = height;
}
@@ -49,12 +49,10 @@ class MovingRectangle extends Rectangle implements Moving {
this.pos.y += Math.floor(this.dir.y * this.speed * delta);
}
moveAndCollide(delta: number, colliderArr: Rectangle[]) {
let oldPos = Object.assign({}, this.pos);
let oldPos = new VectorInteger(this.pos.x, this.pos.y);
this.move(delta);
if (colliderArr.some(this.collision, this))
{
this.pos.x = oldPos.x;
this.pos.y = oldPos.y;
if (colliderArr.some(this.collision, this)) {
this.pos = oldPos;
}
}
}