Coder Social home page Coder Social logo

core-js's Introduction

core-js

core-js is a very simple game/simulation loop framework I initially made a long time ago in Java, which I ported to Javascript.

It is an Entity-Component system used to structure packages of data and reference them - almost like viewing a set of data through an arbitrary window. Core also keeps track of the Systems - things that operate on Entities to perform a particular set of work every game loop.

Games run in a loop many time a second. In fact, if you’re trying to run a game at 60 frames per second, you only have a budget of ~16.6667ms to complete all of the things you are trying to do in your game.

I built Core so that I could manage all of the pieces of all of the things I wanted to do in a centralized, consistent manner.


Games I made with Core:

Frontier

Source code | Demo

Screenshot 2024-04-19 at 7 13 18 PM

The major parts

Entities

Entities are things in the game world. They have a unique identifier as well as a key, and that’s about it. Entities contain Components that hold the actual data.

Components

A component is a set of data for a particular arbitrary purpose. They can be added to an Entity. Imagine data you need to represent an Entity’s health - you could have a HealthComponent with a property health_points.

Tags

A tag is a window into an entity and its components that is particularly relevant for something you are trying to do with or to that Entity.

You can use it to group together component data access from multiple components, and then access all eligible Entities with that Tag - handy for naming a set of things that a System can act on.

For example - if you wanted to have a Movable object, you could create a Tag that looks at a PositionComponent and a VelocityComponent to modify the data necessary to simulate movement. You could then reference all Entities with both a PositionComponent and a VelocityComponent with the Movable tag.

Systems

Systems are the actual system that operate in the game. Systems can either perform work every game cycle, or send and receive messages to each other. In the above example, I could have a MovementSystem that handles moving all of my Entities by their specified velocity every game loop, using the Movable tag to identify all of them.

Core

Core is the central part of the framework that brings them all together. It tracks the list of Entities, automatically assigns or unassigns Tags as Components are added / removed, and runs the core game loop - a loop that calls every system in sequence and asks it to do work. Because it tracks everything, Systems can use Core to pass messages to each other, retrieve specific Entities, and set/retrieve "global data.

core-js's People

Contributors

jgefroh avatar

Watchers

James Cloos avatar  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.