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

  1.  
  2. #include "main.h"
  3.  
  4. //Inicializacia
  5. //----------------------------------------------------------
  6. void BOMBARDER::Initialize()
  7. {
  8.  
  9.     //gulky
  10.     //--------------
  11.     Bullet.Initialize();
  12.     Bullet.UnFriendly = true;
  13.  
  14.     //bomby
  15.     //----------
  16.     Bomb.Initialize();
  17.     Bomb.UnFriendly = true;
  18.  
  19.     //zvuk
  20.     //------------
  21.     if (SoundEnabled3D == 1)
  22.     {
  23.         Sound.InitialiseForWavMidi3D();
  24.         Sound.LoadSound("sounds/bombarder.wav");
  25.     }
  26.  
  27.     //reset hodnot
  28.     //------------
  29.     Reset();
  30. }
  31.  
  32. //reset hodnot - na konci kazdej hry
  33. //----------------------------------------------------------
  34. void BOMBARDER::Reset()
  35. {
  36.  
  37.     Target = Get3D(0.0f,0.0f,0.0f);
  38.  
  39.     Mode = 0;
  40.  
  41.     BulletTime = 0.0f;
  42.     Bullet.Reset();
  43.  
  44.     BombTime = 0.0f;
  45.     Bomb.Reset();
  46.  
  47.     Active = false;
  48.     ActiveTime = 0.0f;
  49.     Life = 1;
  50.  
  51.     SoundPlay = false;
  52.     Sound.Stop();
  53.  
  54.     NormalMode = true;
  55.     CrazyMode = false;
  56.     DestroyedMode = false;
  57.  
  58.     AITime = 0.0f;
  59.     Pos = Get3D(0.0f,0.0f,0.0f);
  60.     Rot = Get3D(0.0f,0.0f,0.0f);
  61.     ActRotZ = 0.0f;
  62.     Matrix = GetMatrix(Pos,Rot,F_Scale);
  63.  
  64.     VrtulaRotation = 0.0f;
  65.  
  66. }
  67.  
  68. //zastavi zvuk bombardera
  69. //--------------------------------------------------------------
  70. void BOMBARDER::StopSound()
  71. {
  72.     Sound.Stop();
  73.     SoundPlay = false;
  74. }
  75.  
  76. //kolizia
  77. //--------------------------------------------------------------
  78. bool BOMBARDER::CollisionBox(VECTOR3D P1, VECTOR3D P2)
  79. {
  80.     //ak nieje je aktviny
  81.     if (Active == false)
  82.         return false;
  83.  
  84.     //ak je zostreleny
  85.     if (DestroyedMode == true)
  86.         return false;
  87.  
  88.     return ModelLib.Bombarder_ModelNormal.CollisionBox(P1,P2,Matrix);
  89.  
  90. }
  91.  
  92. //kolizia
  93. //--------------------------------------------------------------
  94. bool BOMBARDER::CollisionDetail(VECTOR3D P1, VECTOR3D P2)
  95. {
  96.     //ak nieje je aktviny
  97.     if (Active == false)
  98.         return false;
  99.  
  100.     //ak je zostreleny
  101.     if (DestroyedMode == true)
  102.         return false;
  103.  
  104.     return ModelLib.Bombarder_ModelNormal.CollisionDetail(P1,P2,Matrix);
  105.  
  106. }
  107.  
  108. //zisti koliziu so zemov
  109. //--------------------------------------------------------------
  110. bool BOMBARDER::GetGroundCollision()
  111. {
  112.  
  113.     //Zem
  114.     //-------------
  115.     if (Level.Krajina.Collise(PR,PL) == true)
  116.     {
  117.         return true;
  118.     }
  119.     if (Level.Krajina.Collise(PB,PF) == true)
  120.     {
  121.         return true;
  122.     }
  123.     
  124.     return false;
  125. }
  126.  
  127. //refresh & render
  128. //--------------------------------------------------------------
  129. void BOMBARDER::Refresh()
  130. {
  131.  
  132.     //ak nieje aktivny vyhod
  133.     if (Active == false)
  134.         return;
  135.  
  136.     //-------------------------------------
  137.     //vypocitanie matice podla ktorej sa posunie
  138.     //------------------------------------
  139.     Matrix = GetMatrix(Pos,Rot,F_Scale);
  140.  
  141.     //------------------
  142.     //umela inteligencia
  143.     //------------------
  144.     if (NormalMode)
  145.     {
  146.  
  147.         //sledovanie targetu
  148.         //------------------
  149.         D3DXMATRIX AiMatrix = GetMatrix(Pos,Get3D(0.0f,Rot.Y,0.0f),F_Scale);
  150.         VECTOR3D Tar = UnTransformPoint(Target,AiMatrix);
  151.  
  152.         //vodorovne
  153.         ActRotZ = -(Tar.X)/500.0f;            
  154.         
  155.         if (ActRotZ >  Bombarder_MaxSteerZ) ActRotZ =  Bombarder_MaxSteerZ;
  156.         if (ActRotZ < -Bombarder_MaxSteerZ) ActRotZ = -Bombarder_MaxSteerZ;
  157.             
  158.         //RotaciaZ
  159.         Rot.Z += (ActRotZ-Rot.Z) * Power(Bombarder_FactorZ);
  160.             
  161.         //RotaciaY
  162.         Rot.Y -= Power(sinf(Rot.Z)*Bombarder_FactorY);
  163.  
  164.         //strielanie
  165.         //----------
  166.         AITime += PowerTime(0.001f);
  167.         if (AITime > Bombarder_MaxTime)
  168.             AITime = 0.0f;
  169.  
  170.         BulletTime += PowerTime(1.0f);
  171.  
  172.         if (Mode == 1 && AITime > Bombarder_FireTime && BulletTime > Bombarder_BulletFreq)
  173.         {
  174.             if (SpitFire.Pos.X > Pos.X - 1300.0f && SpitFire.Pos.X < Pos.X + 1300.0f &&
  175.                 SpitFire.Pos.Y > Pos.Y - 400.0f && SpitFire.Pos.Y < Pos.Y + 400.0f &&
  176.                 SpitFire.Pos.Z > Pos.Z - 1300.0f && SpitFire.Pos.Z < Pos.Z + 1300.0f)
  177.             {
  178.                 VECTOR3D CRot = GetRotationLok(BL,SpitFire.Pos);
  179.                 Bullet.SpawnBullet(BL,CRot);
  180.                 BulletTime = 0.0f;
  181.  
  182.                 //zvuk
  183.                 SoundLib.FireUnFriendly.SetPosition(Pos,FireUnFriendly_Scale);
  184.                 SoundLib.FireUnFriendly.Play();
  185.                                 
  186.             }
  187.  
  188.         }
  189.         
  190.         //bomby
  191.         //---------
  192.         BombTime += PowerTime(1.0f);
  193.         if (BombTime > Bombarder_BombFreq)
  194.         {
  195.             if(Tar.X < 250.0f && Tar.X > -250.0f &&
  196.                Tar.Z < 850.0f && Tar.Z > 200.0f)
  197.             {
  198.                 Bomb.SpawnBomb(Pos,Rot,Bombarder_Speed);
  199.                 BombTime = 0.0f;
  200.             }
  201.         }
  202.         
  203.     }
  204.  
  205.     //---------
  206.     //posunutie
  207.     //---------
  208.     if (NormalMode || CrazyMode)
  209.     {
  210.     
  211.         Pos = TransformPoint(Get3D(0.0f,0.0f,Power(Bombarder_Speed)),
  212.                               Matrix);
  213.     }
  214.  
  215.     //-------------------------------------
  216.     //vypocitanie matice a koliznych bodov
  217.     //------------------------------------
  218.     Matrix = GetMatrix(Pos,Rot,F_Scale);
  219.  
  220.     //kolizne body
  221.     PL = Bombarder_Left;
  222.     PR = Bombarder_Right;
  223.     PF = Bombarder_Front;
  224.     PB = Bombarder_Back;
  225.  
  226.     PL = TransformPoint(PL,Matrix);
  227.     PR = TransformPoint(PR,Matrix);
  228.     PB = TransformPoint(PB,Matrix);
  229.     PF = TransformPoint(PF,Matrix);
  230.  
  231.     //gulomety
  232.     BL = TransformPoint(Bombarder_BulletLeft,Matrix);
  233.     BR = TransformPoint(Bombarder_BulletRight,Matrix);
  234.  
  235.     //vrtula
  236.     PVLeft = TransformPoint(Bombarder_VrtulaPointLeft,Matrix);
  237.     PVRight = TransformPoint(Bombarder_VrtulaPointRight,Matrix);
  238.  
  239.     //Explo
  240.     PE1 = TransformPoint(Bombarder_ExploPoint1,Matrix);
  241.     PE2 = TransformPoint(Bombarder_ExploPoint2,Matrix);
  242.  
  243.     //----------------
  244.     //kolizia so zemov
  245.     //----------------
  246.     bool GroundCollision = GetGroundCollision();
  247.  
  248.     //-------------
  249.     //Zvuk motora
  250.     //-------------
  251.     if (NormalMode || CrazyMode)
  252.     {
  253.         if (SoundPlay == false && Menu.EnabledBriefring == false)
  254.         {
  255.             SoundPlay = true;
  256.             Sound.Play(true);    
  257.         }
  258.  
  259.         Sound.SetPosition(Pos,Bombarder_SoundScale);
  260.     }
  261.  
  262.     //-------------
  263.     //process
  264.     //-------------
  265.     if (NormalMode)
  266.     {
  267.         
  268.         //kolizia zo zemov
  269.         if (GroundCollision == true)
  270.         {
  271.             //particle
  272.             Explo.SpawnExplosion(PE1);
  273.             Explo.SpawnParticle(PE1);
  274.             Explo.F_Plane.Spawn(PE1);
  275.             Explo.F_Ball.Spawn(PE1);
  276.             Explo.SpawnExplosion(PE2);
  277.             Explo.SpawnParticle(PE2);
  278.             Explo.F_Plane.Spawn(PE2);
  279.             Explo.F_Ball.Spawn(PE2);
  280.  
  281.             DestroyedMode = true;
  282.             NormalMode = false;
  283.  
  284.             //zvuk
  285.             SoundLib.ExplodeLarge.SetPosition(Pos,ExplodeLarge_Scale);
  286.             SoundLib.ExplodeLarge.Play();
  287.  
  288.             //zastav zvuk motora
  289.             Sound.Stop();
  290.         }
  291.  
  292.         //zivoty
  293.         if (Life <= 0)
  294.         {
  295.             //particle
  296.             Explo.SpawnExplosion(PE1);
  297.             Explo.SpawnParticle(PE1);
  298.             Explo.F_Plane.Spawn(PE1);
  299.             Explo.F_Ball.Spawn(PE1);
  300.             Explo.SpawnExplosion(PE2);
  301.             Explo.SpawnParticle(PE2);
  302.             Explo.F_Plane.Spawn(PE2);
  303.             Explo.F_Ball.Spawn(PE2);
  304.  
  305.             CrazyMode = true;
  306.             NormalMode = false;
  307.  
  308.             //zvuk
  309.             SoundLib.ExplodeSmall.SetPosition(Pos,ExplodeSmall_Scale);
  310.             SoundLib.ExplodeSmall.Play();
  311.  
  312.             //vypusti score particle
  313.             Score.DrawScore(Score_Bombarder,Pos);
  314.  
  315.             //pripocita score
  316.             SpitFire.Score += Score_Bombarder;            
  317.         }
  318.         
  319.     }
  320.     else if(CrazyMode)
  321.     {
  322.  
  323.         //kolizia zo zemov
  324.         if (GroundCollision == true)
  325.         {
  326.  
  327.             //particle
  328.             Explo.SpawnExplosion(PE1);
  329.             Explo.SpawnParticle(PE1);
  330.             Explo.F_Plane.Spawn(PE1);
  331.             Explo.F_Ball.Spawn(PE1);
  332.             Explo.SpawnExplosion(PE2);
  333.             Explo.SpawnParticle(PE2);
  334.             Explo.F_Plane.Spawn(PE2);
  335.             Explo.F_Ball.Spawn(PE2);
  336.  
  337.  
  338.             DestroyedMode = true;
  339.             CrazyMode = false;
  340.  
  341.             //zvuk
  342.             SoundLib.ExplodeLarge.SetPosition(Pos,ExplodeLarge_Scale);
  343.             SoundLib.ExplodeLarge.Play();
  344.  
  345.             //zastav zvuk motora
  346.             Sound.Stop();
  347.         }
  348.  
  349.         //crazy
  350.         Rot.Z += Power(0.01f);
  351.         Rot.X += Power(0.005f);
  352.         Pos.Y -= Power(2.0f);
  353.  
  354.         //particle
  355.         Explo.SpawnSmokePlane(PE1);
  356.         Explo.SpawnSmokeHit(PE1);
  357.         Explo.SpawnSmokePlane(PE2);
  358.         Explo.SpawnSmokeHit(PE2);
  359.  
  360.     }
  361.     else if(DestroyedMode)
  362.     {
  363.         Explo.SpawnSmokeGround(PE1);
  364.         Explo.SpawnSmokeGround(PE2);
  365.  
  366.         ActiveTime += PowerTime(1.0f);
  367.         if (ActiveTime > Bombarder_DestroyTime)
  368.             Active = false;
  369.     }
  370.  
  371.     //----------
  372.     //Render
  373.     //-----------
  374.  
  375.     //Naboje
  376.     Bullet.Refresh();
  377.  
  378.     //bomby
  379.     Bomb.Refresh();
  380.  
  381.     //Normal
  382.     if ((NormalMode)||(CrazyMode))
  383.     {
  384.         //model
  385.         ModelLib.Bombarder_ModelNormal.Pos = Pos;
  386.         ModelLib.Bombarder_ModelNormal.Rot = Rot;
  387.         ModelLib.Bombarder_ModelNormal.Render();
  388.  
  389.         //vrtula
  390.         VrtulaRotation += Power(Bombarder_Speed/20.0f);
  391.         
  392.         ModelLib.Vrtula.Sca = Get3D(1.4f,1.4f,1.4f);
  393.         Engine.SetAlphaTest(true);
  394.         Engine.SetBlendTrans();
  395.  
  396.         ModelLib.Vrtula.Pos = PVLeft;
  397.         ModelLib.Vrtula.Rot = Rot;
  398.         ModelLib.Vrtula.Rot.Z = VrtulaRotation;
  399.         ModelLib.Vrtula.Color.A = 0.6f;
  400.  
  401.         ModelLib.Vrtula.Render();
  402.  
  403.         ModelLib.Vrtula.Pos = PVRight;
  404.         ModelLib.Vrtula.Rot = Rot;
  405.         ModelLib.Vrtula.Rot.Z = VrtulaRotation+0.5f;
  406.         ModelLib.Vrtula.Color.A = 0.6f;
  407.  
  408.         ModelLib.Vrtula.Render();
  409.         
  410.         Engine.SetBlendNone();
  411.         ModelLib.Vrtula.Sca = F_Scale;
  412.  
  413.  
  414.     }
  415.  
  416.     //destroyed
  417.     else if(DestroyedMode)
  418.     {
  419.         ModelLib.Bombarder_ModelDestroyed.Pos = Pos;
  420.         ModelLib.Bombarder_ModelDestroyed.Rot = Rot;
  421.         ModelLib.Bombarder_ModelDestroyed.Render();
  422.     }
  423.  
  424.  
  425. }
  426.  
  427.