Add basic gameobject system
This commit is contained in:
parent
d5be727040
commit
efb01476b2
33 changed files with 399 additions and 171 deletions
|
|
@ -13,6 +13,10 @@ export class Vec2 extends Typed {
|
|||
return new Vec2(this.x * scalar, this.y * scalar);
|
||||
}
|
||||
|
||||
public times(other: Vec2): Vec2 {
|
||||
return new Vec2(this.x * other.x, this.y * other.y);
|
||||
}
|
||||
|
||||
public add(other: Vec2): Vec2 {
|
||||
return new Vec2(this.x + other.x, this.y + other.y);
|
||||
}
|
||||
|
|
@ -21,6 +25,21 @@ export class Vec2 extends Typed {
|
|||
return new Vec2(this.x - other.x, this.y - other.y);
|
||||
}
|
||||
|
||||
public get length(): number {
|
||||
return Math.sqrt(this.x * this.x + this.y * this.y);
|
||||
}
|
||||
|
||||
public get normalized(): Vec2 {
|
||||
return this.scale(1 / this.length);
|
||||
}
|
||||
|
||||
public get clamped_0_1(): Vec2 {
|
||||
return new Vec2(
|
||||
Math.min(1, Math.max(0, this.x)),
|
||||
Math.min(1, Math.max(0, this.y))
|
||||
);
|
||||
}
|
||||
|
||||
public get list(): [number, number] {
|
||||
return [this.x, this.y];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue