-
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.
- Loading branch information
1 parent
fff6e9a
commit 91ad0df
Showing
5 changed files
with
130 additions
and
88 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
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,52 @@ | ||
import { Entity } from "./ecs"; | ||
import { | ||
PositionComponent, | ||
VelocityComponent, | ||
ForceComponent, | ||
FrictionComponent, | ||
MassComponent, | ||
AccumulatedForceComponent, | ||
} from "./components"; | ||
import { DOMComponent, MouseDragComponent } from "./dom"; | ||
|
||
// Define BoxEntity to represent a box that can be dragged | ||
export class BoxEntity extends Entity { | ||
constructor( | ||
domElement: HTMLElement, | ||
initialPositon: { x: number; y: number }, | ||
name?: string, | ||
initialVelocity: { vx: number; vy: number } = { vx: 0, vy: 0 }, | ||
mass: number = 1, | ||
friction: number = 0.05, | ||
) { | ||
super(); | ||
|
||
this.name = name; | ||
this.addComponent( | ||
new PositionComponent(initialPositon.x, initialPositon.y), | ||
); // Initial position | ||
this.addComponent( | ||
new VelocityComponent(initialVelocity.vx, initialVelocity.vy), | ||
); // Initial velocity | ||
this.addComponent(new MassComponent(mass)); // Mass of the entity | ||
this.addComponent(new ForceComponent()); // Force acting on the entity | ||
this.addComponent(new AccumulatedForceComponent()); // Force acting on the entity | ||
this.addComponent(new MouseDragComponent()); // Component for mouse dragging | ||
this.addComponent(new FrictionComponent(friction)); // Friction acting on the entity | ||
this.addComponent(new DOMComponent(domElement)); // DOM element associated with the entity | ||
} | ||
} | ||
|
||
// Define an AnchorEntity to represent a fixed anchor point | ||
export class AnchorEntity extends Entity { | ||
constructor(initialPositon: { x: number; y: number }, name?: string) { | ||
super(); | ||
this.name = name; | ||
this.addComponent( | ||
new PositionComponent(initialPositon.x, initialPositon.y), | ||
); // Initial position | ||
this.addComponent(new VelocityComponent(0, 0)); // Initial velocity | ||
this.addComponent(new ForceComponent()); // Force acting on the entity | ||
this.addComponent(new AccumulatedForceComponent()); // Force acting on the entity | ||
} | ||
} |
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