npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chaos-studio

v0.8.1

Published

a 2D game engine

Downloads

30

Readme

Chaos-engine

DeepScan grade npm npm NPM GitHub Repo stars

This is a 2d game engine with physics,a basic canvas renderer,AI,audio management through web audio,an event system and many more features.

Features of this game engine.

  • An entity-component-system architecture where entities are made up of components and components are updated by their respective systems.Data-driven systems only.

  • An AI system that follows the Craig - Renolds implementation.It provides means to follow a target,evade another entity,follow a path and wandering about in the game world.

  • A semi-realistic physics engine that features the following:

    -> Collision Masking:Used to allow or disallow physical bodies from colliding with each other.

    -> Narrowphase:Provides collision manifold from a given pair of bodies if the bodies are colliding.

    -> Broadphase:Used to improve performance of the physics world by calculating pairs of bodies that could possibly be colliding.

    -> Distance constraints:Used to constrain two bodies at a certain distance.

    -> Static and Dynamic bodies types:Static bodies do not respond to collision with other bodies(due to infinite mass) while dynamic bodies respond to collision forces.

    -> ~~Composite bodies:It is a composition of several bodies and constraints.~~

    -> Friction:Bodies colliding experience friction between their two surfaces.

    -> Sleeping:Bodies at rest do not need to be tested every frame hence are put to "sleep" to improve performance of the physics engine.

    -> Querying:The world can be queried to know if bodies are within a certain range(either a bounding-box or bounding-circle).

    -> Iterative solving for velocity to improve non-rotational stacking.

    -> Shapes:Various convex shapes are supported in the physics engine.

  • An event system to provide defined events such as the collision event and user defined events.

  • A set of loaders to preload game assets.

  • A storage API to store data in cookies,sessions or local storage.

  • An input abstraction that normalizes input from the keyboard,mouse and touch on mobile devices.

  • A math library with support for 2D vectors.

Usage

Download and installation.

In order to get a copy of the engine ,enter the following command on your node project.

npm i chaos-studio

Import it into your project like this:

import * as CHAOS from "chaos-studio"

OR

Get the umd file from the dist folder of the repository, put it in your root directory and add it to your html page like so:

<head>
  <title>Load Example</title>
  <script src="./chaos.umd.js"></script>
</head>

This way,the "CHAOS" module name will be available on the window object.

OR

import the library from unpkg.com like this:

<head>
  <script src="https://unpkg.com/chaos-studio@latest/dist/chaos.umd.js"></script>
</head>

Creating an example

Setup game

Now we can create a small demo. Add this to your html file in the body tag for this example to work

<div id="can"></div>

In your JavaScript file,do this:

//creates a new game manager for us to handle the game's entities.
const game = new CHAOS.Manager()

//we need to draw the entities on the screen.
//that is done through a renderer.
const renderer = new CHAOS.Renderer2D()

//this binds the renderer to html.
//the canvas will be a child to the queried  html element(renderer will attach it to the html element with id of "can")
//CHAOS.Renderer2D.bindTo(renderer,"#can")

//This sets the width and height of the renderer to cover the entire screen.
CHAOS.Renderer2D.setViewport(renderer,innerWidth, innerHeight)

//Enables physics for the game.
game.registerPlugin(new CHAOS.Physics2DPlugin({
  //applies gravity to the physics world.
  gravity:new CHAOS.Vector2(0,900)
}))

//Enables rendering to 2D context of canvas
game.registerPlugin(new CHAOS.Renderer2DPlugin(renderer))

Add a box to the game

So far there is nothing on the screen... Lets fix that.

//Creates an entity on which we can components are added to.
game.create({
  //transform contains the position , orientation and scale of the entity
  "transform": new CHAOS.Transform(renderer.width/2, 300),
  //movable contains components to enable movement i.e velocity and rotation
  "movable": new CHAOS.Movable(),
  //bound is used for broadphase collision detection in the physics engine
  "bound": new CHAOS.BoundingBox(),
  //body is used for physics interaction with other bodies.
  "body": new CHAOS.Box(50, 50),
  //sprite is the object renderered onto the canvas.
  "sprite": new CHAOS.Sprite(
    new CHAOS.BoxGeometry(50, 50),
    new CHAOS.BasicMaterial()
  )
})

Adding ground

Now you should see a box falling into nothingness. Lets add ground it can land on.

const body = new CHAOS.Box(400, 100)

//This makes the body immune to gravity and collisions with other bodies.
CHAOS.Box.setType(body, CHAOS.Box.STATIC)

//Creates an entity that will act as ground.
game.create({
  "transform": new CHAOS.Transform(renderer.width/2, renderer.height - 800),
  "movable": new CHAOS.Movable(),
  "bound": new CHAOS.BoundingBox(),
  "body": body,
  "sprite": new CHAOS.Sprite(
    new CHAOS.BoxGeometry(400, 100),
    new CHAOS.BasicMaterial()
  )
})

**** WARNING ****

~~This is not yet a stable version hence dont rely on it to make production apps yet.~~

**** FUTURE WORK ****

  • [ ] Add a webgl renderer
  • [ ] Stabilize the collision response to work well with large forces such as (gravity = 10000)
  • [ ] Stabilize rotational stacking in the physics engine
  • [ ] ~~Add game state class for managing the game~~
  • [x] Add an animation system.
  • [ ] Add tutorials to this game engine
  • [ ] Add appropriate demos to the project and get a website running for them
  • [ ] Add some error handling mechanisms
  • [x] Add Serialization/Deserialization of objects(on the way)
  • [ ]~~ Kinematic bodies~~
  • [x] Collision masking using bits(bit masking)
  • [ ] More AI behaviors.
  • [ ] Add indexedDB to Storage API.
  • [ ] An audio tag fallback to Web audio (if necessary )