@medieval/sword v2.0.6
Sword ECS โ๏ธ
๐งโโ๏ธ "Why manage components manually, when you can let the engine do it for you?"
โ Some wise developer
๐ฐ Welcome to Sword ECS โ the magical world where entities roam free, systems take care of all the heavy lifting, and components live happily ever after!
๐ก Features
- ๐ฎ ECS Awesomeness: Build your game with an Entity Component System, because who needs OOP? ๐คทโโ๏ธ
- ๐ค Super-Smart Systems: Let systems update your entities while you sit back and sip coffee โ.
- ๐งโโ๏ธ Archetype Wizards: Create entities from archetypes like a magician conjuring spells.
- ๐ก Event Chaos: Built-in events to make everything more dramatic.
- โณ Deferred Magic: Entities appear right on time thanks to deferred creation.
- ๐ Query Like a Pro: Retrieve entities like searching for your TV remote.
- ๐ฒ Custom Hooks: Insert your special logic like a master chef.
๐ Installation
Installing is as simple as:
npm install @medieval/sword --force
๐ก Pro Tip: ๐งโโ๏ธ Don't forget to run npm install
โ your code won't magically work without it!
๐ Getting Started
Hereโs how you start creating your next award-winning game:
import { World, Entity } from 'sword-ecs';
// Create your first epic entity
interface MyEntity extends Entity {
position: { x: number; y: number };
velocity: { x: number; y: number };
health: number;
}
const world = new World<MyEntity>([
(dt: number) => {
world.query({ has: ['position', 'velocity'] }).entities.forEach((entity) => {
entity.position.x += entity.velocity.x * dt;
entity.position.y += entity.velocity.y * dt;
});
}
]);
const player = world.spawn({
position: { x: 0, y: 0 },
velocity: { x: 1, y: 1 },
health: 100 // Because you don't want your player dying too soon! ๐
});
function gameLoop(dt: number) {
world.runSystems(dt);
requestAnimationFrame(gameLoop);
}
requestAnimationFrame(gameLoop);
๐ Disclaimer: No real entities were harmed during this loop!
๐ Systems and Queries
Systems are your game engine ninjas ๐ฅท, silently doing their job every frame. Define them and let them work their magic!
world.addSystem((dt) => {
const { entities } = world.query({
has: ['position', 'velocity'],
where: (entity) => entity.health > 0
});
entities.forEach((entity) => {
entity.position.x += entity.velocity.x * dt;
entity.position.y += entity.velocity.y * dt;
});
});
๐งโ๐ป "Just one query a day keeps the bugs away!" โ Random dev wisdom
๐ง Events
Life's more fun with events!
world.subscribeToEvent('entityAdded', (event) => {
console.log('๐ Entity added:', event.entity);
});
world.emitEvent('customEvent', { message: 'Hello, World! ๐' });
๐ Fun fact: Emitting custom events is like sending a postcard to all your entities.
Advanced Features
- โ Deferred Entity Creation: Because some entities like to make a dramatic entrance.
- ๐ซ Custom Hooks: Use lifecycle hooks like an exclusive backstage pass to control entity behavior.
๐ค Contributing
We would love your help to make this engine even more awesome! Submit issues, PRs, or just send us a virtual high-five!
๐ธ๏ธ "With great engines, comes great responsibility." โ Not Spider-Man, but close
Feel free to contribute at the GitHub repository.
๐ License
This project is licensed under the MIT License.
๐ฎ Now go ahead and build something epic with Sword ECS! Enjoy the ride!
8 months ago
10 months ago
10 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago