struct CSprite
{
	void Init(void);
	void destructor(void);
	void setBitmap(dword);				// sets bitmap for sprite
	void move(void);					// move sprite
	void draw(void);					// draw sprite on drawDC
	void fastcall setSpeed(EAX);
	void setScreenSize(dword, dword);
	void fastcall setDrawingDC(EAX);
	dword hBitmap;
	dword dcBitmap;
	dword drawDC;
	dword widthScreen;
	dword heightScreen;
	dword bmpWidth;
	dword bmpHeight;
	dword xPos;
	dword yPos;
	dword speed;
};

dword fastcall newobject(EAX)
{
	return GlobalAlloc(GMEM_FIXED,EAX);
}

void fastcall destroy(EAX)
{
	GlobalFree(EAX);
}

void CSprite::Init(void)
{
	xPos=200;
	yPos=150;
}

/*
; --=====================================================================================--
; #METHOD:      destructor (NONE)
;
; #DESCRIPTION: Will delete the object bimpate handle (if one is stored to this object),
;               as well as delete the given DC (if one was stored to this object)..
;
; #RETURN:      Nothing..
; --=====================================================================================--*/
void CSprite::destructor(void)
{
   EAX=hBitmap;
   IF(EAX)DeleteObject(EAX);
   EAX=dcBitmap;
   IF(EAX)DeleteDC(EAX);
}

/*
; --=====================================================================================--
; #METHOD:      setBitmap (hBitMap)
;
; #DESCRIPTION: Creates a DC for this object and selects the passes hBitmap into it..
;
; #PARAM:       hBitmap    The handle of the bitmap to be used with this object..
;
; #RETURN:      Nothing..
; --=====================================================================================--*/
void CSprite::setBitmap(dword hBitmp)
struct BITMAP tmpBITMAP;
{
   hBitmap=hBitmp;
	 dcBitmap=CreateCompatibleDC(NULL);
   SelectObject(EAX,hBitmp);
   GetObject(hBitmp,sizeof(BITMAP),#tmpBITMAP);
   bmpWidth=tmpBITMAP.bmWidth;
   bmpHeight=tmpBITMAP.bmHeight;
}

/*
; --=====================================================================================--
; #METHOD:      move (VOID)
;
; #DESCRIPTION: Randomly moves this sprite object's x-y location, at a random speed.<br>
;               NOTE: The spite's location variable are only ajusted, and not redrawn..
;
; #RETURN:      Nothing..
; --=====================================================================================--*/
void CSprite::move(void)
{
   Rand32(speed);
   ECX=speed>>1;
   EAX-=ECX;
   xPos+=EAX;
   -ECX;
   ECX+=widthScreen;
   IF(long xPos < 0){
   		EAX=widthScreen;
   		EDX=bmpWidth>>1;
   		EAX-=EDX;
   		EAX-=40;
   		xPos=EAX;
	 }
	 ELSE IF(long xPos > ECX)xPos=0;
   Rand32(speed);
   ECX=speed>>1;
   EAX-=ECX;
   yPos+=EAX;
   -ECX;
   ECX+=heightScreen;
   IF(long yPos < 0){
   		EAX=heightScreen;
   		EAX-=bmpHeight;
   		yPos=EAX;
	 }
	 ELSE IF(long yPos > ECX)yPos=0;
}

/*
; --=====================================================================================--
; #METHOD:      draw (VOID)
;
; #DESCRIPTION: Draws the sprite object onto the displayed DC according to its x-y location..
;
; #RETURN:      Nothing..
; --=====================================================================================--*/
void CSprite::draw(void)
{
   EAX=bmpWidth>>1;
   BitBlt(drawDC,xPos,yPos,EAX,bmpHeight,dcBitmap,EAX, 0, SRCAND);
   BitBlt(drawDC,xPos,yPos,bmpWidth>>1,bmpHeight,dcBitmap,0,0,SRCINVERT);
}

/*
; --=====================================================================================--
; #METHOD:      setSpeed (dwSpeed)
;
; #DESCRIPTION: Used to adjust the sprinte objects speed of movement..
;
; #PARAM:       dwSpeed  The value to set the new speed to..
;
; #RETURN:      Nothing..
; --=====================================================================================--*/
void fastcall CSprite::setSpeed(EAX)
{
   speed=EAX;	//get speed parameter
}

/*
; --=====================================================================================--
; #METHOD:      setScreenSize (dwWidth, dwHeight)
;
; #DESCRIPTION: Used to specify the drawing area's sreen size..
;
; #PARAM:       dwWidth       The screen width (DWORD)..
; #PARAM:       dwHeight      The screen heigth (DWORD)..
;
; #RETURN:      Nothing..
; --=====================================================================================--*/
void CSprite::setScreenSize(DWORD dwWidth,dwHeight)
{
   widthScreen=dwWidth;
   heightScreen=dwHeight;
}

/*
; --=====================================================================================--
; #METHOD:      setDrawingDC (hDC)
;
; #DESCRIPTION: Used to set the global DC that is to be displayed with the GUI.  Each
;               sprite needs this information such it can draw itself onto the same
;               DC and thus be shown..
;
; #PARAM:       hDC      A non volitile DC that this sprite can be drawn onto..
;
; #RETURN:      Nothing..
; --=====================================================================================--*/
void fastcall CSprite::setDrawingDC(EAX)
{
   drawDC=EAX;
}
