GithubHelp home page GithubHelp logo

doytsujin / wolf-ecs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from endershadow8/wolf-ecs

0.0 1.0 0.0 230 KB

WolfECS is a powerful, lightweight Entity Component System framework written in Typescript.

License: MIT License

TypeScript 55.83% JavaScript 44.17%

wolf-ecs's Introduction

WolfECS

WolfECS is a powerful, lightweight Entity Component System framework written in Typescript.

Huge thanks to NateTheGreatt's BitECS from which I took many valuable techniques which I then improved upon.

Features

Possible future features

Installation

Installing locally

npm:

npm i wolf-ecs

yarn:

yarn add wolf-ecs

Alternatively, download the latest release here on GitHub.

Using a CDN

JSDelivr:

import { ECS, types } from "https://esm.run/wolf-ecs/wolf-ecs.js"

Usage

Find detailed documentation here.

import { ECS, types } from "wolf-ecs"

// Create ECS object
const ecs = new ECS()

// Define the shape of a component
const vector = {x: types.i32, y: types.i32}

// Define a component using a component definition
ecs.defineComponent("position", vector)
ecs.defineComponent("velocity", vector)

// Create a query which requires certain components
const moveQuery = ecs.createQuery("position", "velocity")

// Define a system
function moveSystem() {
  // Get relevant components
  const position = ecs.components.position
  const velocity = ecs.components.velocity

  // Iterate over all entities that match a query
  for(let archetype of moveQuery.archetypes) {
    for(let entity of archetype.entities) {
      position.x[entity] += velocity.x[entity]
      position.y[entity] += velocity.y[entity]
    }
  }
}

// Create an entity
const entity = ecs.createEntity()

// Add components to entity
ecs.addComponent(entity, "position")
ecs.addComponent(entity, "velocity")

// Values must be set otherwise undefined behaviour will occur
ecs.components.position.x[entity] = 1
ecs.components.position.y[entity] = 1
ecs.components.velocity.x[entity] = 1
ecs.components.velocity.y[entity] = 1

// Main loop
function main() {
  // Execute a system
  moveSystem()
  requestAnimationFrame(main)
}
main()

More on ECS

Entity–component–system (ECS) is an architectural pattern that is mostly used in game development. ECS follows the composition over inheritance principle that allows greater flexibility in defining entities where every object in a game's scene is an entity (e.g. enemies, bullets, vehicles, etc.). Every entity consists of one or more components which contains data or state.

- Wikipedia

This article explains ECS very well.

Contributing

Small pull requests are welcome. For major changes, please open an issue first to discuss the changes you'd like to make.

wolf-ecs's People

Contributors

endershadow8 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.