enum GameStates {
STATE_NULL,
STATE_INTRO,
STATE_TITLE,
STATE_QUIT,
};
class GameState {
public:
virtual void handleEvents() = 0;
virtual void logic() = 0;
virtual void render() = 0;
virtual ~GameState(){};
};
From what I understand, first we create a custom variable, which can be STATE_NULL, STATE_INTRO, etc. Then we create a class called Game State with a set of "virtual" functions- I believe they are functions that are meant to be inherited and thus don't require themselves to be present (No need for GameState::handleEvents()) or is this what the = 0 does??class Intro : public GameState {
public:
void handleEvents();
void logic();
void render();
Intro();
~Intro();
private:
SDL_Surface *slide;
int yVel;
float y;
};
Ok here we have the Intro class which inherits from Game State, I pretty much know what is going on here.To save on space I won't attach all the functions.
currentState = new Intro();This is what interests me, does the "currentState" variable have all the properties of Intro??? So for example could I create an array of pointers that are all of type "GameObject" but actually point to different classes that inherit from "GameObject" for example a "BlockWall" and "EntityPlayer" class and could I pass the pointers to other functions (eg when "EntityPlayer" hits "BlockWall" each would have their CheckCollision(GameObject* other) function called with the other objects pointer).
The reason I am interested is that I wish to write a 2D basic physics engine and this could be what I need to handle different types of classes that all have the same functions that just do different things, eg "BlockWall" would just show its self and have a empty checkCollision() function while "EntityPlayer" would have a checkCollision() function full of different switches (eg if it hits "BlockWall" it would stop).
Excited.


Sign In
Create Account


Back to top










