GithubHelp home page GithubHelp logo

topdown-physics's Introduction

topdown-physics experimental

Basic, grid-based, 2D top-down player physics for continuous ndarrays.

You can find a demo here, the code for which is here.

The implementation could be improved a lot - patches welcome :)

Installation

Written to be used with browserify.

npm install topdown-physics

Usage

physics = require('topdown-physics')(player, field[, options])

player is an axis-aligned bounding box - use aabb-2d for this. field is a continuous ndarray to check collisions against. You can also pass the following options:

  • friction: The amount of friction to apply - the higher the value, the more quickly the player will slow down.
  • physical: A function that should the value of a cell and returns whether or not it is solid, i.e. the player cannot move through it. Alternatively, you can just pass in a constant value. Defaults to 0.
  • interval: The granularity of collision checks - generally, this is best set to the reciprocal of the width in pixels of each cell when rendered. So if each block is 32x32, you should set this to 1 / 32.

physics.tick()

Steps forward the simulation by one tick - this should be called each frame.

physics.spd

An array you're free to modify directly. The first value is the horizontal speed (in cells per tick), and the second is the vertical speed.

physics.on('collision', callback)

Emitted when a collision is made during a tick.

topdown-physics's People

Contributors

hughsk avatar shama avatar

Watchers

 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.