2.0.6 โ€ข Published 8 months ago

@medieval/sword v2.0.6

Weekly downloads
-
License
-
Repository
-
Last release
8 months ago

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!

2.0.6

8 months ago

2.0.5

10 months ago

2.0.4

10 months ago

2.0.3

10 months ago

2.0.2

11 months ago

2.0.1

11 months ago

2.0.0

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago

0.0.2

1 year ago

0.0.1

1 year ago