Hey.
I have just changed my whole structure for dealing with Images. Now each Image draws itself and updates itself (if it's a Button and the mouse is over it, it will change to an OVER state, etc.). Because I changed this... a lot of other things got changed. Now I'm left with objects that maintain themselves, which is great... but I don't know how to get anything from these objects... such as determining when to start a new game, view the instructions, etc:
RETURN_CODE menu(Draw_Engine& DE, Audio_Engine& AE, SDL_Event& event_)
{
// Create the menu screen.
Screen menu_screen("Screens/Menu_Screen/");
bool exit_game = false;
while(!exit_game)
{ // While the user hasn't exit
while(SDL_PollEvent(&event_))
{ // While there's events to handle
if(event_.type == SDL_QUIT)
{ // If the user has Xed out
exit_game = true;
break;
}
// if user pressed "new game"
// call game()
// else if user pressed "instructions"
// call instructions()
// else if user pressed "exit"
// exit game
menu_screen.Update(event_);
menu_screen.Draw(DE.Get_Screen());
if(!DE.Draw_Screen())
{
return RC_ERROR;
}
}
}
return RC_EXIT_PROGRAM;
}
class Screen : public Drawable, public Updateable, public Uncopyable
{
public:
Screen();
Screen(const std::string& directory);
virtual ~Screen();
virtual void Draw(SDL_Surface* screen);
virtual void Update(const SDL_Event& event_);
protected:
virtual void Load(const std::string& directory);
std::vector<Base_XImage*> elements;
};
class Base_XImage : public Drawable, public Updateable, public Cloneable
{
public:
Base_XImage();
Base_XImage(
const std::string& file_name_,
int position_x,
int position_y,
bool is_colour_key_,
SDL_Colour colour_key_ = SDL_Wrappers::colour(0,0,0));
Base_XImage(const Base_XImage& rhs);
virtual ~Base_XImage();
Base_XImage& operator=(const Base_XImage& rhs);
const std::string& Get_File_Name() const;
const SDL_Rect& Get_Position() const;
bool Is_Colour_Key() const;
const SDL_Colour& Get_Colour_Key() const;
virtual void Load();
virtual void Draw(SDL_Surface* screen) = 0;
virtual void Update(const SDL_Event& event_) = 0;
virtual Base_XImage* Clone() const = 0;
protected:
static void Check_Opening_Tag(const std::string& buffer);
static void Check_Closing_Tag(const std::string& buffer);
std::string file_name;
SDL_Rect position;
bool is_colour_key;
SDL_Colour colour_key;
SDL_Surface* surface;
};
I don't really want to have huge switch statements throughout my code checking to see if a certain button was pressed to start a new game... so I was wondering if anyone has a solution to this? Perhaps a Listener class or something? I'm really not that great with patterns/design like this and so I'm relying greatly on the suggestions of posters.
Cheers.