Making a 2D game. this part of the code should move a texture randomly over a textured background, use clipping/blitting to draw the texture partially off the screen and use transparency on the texture.
Here's my class declaration & member-function definitions ( which are saved in different files)
Code:
//rectangle class
class CRect {
public:
//constructor & destructor
CRect(){ left = right = top = bottom = 0;}
~ CRect(){};
CRect (int l, int r, int t, int b ) : left (l), right (r), top (t), bottom (b) {};
CRect (const CRect &otherRect):left (other.left), right (other.right), top (other.top), bottom (other.bottom) {};
//functions for returning width & height
int sourceWidth () const {return right-left;}
int sourceHeight () const {return top-botton;}
private:
int left, right, top, bottom;
};
///////////////////////////////////////////////////////////////////////////////
#include "Crect.h"
//function to clip source rectangle against destination rectangle
void ClipFn ( BYTE *destination, int destWidth, const CRect &destRect, BYTE *source, int sourceWidth, const CRect &sourceRect, int posX, int posY )
{
CRect newSourceRect ( 0, sourceRect.Width(), 0, sourceRect.Height() );
source.left + posX, source.right + posX, source.top + posY, source.bottom + posY;
if (otherRect.left > left )
left = otherRect.left;
if (otherRect.right < right )
right = otherRect.right;
if (otherRect.top > top )
top = otherRect.top;
if (otherRect.bottom < bottom )
bottom = otherRect.bottom;
source.left - posX, source.right - posX, source.top - posY, source.bottom - posY;
newSourceRect.left += sourceRect.left;
newSourceRect.right += sourceRect.left;
newSourceRect.top += sourceRect.top;
newSourceRect.bottom += sourceRect.top;
//call to blitting function
BlitFn ( destination, source, destWidth, sourceWidth, newSourceRect, newPosX, newPosY );
}
////////////////////////////////////////////////////////////////////////////////////
//duno where to implement this bit - think it should be a member function of class and used there.
void clip ( const CRect &sourceRect )
{
result = source;
if ( source.right + posX > destination.right )
result.right = destination.right - posX;
if ( source.bottom + posX > destination.bottom )
result.bottom = destination.bottom - posY;
}
Biggest problem is in the class declaration where there are 9 errors in the one line as 'other' is undeclared and therefore all the members (left,right,top&bottom)of 'other' have no type.
Code:
CRect (const CRect &otherRect):left (other.left), right (other.right), top (other.top), bottom (other.bottom) {};
any ideas on how to fix this?
also anybody know where i should implement the clipping & blitting functions within my game loop?
resources:
Task Specification - http://scm-intranet.tees.ac.uk/users...stones.html#M2