// Jason Brillante "Damdoshi"
// Hanged Bunny Studio 2014-2015
//
// Sewer Glue

#ifndef				__HBS_SEWER_GLUE_INGAME_HPP__
# define			__HBS_SEWER_GLUE_INGAME_HPP__
# include			<list>
# include			"Module.hpp"
# include			"SewerGlue.hpp"

namespace			hbs
{
  class				Ingame : public hbs::Module
  {
  public:
    enum			Ressource
      {
	FIRST_RESSOURCE,
	BACKGROUND		= FIRST_RESSOURCE,
	MIDDLEGROUND,
	FOREGROUND,
	CAR,
	PEOPLE,
	BACKMONSTER,
	FOREMONSTER,
	MONSTER,
	BACKMONSTER_HIDDEN,
	FOREMONSTER_HIDDEN,
	LIFEBAR,
	FONT,
	LAST_RESSOURCE
      };
    enum			Position
      {
	BACK,
	FORE
      };
    enum			Direction
      {
	UP,
	DOWN,
	LEFT,
	RIGHT,
	LAST_DIRECTION
      };
    struct			Element
    {
      sf::Sprite		people;
      double			x;
      Position			layer;
      double			speed;
      int			subtype;
      double			anim;
    };
      
  protected:
    static const std::string	ressources_file[LAST_RESSOURCE];
    static const sf::IntRect	sewers[9];
    sf::Texture			ressources[LAST_RESSOURCE];

    sf::Sprite			background;
    sf::Sprite			middleground;
    sf::Sprite			foreground;

    std::list<Element>		car;
    std::list<Element>		people;

    sf::Sprite			backmonster;
    sf::Sprite			foremonster;
    sf::Sprite			monster;
    sf::Sprite			backmonster_hidden;
    sf::Sprite			foremonster_hidden;
    bool			monster_hidden;
    int				monster_hidingplace;
    int				monster_x;
    int				monster_y;
    int				monster_counter;

    int				camera_position;
    double			camera_speed;

    bool			move[LAST_DIRECTION];
    int				miam;

    sf::Sprite			lifebar;
    int				life;
    int				outch_delay;

    void			NewCar(void);
    void			NewPeople(void);

    struct			Word
    {
      std::string		str;
      int			delay;
      int			x;
      int			y;
      bool			color;
      bool			cam;
      int			fade;
    };
    std::list<Word>		words;
    sf::Sprite			font;
    void			Say(const std::string		&str,
				    int				x,
				    int				y,
				    int				delay,
				    bool			color = false,
				    bool			cam = false);

    bool			warping;
    hbs::SewerGlue::Klondike	destination;
    int				warp_animation;

    int				arriving;

    int				victory_step;

    struct			Level
    {
      int			people_frequency;
      int			car_frequency;
      int			people_to_get;
      int			type_to_get;
      bool			escape;
    };
    static const Level		levels[11];
    int				level;

    int				people_get;

    void			Lost(void);
    void			Win(void);

  public:
    bool			Start(hbs::SewerGlue		&sg);
    void			Reset(void);
    bool			Event(const sf::Event		&event);
    bool			Play(uint64_t			delay);
    void			Display(sf::RenderTarget	&x);

    Ingame(void);
    virtual ~Ingame(void);
  };
}

#endif	//		__HBS_SEWER_GLUE_INGAME_HPP__
