home *** CD-ROM | disk | FTP | other *** search
/ NEXT Generation 27 / NEXT27.iso / pc / demos / emperor / dx3.exe / SDK / SAMPLES / IKLOWNS / CGCHAR.H < prev    next >
C/C++ Source or Header  |  1996-08-28  |  6KB  |  202 lines

  1. /*===========================================================================*\
  2. |
  3. |  File:        cgchar.h
  4. |
  5. |  Description: 
  6. |       
  7. |-----------------------------------------------------------------------------
  8. |
  9. |  Copyright (C) 1995-1996 Microsoft Corporation.  All Rights Reserved.
  10. |
  11. |  Written by Moss Bay Engineering, Inc. under contract to Microsoft Corporation
  12. |
  13. \*===========================================================================*/
  14.  
  15. /**************************************************************************
  16.  
  17.     (C) Copyright 1995-1996 Microsoft Corp.  All rights reserved.
  18.  
  19.     You have a royalty-free right to use, modify, reproduce and 
  20.     distribute the Sample Files (and/or any modified version) in 
  21.     any way you find useful, provided that you agree that 
  22.     Microsoft has no warranty obligations or liability for any 
  23.     Sample Application Files which are modified. 
  24.  
  25.     we do not recomend you base your game on IKlowns, start with one of
  26.     the other simpler sample apps in the GDK
  27.  
  28.  **************************************************************************/
  29.  
  30. #ifndef CGCHAR_H
  31. #define CGCHAR_H
  32.  
  33. #include "cgupdate.h"
  34. #include "cgaction.h"
  35. #include "cggraph.h"
  36. #include "cgchdll.h"
  37. #include "cgremote.h"
  38.  
  39. // maximum number of actions per character
  40. #define MAX_ACTIONS 32
  41.  
  42. // NOTE: our internal mCurSubX values are in 256 sub-pixel units
  43. // externally, they are pixels -- these macro convert between the 2
  44. #define SUB2WORLD( x ) ( x >> 8 )
  45. #define WORLD2SUB( x ) ( x << 8 )
  46.  
  47. class CGameCharacter : public CGameGraphic
  48. {
  49. public:
  50.     CGameCharacter( char* pFileName, 
  51.                     char* pCharName, 
  52.                     char* pGraphicKey,
  53.                     CGameLevel * pLevel,
  54.                     int minz, 
  55.                     int maxz, 
  56.                     int startx=0,
  57.                     int starty=0,
  58.                     void *pNewObjID=NULL,
  59.                     char *pRemoteName=NULL);
  60.     virtual ~CGameCharacter();
  61.     // 'instance' data so characters can keep private data if needed
  62.     void * mpPrivateData;
  63.  
  64.     // NOTE: our internal mCurSubX values are pixels * 256!
  65.     // externally, they are pixels
  66.     virtual void MoveTo( int worldX, int worldY );
  67.  
  68.     virtual void GetXY( int *worldX, int * worldY )
  69.     {
  70.         *worldX = SUB2WORLD(mCurSubX);
  71.         *worldY = SUB2WORLD(mCurSubY);
  72.     }
  73.  
  74.     virtual void SetVelocity( int vX, int vY )
  75.     {
  76.         mVelocityX = vX;
  77.         mVelocityY = vY;
  78.     }
  79.  
  80.     virtual void GetVelocity( int* pvX, int* pvY )
  81.     {
  82.         *pvX = mVelocityX;
  83.         *pvY = mVelocityY;
  84.     }
  85.  
  86.     virtual void Update(CGameLevel* pLevel, CGameUpdateList* pUpdate);
  87.     virtual void Render(CGameLevel* pLevel, CGameScreen* pScreen, CGameUpdateList* pUpdate);
  88.  
  89.     virtual HPALETTE GetHPalette()
  90.     {
  91.         return NULL;    // characters can't return palettes
  92.     }
  93.  
  94.     virtual int GetCurWidth() { return mpCurAction?mpCurAction->GetCurWidth():0; }
  95.     virtual int GetCurHeight() { return mpCurAction?mpCurAction->GetCurHeight():0; }
  96.     virtual int NextSprite(int time, BOOL wrap = TRUE);
  97.  
  98.     virtual int GetMinZ()
  99.     {
  100.         return mMinZ;
  101.     }
  102.  
  103.     virtual int GetMaxZ()
  104.     {
  105.         return mMaxZ;
  106.     }
  107.  
  108.     virtual int GetXParallax()
  109.     {
  110.         return mXParallax;
  111.     }
  112.  
  113.     virtual int GetYParallax()
  114.     {
  115.         return mYParallax;
  116.     }
  117.  
  118.     virtual void SetCurrentZ( int newZ )
  119.     {
  120.         mCurZ = newZ;       
  121.         mpLevel->ReSort();
  122.     }
  123.  
  124.     // Remote interaction methods
  125.     virtual int GetRemoteAction(void *&Data, DWORD &DataSize);
  126.     virtual int TransmitRemoteAction(int action, void *Data, DWORD DataSize);
  127.     virtual void ReleaseRemoteAction(void *);
  128.     BOOL IsRemoteControlled()
  129.     {
  130.         return fRemote;
  131.     }
  132.  
  133.     int mLastTime;      // last time (in Timer units) we updated position
  134.  
  135.     virtual int Collided (CGameCharacter *other)
  136.     {
  137.         if (pCollideFunc)
  138.             return (*pCollideFunc)( this, other, mpLevel);
  139.         else 
  140.             return 0;
  141.     }
  142.  
  143.     virtual char * GetName() 
  144.     {
  145.         return mpName;
  146.     }
  147.  
  148.     virtual void Destroy (CGameCharacter *me, CGameLevel *lev)
  149.     {
  150.         if (mpCharInfo)
  151.             mpCharInfo->Destroy(me,lev);
  152.     }
  153.  
  154.     // NOTE: our internal mCurSubX values are pixels * 256!
  155.     // externally, they are pixels -- this allows the DLL
  156.     // functions to get & set the actual values as well as move
  157.     virtual void SetAndMove( int subX, int subY )
  158.     {
  159.         MoveTo( SUB2WORLD(subX), SUB2WORLD(subY) ); // this sets curworld
  160.         mCurSubX = subX;        // so we reset
  161.         mCurSubY = subY;
  162.     }
  163.  
  164.     virtual void GetSubXY( int *subX, int * subY )
  165.     {
  166.         *subX = mCurSubX;
  167.         *subY = mCurSubY;
  168.     }
  169.  
  170.     // to allow DLL's to easily override our default behavior:
  171.     CGameCharInfo * mpCharInfo;
  172.  
  173. protected:
  174.     // for Z ordering....
  175.     int     mMinZ, mMaxZ;
  176.  
  177.     char* mpName;
  178.  
  179.     CGameAction** mpActions;    // array of action ptrs
  180.     int mNumActions;
  181.     CGameAction* mpCurAction;   // our current action
  182.  
  183.     int curState;
  184.  
  185.     // NOTE: our internal mCurSubX values are pixels * 256!
  186.     // externally, they are pixels
  187.     int mCurSubX;       // current position in world coordinates * 256
  188.     int mCurSubY;       // current position in world coordinates * 256
  189.  
  190.     int mVelocityX;     // current velocity ((pixels/256)/ms) in X dimension (sign == direction)
  191.     int mVelocityY;     // current velocity ((pixels/256)/ms) in Y dimension (sign == direction)
  192.  
  193.     pActionFunction pActFunc;
  194.     pCollideFunction pCollideFunc;
  195.     BOOL        fRemote;    // TRUE -> controlled remotely
  196.     REMOTE_OBJECT   *pObjID;    // unique object ID across all peers
  197.     CLinkedList *pActionQueue;  // actions received from remotes
  198.     CGameLevel * mpLevel;
  199. };
  200.  
  201. #endif // CGCHAR_H
  202.