Original Post
Been learning finite state machines with :Programming game AI by example book". So for the past week I have been doing very well. Except for today I can not seem to compile any of the code I did. I keep getting this error error C2143: syntax error : missing ';' before '.'.
[Edited by - InnocuousFox on June 29, 2010 5:20:31 PM]
#ifndef _ENTITY_H_#define _ENTITY_H_#pragma once#include "allegro.h"#include "Sprite.h"class State;class entity{public: entity(void); ~entity(void); State* m_pCurrentState; State* m_pPreviousState; Sprite m_sprite; void Update(); void ChangeState( State* p_newState );};#endif #include "entity.h"#include "state.h"entity::entity(void){ m_pCurrentState = NULL; m_pPreviousState = NULL;}entity::~entity(void){}void entity::Update(){ m_pCurrentState->execute(this);}void entity::ChangeState( State* p_newState) { if( m_pCurrentState != NULL ) { //Save the previous state m_pPreviousState = m_pCurrentState; //Delete the current state delete m_pCurrentState; }//end if else{ m_pPreviousState = p_newState; } //change the state m_pCurrentState = p_newState;}</code> here is the states<code>#include "entity.h"#ifndef _STATE_H_#define _STATE_H_#pragma onceclass entity;class State_Right;class State_Left;class State_Down;class State_UP;//The state abstract classclass State{public: int prev; virtual void execute( entity* p_e )=0;};//State right change the direction of the entity to go rightclass State_Right : public State{private: public: State_Right(); void execute( entity* p_e );};//State go left////////////////////////////////////////class State_Left : public State{private: public: State_Left(); void execute( entity* p_e );};//State go down///////////////////////////////////////class State_Down_Left : public State{private: public: State_Down_Left(); void execute( entity* p_e );};//State go down///////////////////////////////////////class State_Down_Right : public State{private: public: State_Down_Right(); void execute( entity* p_e );};//State go up////////////////////////////////////////class State_Up : public State{private: public: State_Up(); void execute( entity* p_e );};#include "State.h"void State::execute( entity *p_e ){}////////////////////State Right//////////////State_Right::State_Right(){ prev =0;}void State_Right::execute(entity *p_e){ static int delay = 10; static int timer =0; static int space = 0; if( timer >= delay ) { timer = 0; space = p_e->m_sprite.getSpriteStats()->width; }//end if else{ ++timer; space=0; }//end else //Move the sprite p_e->m_sprite.setPos(p_e->m_sprite.getXpos()+space, p_e->m_sprite.getYpos()); if( p_e->m_sprite.getXpos()+p_e->m_sprite.getSpriteStats()->width >= SCREEN_W ) { p_e->ChangeState( new State_Down_Left()); }}//State_Down//////////////////////////////State_Down_Left::State_Down_Left(){ prev =3;}void State_Down_Left::execute(entity *p_e){ //Move the sprite down on then switch to the left p_e->m_sprite.setPos(p_e->m_sprite.getXpos(), p_e->m_sprite.getYpos()+p_e->m_sprite.getSpriteStats()->height); p_e->ChangeState(new State_Left()); if( p_e->m_sprite.getYpos() >= SCREEN_H ) { p_e->m_sprite.setPos(0,0); }}//////////////////////////////////////////State_Down_Right::State_Down_Right(){ prev =3;}void State_Down_Right::execute(entity *p_e){ //Move the sprite down on then switch to the left p_e->m_sprite.setPos(p_e->m_sprite.getXpos(), p_e->m_sprite.getYpos()+p_e->m_sprite.getSpriteStats()->height); p_e->ChangeState(new State_Right()); if( p_e->m_sprite.getYpos() >= SCREEN_H ) { p_e->m_sprite.setPos(0,0); }}//State_Left////////////////////////////State_Left::State_Left(){ prev =1;}void State_Left::execute(entity *p_e){ static int delay = 10; static int timer =0; static int space = 0; if( timer >= delay ) { timer = 0; space = p_e->m_sprite.getSpriteStats()->width; }//end if else{ ++timer; space=0; }//end else //Move the sprite p_e->m_sprite.setPos(p_e->m_sprite.getXpos()-space, p_e->m_sprite.getYpos()); if( p_e->m_sprite.getXpos() <= 0 ) { p_e->ChangeState( new State_Down_Right()); }}//State_Up////////////////////////////////State_Up::State_Up(){}#endif </code>Here is the main<code> #include "allegro.h"#include "entity.h"entity e;e.ChangeState(new State_Right);//main functionvoid main(void){ //main loop return;}END_OF_MAIN()Thanks in advance for your help[IFox: Added source tags][Edited by - InnocuousFox on June 29, 2010 5:20:31 PM]