00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _FILE_PIXEL_H_
00018 #define _FILE_PIXEL_H_
00019 #include "SDL.h"
00020 #include "mxsurface.h"
00021
00022
00023 namespace mx
00024 {
00025
00026 class mxPixelData;
00027
00028
00029 class mxPixel {
00030
00031
00032 public:
00033 enum { DIR_UPRIGHT, DIR_DOWNRIGHT, DIR_DOWNLEFT, DIR_UPLEFT, DIR_UPRIGHT_EX, DIR_UP, DIR_RIGHT };
00034
00035 mxPixel();
00036 mxPixel(unsigned int color_value);
00037 mxPixel(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
00038 mxPixel(const mxPixel &p);
00039
00040 Uint32 GetMappedColor(SDL_PixelFormat *format);
00041 void GetSDLColor(SDL_Color *col);
00042 void SetMappedColor(SDL_PixelFormat *format, Uint32 color);
00043 void setColor(unsigned int color);
00044
00045 const bool isActive() const;
00046
00047
00048 void setBounds(const int bx, const int by, const int bw, const int bh);
00049 void setNoRespawn(bool spawn);
00050 void setPos(int x, int y) { this->x = x, this->y = y; }
00051 void setPixel(const mxPixel &p);
00052 void setPixel(int x, int y, int direction);
00053 void setDirection(int direction);
00054 void setAlpha(float alpha, bool on);
00055 void setVibration(float alpha, bool on);
00056 void setSpeed(int speed);
00057 void clearPixel();
00058
00059
00060
00061 void resetPixel();
00062
00063
00064 mxPixel &operator=(const mxPixel &p);
00065 mxPixel &operator+=(const mxPixel &p);
00066 friend mxPixel operator+(const mxPixel &p, const mxPixel &p2);
00067 mxPixel &operator-=(const mxPixel &p);
00068 friend mxPixel operator-(const mxPixel &p, const mxPixel &p2);
00069 mxPixel &operator*=(const mxPixel &p);
00070 friend mxPixel operator*(const mxPixel &p, const mxPixel &p2);
00071 mxPixel &operator/=(const mxPixel &p);
00072 friend mxPixel operator/(const mxPixel &p, const mxPixel &p2);
00073
00074 void operator++();
00075 void operator++(int);
00076 ~mxPixel();
00077
00078 const int getx() const { return x; }
00079 const int gety() const { return y; }
00080
00081
00082 protected:
00083
00084 friend class mxPixelData;
00085
00086 int x,y,speed,direction;
00087 int sx,sy,sw,sh;
00088
00089 union {
00090
00091 unsigned char rgb[4];
00092 unsigned int value;
00093
00094 } color;
00095
00096 float alpha, distance, vibration;
00097 bool dead, no_respawn;
00098
00099 void moveByDirection();
00100 void boundsCheck();
00101 };
00102
00103 class mxPixelData {
00104
00105 public:
00106
00107
00108
00109 mxPixelData();
00110 ~mxPixelData();
00111 bool initDataFromSurface(mx::mxSurface &surface);
00112 void copyDataToSurface(mx::mxSurface &surf, int amt);
00113
00114 mxPixel **pixelData() { return data; }
00115 const int getX() const { return sx; }
00116 const int getY() const { return sy; }
00117
00118 protected:
00119 mxPixel **data;
00120 int sx, sy;
00121 mxSurface surf;
00122
00123 };
00124
00125 }
00126
00127
00128
00129
00130
00131
00132 #endif
00133
00134
00135