Help Needed On Classes

This is a discussion on Help Needed On Classes within the C++ Programming forums, part of the General Programming Boards category; Making a 2D game. this part of the code should move a texture randomly over a textured background, use clipping/blitting ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    13

    Help Needed On Classes

    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

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Code:
    CRect (const CRect& otherRect):left (other.left), right (other.right), top (other.top), bottom (other.bottom) {};

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. storing derived classes in a stl container
    By *DEAD* in forum C++ Programming
    Replies: 2
    Last Post: 10-03-2008, 08:50 PM
  2. Defining multiple classes in the same header file
    By Stonehambey in forum C++ Programming
    Replies: 2
    Last Post: 08-14-2008, 11:36 AM
  3. Classes advice needed
    By DanFraser in forum C# Programming
    Replies: 5
    Last Post: 12-05-2007, 05:30 AM
  4. High Schoolers - Techy Classes?
    By mart_man00 in forum A Brief History of Cprogramming.com
    Replies: 22
    Last Post: 05-09-2003, 03:14 PM
  5. Replies: 2
    Last Post: 01-18-2003, 01:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21