home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / developer_install / ReplicaNetFreewareV5_4.exe / data1.cab / Program_Executable_Files / Example4 / Projectile.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-30  |  2.7 KB  |  95 lines

  1. /* START_LICENSE_HEADER
  2.  
  3. Copyright (C) 2000 Martin Piper, original design and program code
  4. Copyright (C) 2001-2005 Replica Software
  5.  
  6. This program file is copyright (C) Replica Software and can only be used under license.
  7. For more information visit: http://www.replicanet.com/
  8. Or email: info@replicanet.com
  9.  
  10. END_LICENSE_HEADER */
  11. /*
  12. The Projectile game object. Every tick the Projectile will move
  13. This object have corresponding ROL files in the ROLFiles folder. The ROL files are compiled by the ROLCompiler.
  14. The CompiledGameObjects folder contains the compiled ROL definition file for this object. The member variables listed
  15. in the ROL file for this class are automatically updated when this object is allocated on another machine
  16. */
  17. #include "Projectile.h"
  18. #include "Enemy.h"
  19. #include "Network.h"
  20. #include "Camera.h"
  21. #include "GameDatabase.h"
  22.  
  23. Projectile::Projectile()
  24. {
  25.     SetReplicaObject(this);        // Setup our forward reference pointer
  26.     mMesh = 0;
  27.     mPosition = D3DXVECTOR4(0,0,0,0);
  28.     mRotation = D3DXVECTOR4(0,0,0,0);
  29.  
  30.     mLifetime = 0.0f;
  31. }
  32.  
  33. Projectile::~Projectile()
  34. {
  35. }
  36.  
  37. void Projectile::PollIt(void)
  38. {
  39.     mLifetime += GameDatabase::mGameFrameTick;
  40.  
  41. #define LIMIT (180.0f)
  42.  
  43.     if (mLifetime > 4.0f || mPosition.x < -LIMIT  || mPosition.x > LIMIT || mPosition.z < -LIMIT || mPosition.z > LIMIT || mPosition.y < -10.0f || mPosition.y > 500.0f)
  44.     {
  45.         Delete();
  46.         return;
  47.     }
  48.  
  49.     // Only run the "physics" if we are a master object
  50.     if (!IsMaster())
  51.     {
  52.         return;
  53.     }
  54.  
  55. #if 0
  56.     for (int i=0;i<gGameObjects.size();i++)
  57.     {
  58.         ReplicaObject *robject;
  59.         // Get the derived class object pointer that contains a base class type of ReplicaObject from the GameObject class
  60.         robject = gGameObjects[i]->mReplica;
  61.         // If there is no object pointer then ignore this object for rendering
  62.         if (!robject)
  63.         {
  64.             continue;
  65.         }
  66.         // Compare the class id of the ReplicaObject with the class ID of the ReplicaObject Plane object
  67.         // If they are the same then we can assume the type cast to a Plane class is valid
  68.         if (robject->GetClassID() == _MAKE_RO(Enemy)::StaticGetClassID())
  69.         {
  70.             D3DXVECTOR4 diff;
  71.             Enemy *proj = (Enemy *) robject;
  72.             diff = GetPosition() - proj->GetPosition();
  73.             float length = D3DXVec4Length(&diff);
  74.             if (length < 10.0f)
  75.             {
  76.                 Delete();
  77.                 return;
  78.             }
  79.         }
  80.     }
  81. #endif
  82.  
  83.     D3DXVECTOR4 velocity = D3DXVECTOR4(0,0,-100.05f,0);
  84.  
  85.     // Calculate the velocity movement
  86.     D3DXMatrixRotationYawPitchRoll(&m_matObjectMatrix,mRotation.y,mRotation.x,mRotation.z);
  87.     D3DXVECTOR4 trans;
  88.     D3DXVec4Transform(&trans,&velocity,&m_matObjectMatrix);
  89.     mPosition += trans * GameDatabase::mGameFrameTick;
  90. //    GiveDeltaHint(mPosition.x,trans.x);
  91. //    GiveDeltaHint(mPosition.y,trans.y);
  92. //    GiveDeltaHint(mPosition.z,trans.z);
  93. }
  94.  
  95.