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

  1. /*===========================================================================*\
  2. |
  3. |  File:        cgmisc.cpp
  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. #include <windows.h>
  31. #ifdef __WATCOMC__
  32. #include <mem.h>
  33. #else
  34. #include <memory.h>
  35. #endif
  36. #include "cgchdll.h"
  37. #include "cgchar.h"
  38. #include "cgtimer.h"
  39. #include "cginput.h"
  40. #include "cgimage.h"
  41.  
  42. char inifile [260];
  43.  
  44.  
  45. HINSTANCE hInst = NULL;            // our library instance
  46. // This is returned by the 'Ident' function, but isn't used internally at all
  47. CGameVersionIdent version =
  48. {
  49.     RELEASE1_0,
  50.     GAMEID
  51. };
  52.  
  53. // prototypes so we can fill in the action arrays
  54. int PlaneCreate( CGameCharacter *, CGameLevel * );
  55. int PlaneAction( CGameCharacter *, CGameLevel * );
  56. int PlaneDestroy( CGameCharacter *, CGameLevel * );
  57. int PlaneCollide( CGameCharacter *, CGameCharacter *, CGameLevel * );
  58.  
  59. int CloudCreate( CGameCharacter *, CGameLevel * );
  60. int CloudAction( CGameCharacter *, CGameLevel * );
  61. int CloudDestroy( CGameCharacter *, CGameLevel * );
  62. int CloudCollide( CGameCharacter *, CGameCharacter *, CGameLevel * );
  63.  
  64. // returned by 'Info' function, and isn't used either (internally)
  65. CGameCharSequenceInfo char1seq[1] =
  66. {
  67.     {"plane.spr", "Fly", 15, {"plane.wav", NULL, 100, 1}}   
  68. };
  69.  
  70. CGameCharSequenceInfo char2seq[1] =
  71. {
  72.     {"clouds.spr", "Cloud1", 30, {NULL, NULL, 100, 1}}  
  73. };
  74. CGameCharSequenceInfo char3seq[1] =
  75. {
  76.     {"clouds.spr", "Cloud2", 30, {NULL, NULL, 100, 1}}  
  77. };
  78. CGameCharSequenceInfo char4seq[1] =
  79. {
  80.     {"clouds.spr", "Cloud3", 30, {NULL, NULL, 100, 1}}  
  81. };
  82.  
  83. CGameCharInfo character1 =
  84. {
  85.     "Plane",
  86.     1,
  87.     &char1seq[0],
  88.     PlaneCreate,
  89.     PlaneAction,
  90.     PlaneDestroy,
  91.     NULL,
  92.     PlaneCollide
  93. };
  94.  
  95. CGameCharInfo character2 =
  96. {
  97.     "Cloud1",
  98.     1,
  99.     &char2seq[0],
  100.     CloudCreate,
  101.     CloudAction,
  102.     CloudDestroy,
  103.     NULL,
  104.     CloudCollide
  105. };
  106.  
  107. CGameCharInfo character3 =
  108. {
  109.     "Cloud2",
  110.     1,
  111.     &char3seq[0],
  112.     CloudCreate,
  113.     CloudAction,
  114.     CloudDestroy,
  115.     NULL,
  116.     CloudCollide
  117. };
  118.  
  119. CGameCharInfo character4 =
  120. {
  121.     "Cloud3",
  122.     1,
  123.     &char4seq[0],
  124.     CloudCreate,
  125.     CloudAction,
  126.     CloudDestroy,
  127.     NULL,
  128.     CloudCollide
  129. };
  130.  
  131. // This array allows the caller to get our information directly
  132. CGameCharInfo *characters[] =
  133. {
  134.     &character1,
  135.     &character2,
  136.     &character3,
  137.     &character4
  138. };
  139.  
  140. CGameInfo dllinfo =
  141. {
  142.     4,                 // number of characters implemented in
  143.     // this DLL
  144.     characters             // array of CGameCharInfo pointers
  145. };
  146.  
  147. // EXPORTED as ordinal #1:
  148. #ifdef __BORLANDC__
  149. extern "C" void CALLBACK Ident( CGameVersionIdent * id )
  150. #else
  151. void CALLBACK Ident( CGameVersionIdent * id )
  152. #endif
  153. {    
  154.     GetModuleFileName(NULL, inifile, 259);
  155.     char *p = strrchr(inifile, '.');
  156.     if (p)
  157.         lstrcpy(p+1, "GAM");
  158.  
  159.     memcpy( id, &version, sizeof( version ) );
  160. }
  161.  
  162. // EXPORTED as ordinal #2:
  163. #ifdef __BORLANDC__
  164. extern "C" void CALLBACK Info( CGameInfo * info )
  165. #else
  166. void CALLBACK Info( CGameInfo * info )
  167. #endif
  168. {    
  169.     memcpy( info, &dllinfo, sizeof( dllinfo ) );
  170. }
  171.  
  172. int     PlaneCreate( CGameCharacter *me, CGameLevel *level )
  173. {
  174.     int posx,posy;
  175.     me->GetXY(&posx, &posy);
  176.     me->SetVelocity(-32,0);
  177.     me->MoveTo(level->GetMaxX(), posy);
  178.     return ( ACTION_COMPLETED );
  179. }
  180.  
  181. int     PlaneAction( CGameCharacter *me, CGameLevel *level )
  182. {
  183.     int posx, posy, velx, vely;
  184.     int time = level->GetFrameTime();
  185.     int slices = (me->mLastTime == -1) ? 1 : (time - me->mLastTime);
  186.     me->mLastTime = time;
  187.  
  188.     me->GetVelocity(&velx, &vely);
  189.  
  190.     // remember to use sub-pixels!
  191.     me->GetSubXY(&posx, &posy);
  192.  
  193.  
  194.     posx += SUBPIXEL_DELTA(velx, slices);
  195.     posy += SUBPIXEL_DELTA(vely, slices);
  196.  
  197.     // did we move off the screen?  If so, start over at maxx...
  198.     if (SUB2WORLD(posx) < -level->GetMaxX())
  199.         posx = WORLD2SUB(level->GetMaxX());
  200.  
  201.     me->SetAndMove(posx, posy);
  202.     me->NextSprite(level->GetTimer()->Time, FALSE);
  203.  
  204.     return ( ACTION_COMPLETED );
  205. }
  206.  
  207. int     PlaneDestroy( CGameCharacter *me, CGameLevel *level )
  208. {
  209.     return ( ACTION_COMPLETED );
  210. }
  211.  
  212. int     PlaneCollide( CGameCharacter *me, CGameCharacter *other, CGameLevel *level )
  213. {   
  214.     return(ACTION_COMPLETED);   
  215. }
  216.  
  217.  
  218. int     CloudCreate( CGameCharacter *me, CGameLevel *level )
  219. {
  220.     me->SetVelocity(64 / (me->GetXParallax()+1),0);
  221.     return ( ACTION_COMPLETED );
  222. }
  223.  
  224. int     CloudAction( CGameCharacter *me, CGameLevel *level )
  225. {
  226.     int posx, posy, velx, vely;
  227.     int time = level->GetFrameTime();
  228.     int slices = (me->mLastTime == -1) ? 1 : (time - me->mLastTime);
  229.     me->mLastTime = time;
  230.  
  231.     me->GetVelocity(&velx, &vely);
  232.  
  233.     // remember to use sub-pixels!
  234.     me->GetSubXY(&posx, &posy);
  235.  
  236.     posx += SUBPIXEL_DELTA(velx, slices);
  237.  
  238.     // did we move off the screen?  If so, start over at maxx...
  239.     if (posx > WORLD2SUB(SCREEN_WIDTH))
  240.         posx = WORLD2SUB(-SCREEN_WIDTH);
  241.  
  242.     me->SetAndMove(posx, posy);
  243.  
  244.     return ( ACTION_COMPLETED );
  245. }
  246.  
  247. int     CloudDestroy( CGameCharacter *me, CGameLevel *level )
  248. {
  249.     return ( ACTION_COMPLETED );
  250. }
  251.  
  252. int     CloudCollide( CGameCharacter *me, CGameCharacter *other, CGameLevel *level )
  253. {   
  254.     return(ACTION_COMPLETED);   
  255. }
  256.