/****************************************************************
    class base_image, BY AHARON HILLEL.
    The basic sprite-class.
    sprites reside in array of (RLE_SPRITE *)
    gcc version 3.2 (mingw special 20020817-1)
    ALLEGRO VERSION: 4.1.12 (WIP)
    ALLEGRO DATE:    2003-11-10
****************************************************************/
#include <allegro.h>

#if !defined( _BASE_IMAGE_H_ )
#define _BASE_IMAGE_H_

#define G_FALSE 0
#define G_TRUE  1
/*  To use this class, all sprites should reside in:  */
/*  RLE_SPRITE *sprites_array[LAST_SPRITE] array.     */

class base_image
{
    private:
      BITMAP *dest;
      RLE_SPRITE **data;

      int index;
      int visible;
      int use_bg;
      int x;
      int y;
      int z;
      int x_start;
      int y_start;

      BITMAP *bg;

    public:
      base_image();
      base_image(RLE_SPRITE **dt, const int sprite_index);
      base_image(RLE_SPRITE **dt, BITMAP *dst, const int sprite_index);  // constructor with sprite index
      base_image(RLE_SPRITE **dt, BITMAP *dst, const int pos_x, const int pos_y, const int sprite_index, const int bg_flag, const int d);
      base_image(RLE_SPRITE **dt, BITMAP *dst, const int pos_x, const int pos_y, const int z_order, const int sprite_index, const int bg_flag, const int d);
      base_image(const base_image &other);   // COPY constructor
      virtual ~base_image();  // destructor of drived class called.

      inline const int get_sprite_index(void) { return index; };
      inline BITMAP *get_dest_bitmap(void) { return dest; };
      inline void set_dest_bitmap(BITMAP *new_dest) { dest = new_dest; visible = G_FALSE; };
      inline void set_data_ptr(RLE_SPRITE **new_data) { data = new_data; index = -1; };
      inline void clear_bg_flag(void) { if(bg) delete(bg); bg = NULL; use_bg = G_FALSE; };
      inline void set_bg_flag(void)   { if(bg) delete(bg); bg = NULL; use_bg = G_TRUE; };
      BITMAP *get_background_bitmap(void){ return bg; };
      void set_sprite_index(const int new_index);
      inline const RLE_SPRITE *get_sprite() { if(index < 0) return NULL; return data[index]; };
      inline const int get_x_pos() { return x; };
      inline const int get_y_pos() { return y; };
      inline const int get_z_order() { return z; };
      inline int point(int x, int y, int c) { return (getpixel(dest, x, y) == c); };
      int inside(const int left_x, const int top_y, const int right_x, const int bt_y);
      int point_inside(const int pos_x, const int pos_y);
      int collision(const int pos_x, const int pos_y, const RLE_SPRITE &other);
      int collision_ex(const int pos_x, const int pos_y, const int z_order, const RLE_SPRITE &other);
      int draw();
      int remove();
      int erase();
      int set_pos(const int new_x, const int new_y, const int d);
      int set_pos_ex(const int new_x, const int new_y, const int new_z, const int d);
      int move(const int new_x, const int new_y);
      int move_ex(const int new_x, const int new_y, const int new_z);
      int go_to_start_pos(void);
                                         
      virtual int kill(void);
      virtual int action(void);        //  Image action for drived class
};

#endif // _BASE_IMAGE_H_