Have we got a place where we can store the code yet? I have a few classes lying around that might be useful:
_Point, int and float versions:
template<typename T>
struct _Point{
T x, y;
_Point():x(0),y(0){} //Default constructor(called if no other constructors are called)
_Point(T xx, T yy):x(xx),y(yy){} //Constructor for setting the values
bool operator==(_Point<T> a) //eg: if(pointi1==pointi2)
{return(a.x==x && a.y==y);}
bool operator!=(_Point<T> a) //eg: if(pointi1!=pointi2)
{return!(a.x==x && a.y==y);}
_Point<T>* operator+=(_Point<T> a){//eg: pointi1 += pointi2
_Point<T>* p = this;
p->x += a.x;
p->y += a.y;
return p;
}
_Point<T>* operator-=(_Point<T> a){//eg: pointi1 -= pointi2
_Point<T>* p = this;
p->x -= a.x;
p->y -= a.y;
return p;
}
_Point<T> operator+(_Point<T> a)//eg: pointi1 = pointi2 + pointi2
{return _Point<T>(a.x+x, a.y+y);}
_Point<T> operator-(_Point<T> a)//eg: pointi1 = pointi2 - pointi2
{return _Point<T>(a.x-x, a.y-y);}
};
typedef _Point<float> pointf; //float version of _Point
typedef _Point<int> pointi; //int version of _Point
_Vector, int and float versions:
template<typename T>
struct _Vector{
T x, y, z;
_Vector():x(0),y(0),z(0){} //Default constructor(called if no other constructors are called)
_Vector(T xx, T yy, T zz):x(xx),y(yy),z(zz){} //Constructor for setting the values
// Operators here are pretty much the same as _Point except they have the z atribute aswell
bool operator==(_Vector<T> a)
{return(a.x==x && a.y==y);}
bool operator!=(_Vector<T> a)
{return!(a.x==x && a.y==y);}
_Vector<T>* operator+=(_Vector<T> a){
_Vector<T>* p = this;
p->x += a.x;
p->y += a.y;
p->z += a.z;
return p;
}
_Vector<T>* operator-=(_Vector<T> a){
_Vector<T>* p = this;
p->x -= a.x;
p->y -= a.y;
p->z -= a.z;
return p;
}
_Vector<T> operator+(_Vector<T> a)
{return _Vector<T>(a.x+x, a.y+y);}
_Vector<T> operator-(_Vector<T> a)
{return _Vector<T>(a.x-x, a.y-y);}
};
typedef _Vector<float> vectorf; //float version of _Vector
typedef _Vector<int> vectori; //int version of _Vector
Color:
struct Color{
int r, g, b;
Color():r(0),g(0),b(0){}
Color(int rr, int gg, int bb)
:r(rr),g(gg),b(bb){}
};
Bounds:
struct Bounds{ //For width and height
int w, h;
Bounds():w(0),h(0){}
Bounds(int ww, int hh):w(ww),h(hh){}
};
And this is an updated verion of my button class, it uses the classes I made above:
struct ButtonFireWhenClicked{
pointi pos; //the position
Bounds bnd; //the width and height
Color c1, c2, txcol; //the color, the alt-color and the text color
char* label; //the label of the button
void(*this_func)(void); //the function to exicute when the button is clicked on
void setFunction(void(*func)(void)) //used for setting the function(see above)
{this_func = func;}
void update(){
int mx = dbMouseX();
int my = dbMouseY();
if(mx > pos.x && mx < pos.x+bnd.w && //
my > pos.y && my < pos.y+bnd.w){ // true if the mouse is over the button
if(mx > pos.x && mx < pos.y+bnd.h && //
my > pos.y && my < pos.y+bnd.h){ //
dbInk(dbRGB(c2.r, c2.g, c2.b), dbRGB(c2.r, c2.g, c2.b)); //set the ink color to the alt color
dbBox(pos.x, pos.y, pos.x+bnd.w, pos.y+bnd.h); //make a box using that alt color
if(dbMouseClick()) //the mouse got clicked while over the button
this_func(); //execute the function previously set
}
}
else{
dbInk(dbRGB(c1.r, c1.g, c1.b),dbRGB(c1.r, c1.g, c1.b));
dbBox(pos.x, pos.y, pos.x+bnd.w, pos.y+bnd.h);
}
}
// constructor
ButtonFireWhenClicked(pointi pos, Color col1, Color col2, Bounds bn,
char* text, Color txcol)
:pos(pos),c1(col1),c2(col2),bnd(bn),txcol(txcol),label(text) //initializer list
{
dbInk(dbRGB(c2.r, c2.g, c2.b),dbRGB(c1.r, c1.g, c1.b)); //set the ink color
dbBox(pos.x, pos.y, pos.x+bnd.w, pos.y+bnd.h); //make a box with that color
dbInk(dbRGB(txcol.r, txcol.g, txcol.b),dbRGB(0,0,0)); //set the ink color to the text color(txcol)
dbText((pos.x+bnd.w)/2,(pos.y+bnd.h)/2,label); //put the text in the middle of the button
}
};
#define BFWC ButtonFireWhenClicked //for easier calling
I didn't put much comments because all these do is hold data into variables,
so I thought that it wouldn't need much explanation
Hope these are useful!
#ifdef __NEWBIE__
MakeAnAwesomeGame(lots of badies, lots of guns, lots of stuff to do, BIG level)
#endif