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

  1.  
  2. #include "main.h"
  3.  
  4. //inicializacia
  5. //-------------------------------------------------------------
  6. void BOMBSYSTEM::Initialize()
  7. {
  8.  
  9.     Model.Normals = false;
  10.     Model.SmoothShading = false;
  11.     Model.Specular = true;
  12.     Model.FrustrumTest = false;
  13.     Model.InitializeAse(1,"models/spitfire/bomb.ase");
  14.     Model.LoadAse(0,"models/spitfire/bomb.ase");
  15.     Model.LoadTexture("models/spitfire/bomb.bmp",GetColor(1,0,1));
  16.     Model.SetMaterial(GetMaterial(GetColor(0.7f,0.7f,0.7f),
  17.                                   GetColor(1.0f,1.0f,1.0f),
  18.                                   GetColor(0.5f,0.5f,0.5f),
  19.                                   GetColor(0.2f,0.2f,0.2f),4.5f));
  20.  
  21.     Friendly = false;
  22.     UnFriendly = false;
  23.  
  24.     Reset();    
  25.  
  26. }
  27.  
  28. //reset
  29. //-------------------------------------------------------------
  30. void BOMBSYSTEM::Reset()
  31. {
  32.     for (int i=0;i<Bomb_MaxBombs;i++)
  33.     {
  34.         Bomb[i].Active = false;
  35.     }
  36. }
  37.  
  38. //refresh
  39. //-------------------------------------------------------------
  40. void BOMBSYSTEM::Refresh()
  41. {
  42.  
  43.     for (int i=0;i<Bomb_MaxBombs;i++)
  44.     {
  45.         if (Bomb[i].Active == false)
  46.             continue;
  47.  
  48.         //process
  49.         //--------
  50.  
  51.         //ak spadne bod
  52.         if (Bomb[i].Pos.Y < -1000.0f)
  53.             Bomb[i].Active = false;
  54.  
  55.         //kolizia
  56.         if (Collision(Bomb[i].Pos,Get3D(Bomb[i].Pos.X + Power(Bomb[i].BPower) * Bomb[i].Sme.X,
  57.                                         Bomb[i].Pos.Y + Power(Bomb[i].BPower) * Bomb[i].Sme.Y,
  58.                                         Bomb[i].Pos.Z + Power(Bomb[i].BPower) * Bomb[i].Sme.Z)))
  59.         {
  60.  
  61.             //spusti particle
  62.             Explo.SpawnExplosion(Bomb[i].Pos);
  63.             Explo.SpawnParticle(Bomb[i].Pos);
  64.             Explo.F_Plane.Spawn(Bomb[i].Pos);
  65.             Explo.F_Ball.Spawn(Bomb[i].Pos);
  66.     
  67.             //zvuk
  68.             SoundLib.ExplodeLarge.SetPosition(Bomb[i].Pos,ExplodeLarge_Scale);
  69.             SoundLib.ExplodeLarge.Play();
  70.  
  71.             //deaktivuk
  72.             Bomb[i].Active = false;
  73.             continue;
  74.  
  75.         }
  76.         
  77.         //urcenie vektoru
  78.         Bomb[i].Sme.Y += Power(-0.03f);    
  79.  
  80.         //posunutie
  81.         Bomb[i].Pos.X += Power(Bomb[i].BPower) * Bomb[i].Sme.X;
  82.         Bomb[i].Pos.Y += Power(Bomb[i].BPower) * Bomb[i].Sme.Y;
  83.         Bomb[i].Pos.Z += Power(Bomb[i].BPower) * Bomb[i].Sme.Z;
  84.  
  85.  
  86.         //render
  87.         //---------
  88.             
  89.         Model.Pos = Bomb[i].Pos;
  90.         Model.Rot = GetRotationSme(Bomb[i].Sme);
  91.         Model.Render();
  92.  
  93.         //dym za bombou
  94.         Explo.SpawnSmokeBomb(Bomb[i].Pos);
  95.  
  96.     }
  97.  
  98. }
  99.  
  100. //kollizia
  101. //--------------------------------------------------------------
  102. bool BOMBSYSTEM::Collision(VECTOR3D P1, VECTOR3D P2)
  103. {
  104.  
  105.     int i;
  106.  
  107.     //
  108.     //Zem
  109.     if (Level.Krajina.Collise(P1,P2) == false)
  110.     {
  111.         return false;
  112.     }
  113.  
  114.     VECTOR3D Point = Level.Krajina.IntPos;
  115.     VECTOR3D B1,B2,B3,B4;
  116.  
  117.     B1 = Point; B1.X = Point.X - Bomb_Range; B1.Y = Point.Y + Bomb_Range;
  118.     B2 = Point; B2.X = Point.X + Bomb_Range; B2.Y = Point.Y - Bomb_Range;
  119.     B3 = Point; B3.Z = Point.Z - Bomb_Range; B3.Y = Point.Y + Bomb_Range;
  120.     B4 = Point; B4.Z = Point.Z + Bomb_Range; B4.Y = Point.Y - Bomb_Range;
  121.  
  122.     //
  123.     //Strucure
  124.     for (i=0;i<Max_Structures;i++)
  125.     {
  126.         if (Level.Structure[i].CollisionBox(B1,B2) == true ||
  127.             Level.Structure[i].CollisionBox(B3,B4) == true)
  128.         {
  129.             Level.Structure[i].Life -= Bomb_Power;
  130.         }
  131.     }
  132.  
  133.     //
  134.     //Truck
  135.     for (i=0;i<Max_Trucks;i++)
  136.     {
  137.         if (Level.Truck[i].CollisionBox(B1,B2) == true ||
  138.             Level.Truck[i].CollisionBox(B3,B4) == true)
  139.         {
  140.             Level.Truck[i].Life -= Bomb_Power;
  141.         }
  142.     }
  143.  
  144.     return true;
  145.  
  146. }
  147.  
  148. //vypustenie bomby
  149. //---------------------------------------------------------------
  150. void BOMBSYSTEM::SpawnBomb(VECTOR3D Pos, VECTOR3D Rot, float BPower)
  151. {
  152.  
  153.     for (int i=0;i<Bomb_MaxBombs;i++)
  154.     {
  155.         if (Bomb[i].Active == true)
  156.             continue;
  157.  
  158.         Bomb[i].Active = true;
  159.         Bomb[i].Pos = Pos;
  160.     
  161.         Bomb[i].BPower = BPower;
  162.  
  163.         Bomb[i].Sme.X = (cosf(Rot.X)*1.0f)*sinf(Rot.Y);
  164.         Bomb[i].Sme.Y = -1.0f * sinf(Rot.X);
  165.         Bomb[i].Sme.Z = (cosf(Rot.X)*1.0f)*cosf(Rot.Y);
  166.  
  167.         break;
  168.  
  169.     }
  170. }