Coder Social home page Coder Social logo

vudustates's Introduction

VuduStates

Vudu is a simple finite state machine to be used in event driven applications or for game character behavior AI in HTML5 games.

How to use:

  1. put <script src="/path/to/VuduStateMachine.js"></script> at the header of your html page.
  2. Create a state structure that will work with Vudu. example: A simple behavior states for a zombie.
var states = [
    {
        'name': 'idle',
            'initial': true,
        'events': {
            'walkTowardPrey': 'walk',
                'closerToPrey': 'attack', // switch to attack state when prey is close
        }
    },

    {
        'name': 'attack',
            'events': {
            'isWounded': 'scream',
                'zeroHealth': 'die'
        }
    },

    {
        'name': 'scream',
            'events': {
            'closerToPrey': 'attack',
                'zeroHealth': 'die'
        }
    }, 
    {
        'name': 'walk',
            'events': {
            'closerToPrey': 'attack',
                'walk_away': 'walk',
                'isWounded': 'scream',
                'zeroHealth': 'die'
        }
    },

    {
        'name': 'die',
            'events': {
            'removeZombie': 'clear', //clear zombie from scene
        }
    },

    {
        'name': 'clear'
         
    }

];

  1. initialize the state
    var zombie = new Vudu.start(states); //the initial state would be set to a Zombie idle state

  2. Run an event that have been declared in states
    zombie.event('closerToPrey');
    this event will swicth the current state from 'idle' to 'attack'

  3. You confirm which state is running in your javascript console with:
    zombie.state(); this will return the name of the current state, so you can use it in your conditionals

Very easy, right?

vudustates's People

Contributors

darmie avatar

Stargazers

David Khourshid 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.