Coder Social home page Coder Social logo

game_state_machine's Introduction

Game State Machine

Game State Machine

Support an Open Source Developer! ♥️
Become a patron

Read the documentation.

Features

  • State trait that is simple to implement.
  • Generic stack-based state machine, for all your needs.
  • State update functions.
  • State pause and unpause.

Usage

Add the following to you Cargo.toml file:

game_state_machine = "*"

Use it like so:

use game_state_machine::*;

type StateData = (isize, isize);

pub struct Test;

impl State<StateData> for Test {
    fn on_start(&mut self, data: &mut StateData) {
        data.0 += data.1;
    }

    fn on_resume(&mut self, data: &mut StateData) {
        self.on_start(data);
    }

    fn update(&mut self, _data: &mut StateData) -> StateTransition<StateData> {
        StateTransition::Push(Box::new(Test))
    }
}

fn main() {
    let mut sm = StateMachine::<StateData>::default();

    let mut state_data = (0, 10);

    sm.push(Box::new(Test), &mut state_data);
    assert!(state_data.0 == 10);

    sm.update(&mut state_data);
    assert!(state_data.0 == 20);

    sm.stop(&mut state_data);
    assert!(state_data.0 == 20);
    assert!(!sm.is_running())
}

Maintainer Information

  • Maintainer: Jojolepro
  • Contact: jojolepro [at] jojolepro [dot] com
  • Website: jojolepro.com
  • Patreon: patreon

game_state_machine's People

Contributors

annekitsune avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

age-rs

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.