home *** CD-ROM | disk | FTP | other *** search
/ PC World 2006 July & August / PCWorld_2006-07-08_cd.bin / temacd / planearcade / planearcade.exe / Tank3.bmp / truck.cpp < prev    next >
C/C++ Source or Header  |  2004-09-28  |  4KB  |  213 lines

  1.  
  2. #include "main.h"
  3.  
  4.  
  5.  
  6.  
  7. //inicializacia 
  8. //--------------------------------------------------------------
  9. void TRUCK::Initialize()
  10. {
  11.  
  12.     //Bullet
  13.     //---------
  14.     Bullet.Initialize();
  15.     Bullet.UnFriendly = true;
  16.  
  17.     //reset
  18.     //-------
  19.     Reset();
  20. }
  21.  
  22.  
  23. //reset
  24. //--------------------------------------------------------------
  25. void TRUCK::Reset()
  26. {
  27.     //vlastnosti
  28.     Life = 150;
  29.  
  30.     //aktivacia
  31.     Active = false;
  32.     ActiveTime = 0.0f;
  33.  
  34.     //ciel 
  35.     Target = false;
  36.  
  37.     //m≤dy
  38.     NormalMode = true;
  39.     DestroyedMode = false;
  40.     CrazyMode = false;
  41.  
  42.     //AI mody
  43.     Utok = false;        
  44.     Sledovanie = true; 
  45.  
  46.     //pozicia a matica
  47.     Pos = Get3D(0.0f,0.0f,0.0f);
  48.     Rot = Get3D(0.0f,0.0f,0.0f);
  49.     Matrix = GetMatrix(Pos,Rot,Get3D(1.0f,1.0f,1.0f));
  50.  
  51.     //strely
  52.     Bullet.Reset();
  53.     BulletTime = 0.0f;
  54.     CannonPosition = Get3D(0.0f,0.0f,0.0f);
  55.     CannonRotation = Get3D(0.0f,0.0f,0.0f);
  56.  
  57. }
  58.  
  59. //refresh
  60. //-------------------------------------------------------------
  61. void TRUCK::Refresh()
  62. {
  63.  
  64.     //ak nieje aktviny vyhod
  65.     if (Active == false)
  66.         return;
  67.  
  68.     //------------------------------------
  69.     //Vypocitanie matice a pomocnych bodov
  70.     //------------------------------------
  71.     Matrix = GetMatrix(Pos,Rot,F_Scale);
  72.  
  73.     //-------------
  74.     //Process
  75.     //-------------
  76.  
  77.     //vypocita vzdialonost
  78.     float Dis = CalcDistance(SpitFire.Pos,Pos);
  79.     if (Dis > Truck_Distance)
  80.         Utok = false;
  81.     else
  82.         Utok = true;
  83.  
  84.     //
  85.     //Normal
  86.     //---------
  87.     if (NormalMode == true)
  88.     {
  89.         //-------
  90.  
  91.         //pozicia
  92.         CannonPosition = TransformPoint(Truck_CannonPos,Matrix);
  93.  
  94.         //rotacia
  95.         CannonRotation = GetRotationLok(CannonPosition,SpitFire.Pos);
  96.  
  97.         //-------
  98.         if (Utok == true)
  99.         {
  100.             //strielanie
  101.             BulletTime += PowerTime(1.0f);
  102.             if (BulletTime > Truck_BulletFreq)
  103.             {
  104.                 //vypusti bullet
  105.                 Bullet.SpawnBullet(CannonPosition,CannonRotation);
  106.  
  107.                 //zvuk
  108.                 SoundLib.FireUnFriendly.SetPosition(CannonPosition,FireUnFriendly_Scale);
  109.                 SoundLib.FireUnFriendly.Play();
  110.  
  111.                 BulletTime = 0.0f;
  112.  
  113.             }
  114.         }
  115.  
  116.         //--------
  117.         if (Life <= 0)
  118.         {
  119.             CrazyMode = true;
  120.             NormalMode = false;
  121.  
  122.             //particle
  123.             Explo.SpawnExplosion(Pos);
  124.             Explo.SpawnParticle(Pos);
  125.             Explo.F_Plane.Spawn(Get3D(Pos.X,Pos.Y,Pos.Z));
  126.             Explo.F_Ball.Spawn(Pos);
  127.  
  128.             //zvuk
  129.             SoundLib.ExplodeLarge.SetPosition(Pos,ExplodeLarge_Scale);
  130.             SoundLib.ExplodeLarge.Play();
  131.  
  132.             //vypusti score particle
  133.             Score.DrawScore(Score_Truck,Pos);
  134.  
  135.             //pripocita score
  136.             SpitFire.Score += Score_Truck;
  137.         }
  138.     }
  139.     //
  140.     //CrazyMode
  141.     //---------
  142.     else if (CrazyMode == true)
  143.     {
  144.         ActiveTime += PowerTime(1.0f);
  145.         if (ActiveTime > Truck_CrazyTime)
  146.         {
  147.             DestroyedMode = true;
  148.             CrazyMode = false;
  149.         }
  150.  
  151.         Pos.Y += Power(3.0f) * cosf(ActiveTime/500.0f);
  152.     }
  153.     //
  154.     //destroyed
  155.     //----------
  156.     else if (DestroyedMode == true)
  157.     {
  158.         //smoke
  159.         Explo.SpawnSmokeGround(Pos);
  160.  
  161.         ActiveTime += PowerTime(1.0f);
  162.         if (ActiveTime > Truck_DestroyTime)
  163.         {
  164.             Active = false;
  165.         }
  166.     }
  167.  
  168.     //--------------
  169.     //render
  170.     //--------------
  171.  
  172.     //bullets
  173.     Bullet.Refresh();
  174.  
  175.     //normal
  176.     if (NormalMode == true)
  177.     {
  178.  
  179.         //podvozok
  180.         ModelLib.Truck_ModelBack.Pos = Pos;
  181.         ModelLib.Truck_ModelBack.Rot = Rot;
  182.         ModelLib.Truck_ModelBack.Render();
  183.  
  184.         //cannon
  185.         ModelLib.Truck_ModelCannon.Pos = CannonPosition;
  186.         ModelLib.Truck_ModelCannon.Rot = CannonRotation;
  187.         ModelLib.Truck_ModelCannon.Render();
  188.     }
  189.     //CrazyMode Destroyed Mode
  190.     else if (CrazyMode == true || DestroyedMode == true)
  191.     {
  192.         ModelLib.Truck_ModelDestroyed.Pos = Pos;
  193.         ModelLib.Truck_ModelDestroyed.Rot = Rot;
  194.         ModelLib.Truck_ModelDestroyed.Render();
  195.         
  196.     }
  197.  
  198. }
  199.  
  200. //kolizia box
  201. //------------------------------------------------------------
  202. bool TRUCK::CollisionBox(VECTOR3D P1, VECTOR3D P2)
  203. {
  204.     return ModelLib.Truck_ModelDestroyed.CollisionBox(P1,P2,Matrix);
  205. }
  206.  
  207. //kolizia detail
  208. //-------------------------------------------------------------
  209. bool TRUCK::CollisionDetail(VECTOR3D P1, VECTOR3D P2)
  210. {
  211.     return ModelLib.Truck_ModelDestroyed.CollisionDetail(P1,P2, Matrix);
  212. }
  213.