#ifndef ENGINE_H_INCLUDED
#define ENGINE_H_INCLUDED

#include <vector>
#include <string>
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include "TextureManager.h"

extern cTextureManager g_TextureManager;
extern SDL_Surface* screen;

#include "RenderObject.h"
#include "RenderManager.h"
#include "Sprite.h"
#include "LevelManager.h"
#include "InputManager.h"
#include "SoundManager.h"

extern cInputManager g_InputManager;
extern cSoundManager g_SoundManager;
extern cRenderManager g_RenderManager;
//-----------------------------------------

class cCompleteScreen : public cRenderObject
{
    private:
    protected:
    public:

        SDL_Surface *m_Surface;

        cCompleteScreen(std::string Name);

        ~cCompleteScreen()
        {
        }

        void update(SDL_Surface *Screen);
        bool updateKey(SDLKey Key);
};

//-----------------------------------------

class cEngine
{
    private:
    protected:
    public:

     cLevelManager *m_Levels;
     cCompleteScreen *m_CompleteScreen;

    cEngine()
    {
        m_Levels = NULL;
        m_CompleteScreen = NULL;
    }

    ~cEngine()
    {
        if(m_Levels)
            delete m_Levels;
    }

    bool Init()
    {
        m_Levels = new cLevelManager("levels", 50);
        m_CompleteScreen = new cCompleteScreen("name");
        m_Levels->selectLevel(0);
        g_InputManager.addInputObject(m_Levels);
        g_InputManager.addInputObject(m_CompleteScreen);
        g_RenderManager.addRenderObject(m_Levels);
        g_RenderManager.addRenderObject(m_CompleteScreen);

        g_SoundManager.addSound("song.mp3");

        return true;
    }

    void update()
    {
        g_RenderManager.update();

        if(m_Levels->checkForWin())
        {
            m_CompleteScreen->m_Visible = true;

            int nextLevel = m_Levels->m_CurrentLevel.m_LevelNumber + 1;

            if(nextLevel > 1)
                nextLevel = 0;

            m_Levels->selectLevel(nextLevel);
        }
    }

    void updateKey(SDLKey Key)
    {
        g_InputManager.updateKey(Key);
    }
};

extern cEngine g_Engine;

#endif // ENGINE_H_INCLUDED
