-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: Create force folder to keep different types of forces
- Loading branch information
1 parent
d33621b
commit 0b103ed
Showing
7 changed files
with
101 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { CanvasObject } from "@/simulator/object"; | ||
import type { SupportForce } from "./supportForce"; | ||
|
||
import { Force, type IForce } from "@/simulator/force"; | ||
|
||
interface IFrictionForce extends IForce { | ||
origin: CanvasObject | ||
} | ||
|
||
export class FrictionForce extends Force implements IFrictionForce { | ||
public origin: CanvasObject; | ||
|
||
private readonly _maxStaticFrictionSize: number; | ||
|
||
private constructor(support: SupportForce, private readonly friction: number) { | ||
super(0, 0); | ||
|
||
this.origin = support.origin; | ||
this._maxStaticFrictionSize = support.length * this.friction; | ||
} | ||
|
||
public override update(self: CanvasObject) { | ||
super.update(self); | ||
|
||
/** @todo */ | ||
} | ||
|
||
/** @deprecated */ | ||
public static override from(_arg: never): never { | ||
throw new Error("Cannot create a friction force via from()."); | ||
} | ||
|
||
public static create(support: SupportForce, friction: number): FrictionForce { | ||
return new FrictionForce(support, friction); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { Vector } from "@/simulator/vector"; | ||
import type { CanvasObject } from "@/simulator/object"; | ||
|
||
import { Force, type IForce } from "@/simulator/force"; | ||
import { Ground } from "@/simulator/objects/ground"; | ||
import { Ball } from "@/simulator/objects/ball"; | ||
import { Block } from "@/simulator/objects/block"; | ||
|
||
interface ISupportForce extends IForce { | ||
origin: CanvasObject | ||
} | ||
|
||
export class SupportForce extends Force implements ISupportForce { | ||
|
||
private constructor(x: number, y: number, public origin: CanvasObject) { | ||
super(x, y); | ||
} | ||
|
||
public override update(self: CanvasObject) { | ||
super.update(self); | ||
|
||
if(self instanceof Ball) { | ||
if(this.origin instanceof Ground && self.obj.y < self.render.canvas.height - Ground.GROUND_HEIGHT - self.radius) { | ||
self.forces.removeForce(this); | ||
} | ||
} else if(self instanceof Block) { | ||
if(this.origin instanceof Ground && self.obj.y < self.render.canvas.height - Ground.GROUND_HEIGHT - self.size) { | ||
self.forces.removeForce(this); | ||
} | ||
} | ||
} | ||
|
||
public static override from(vector: Force | Vector, origin?: CanvasObject): SupportForce { | ||
if(!origin) throw new Error("Cannot create a support force without providing the origin object."); | ||
|
||
return new SupportForce(vector.x, vector.y, origin); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters