ELEC2645 (2018/19) / Mbed 2 deprecated el17ajf

Dependencies:   mbed

Fork of el17ajf by Angus Findlay

Input/Input.cpp

Committer:
el17ajf
Date:
2019-03-15
Revision:
10:5762d7fae033
Parent:
9:3a7776a29a11
Child:
12:beb0d7632531

File content as of revision 10:5762d7fae033:

#include "Input.h"

Input::State Input::states[NUMBER_OF_BUTTONS];

void Input::init() {
    for (int i = 0; i < NUMBER_OF_BUTTONS; i++) {
        Input::states[i] = RELEASED;
    }
}

void Input::deinit() {
    
}

void Input::update() {
    // update existing states
    for (int i = 0; i < NUMBER_OF_BUTTONS; i++) {
        if (Input::states[i] == RELEASED_FRAME) {
            Input::states[i] = RELEASED;
        }
        if (Input::states[i] == HIT_FRAME) {
            Input::states[i] = HELD;
        }
    }
    
    // check inputs
}

bool Input::buttonHit(Button button) {
    return Input::states[button] == HIT_FRAME;
}

bool Input::buttonHeld(Button button) {
    return Input::states[button] == HIT_FRAME
        || Input::states[button] == HELD;
}