/* * "Pigeon" automata simulator for Motorj * * Permits easier simulation of automata in games (e.g. enemies * and other entities that can be described as state machines) * Copyright (C) 2009-2010 Alejandro Valenzuela Roca, * * This file is part of MotorJ, a free framework for videogame creation. * * * * MotorJ is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MotorJ is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with MotorJ. If not, see . */ #include "pigeon-class.h" //! "Pigeon" automata simulator for MotorJ /*! * * "Pigeon" automata simulator for Motorj * * Permits easier simulation of automata in games (e.g. enemies * and other entities that can be described as state machines) * */ mjPigeon::mjPigeon(){ currentStateIndex = 0; timeInCurrentState = 0; currentStatePtr = NULL; } void mjPigeon::Update(float t_elapsed) { int newStateIndex; timeInCurrentState+= t_elapsed; newStateIndex = Test(); if (newStateIndex != currentStateIndex) { // Switch state. timeInCurrentState = 0; currentStatePtr = states[newStateIndex]; currentStateIndex = newStateIndex; } currentStatePtr->Execute(t_elapsed); }