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 >
Wrap
C/C++ Source or Header
|
2004-09-12
|
9KB
|
427 lines
#include "main.h"
//Inicializacia
//----------------------------------------------------------
void BOMBARDER::Initialize()
{
//gulky
//--------------
Bullet.Initialize();
Bullet.UnFriendly = true;
//bomby
//----------
Bomb.Initialize();
Bomb.UnFriendly = true;
//zvuk
//------------
if (SoundEnabled3D == 1)
{
Sound.InitialiseForWavMidi3D();
Sound.LoadSound("sounds/bombarder.wav");
}
//reset hodnot
//------------
Reset();
}
//reset hodnot - na konci kazdej hry
//----------------------------------------------------------
void BOMBARDER::Reset()
{
Target = Get3D(0.0f,0.0f,0.0f);
Mode = 0;
BulletTime = 0.0f;
Bullet.Reset();
BombTime = 0.0f;
Bomb.Reset();
Active = false;
ActiveTime = 0.0f;
Life = 1;
SoundPlay = false;
Sound.Stop();
NormalMode = true;
CrazyMode = false;
DestroyedMode = false;
AITime = 0.0f;
Pos = Get3D(0.0f,0.0f,0.0f);
Rot = Get3D(0.0f,0.0f,0.0f);
ActRotZ = 0.0f;
Matrix = GetMatrix(Pos,Rot,F_Scale);
VrtulaRotation = 0.0f;
}
//zastavi zvuk bombardera
//--------------------------------------------------------------
void BOMBARDER::StopSound()
{
Sound.Stop();
SoundPlay = false;
}
//kolizia
//--------------------------------------------------------------
bool BOMBARDER::CollisionBox(VECTOR3D P1, VECTOR3D P2)
{
//ak nieje je aktviny
if (Active == false)
return false;
//ak je zostreleny
if (DestroyedMode == true)
return false;
return ModelLib.Bombarder_ModelNormal.CollisionBox(P1,P2,Matrix);
}
//kolizia
//--------------------------------------------------------------
bool BOMBARDER::CollisionDetail(VECTOR3D P1, VECTOR3D P2)
{
//ak nieje je aktviny
if (Active == false)
return false;
//ak je zostreleny
if (DestroyedMode == true)
return false;
return ModelLib.Bombarder_ModelNormal.CollisionDetail(P1,P2,Matrix);
}
//zisti koliziu so zemov
//--------------------------------------------------------------
bool BOMBARDER::GetGroundCollision()
{
//Zem
//-------------
if (Level.Krajina.Collise(PR,PL) == true)
{
return true;
}
if (Level.Krajina.Collise(PB,PF) == true)
{
return true;
}
return false;
}
//refresh & render
//--------------------------------------------------------------
void BOMBARDER::Refresh()
{
//ak nieje aktivny vyhod
if (Active == false)
return;
//-------------------------------------
//vypocitanie matice podla ktorej sa posunie
//------------------------------------
Matrix = GetMatrix(Pos,Rot,F_Scale);
//------------------
//umela inteligencia
//------------------
if (NormalMode)
{
//sledovanie targetu
//------------------
D3DXMATRIX AiMatrix = GetMatrix(Pos,Get3D(0.0f,Rot.Y,0.0f),F_Scale);
VECTOR3D Tar = UnTransformPoint(Target,AiMatrix);
//vodorovne
ActRotZ = -(Tar.X)/500.0f;
if (ActRotZ > Bombarder_MaxSteerZ) ActRotZ = Bombarder_MaxSteerZ;
if (ActRotZ < -Bombarder_MaxSteerZ) ActRotZ = -Bombarder_MaxSteerZ;
//RotaciaZ
Rot.Z += (ActRotZ-Rot.Z) * Power(Bombarder_FactorZ);
//RotaciaY
Rot.Y -= Power(sinf(Rot.Z)*Bombarder_FactorY);
//strielanie
//----------
AITime += PowerTime(0.001f);
if (AITime > Bombarder_MaxTime)
AITime = 0.0f;
BulletTime += PowerTime(1.0f);
if (Mode == 1 && AITime > Bombarder_FireTime && BulletTime > Bombarder_BulletFreq)
{
if (SpitFire.Pos.X > Pos.X - 1300.0f && SpitFire.Pos.X < Pos.X + 1300.0f &&
SpitFire.Pos.Y > Pos.Y - 400.0f && SpitFire.Pos.Y < Pos.Y + 400.0f &&
SpitFire.Pos.Z > Pos.Z - 1300.0f && SpitFire.Pos.Z < Pos.Z + 1300.0f)
{
VECTOR3D CRot = GetRotationLok(BL,SpitFire.Pos);
Bullet.SpawnBullet(BL,CRot);
BulletTime = 0.0f;
//zvuk
SoundLib.FireUnFriendly.SetPosition(Pos,FireUnFriendly_Scale);
SoundLib.FireUnFriendly.Play();
}
}
//bomby
//---------
BombTime += PowerTime(1.0f);
if (BombTime > Bombarder_BombFreq)
{
if(Tar.X < 250.0f && Tar.X > -250.0f &&
Tar.Z < 850.0f && Tar.Z > 200.0f)
{
Bomb.SpawnBomb(Pos,Rot,Bombarder_Speed);
BombTime = 0.0f;
}
}
}
//---------
//posunutie
//---------
if (NormalMode || CrazyMode)
{
Pos = TransformPoint(Get3D(0.0f,0.0f,Power(Bombarder_Speed)),
Matrix);
}
//-------------------------------------
//vypocitanie matice a koliznych bodov
//------------------------------------
Matrix = GetMatrix(Pos,Rot,F_Scale);
//kolizne body
PL = Bombarder_Left;
PR = Bombarder_Right;
PF = Bombarder_Front;
PB = Bombarder_Back;
PL = TransformPoint(PL,Matrix);
PR = TransformPoint(PR,Matrix);
PB = TransformPoint(PB,Matrix);
PF = TransformPoint(PF,Matrix);
//gulomety
BL = TransformPoint(Bombarder_BulletLeft,Matrix);
BR = TransformPoint(Bombarder_BulletRight,Matrix);
//vrtula
PVLeft = TransformPoint(Bombarder_VrtulaPointLeft,Matrix);
PVRight = TransformPoint(Bombarder_VrtulaPointRight,Matrix);
//Explo
PE1 = TransformPoint(Bombarder_ExploPoint1,Matrix);
PE2 = TransformPoint(Bombarder_ExploPoint2,Matrix);
//----------------
//kolizia so zemov
//----------------
bool GroundCollision = GetGroundCollision();
//-------------
//Zvuk motora
//-------------
if (NormalMode || CrazyMode)
{
if (SoundPlay == false && Menu.EnabledBriefring == false)
{
SoundPlay = true;
Sound.Play(true);
}
Sound.SetPosition(Pos,Bombarder_SoundScale);
}
//-------------
//process
//-------------
if (NormalMode)
{
//kolizia zo zemov
if (GroundCollision == true)
{
//particle
Explo.SpawnExplosion(PE1);
Explo.SpawnParticle(PE1);
Explo.F_Plane.Spawn(PE1);
Explo.F_Ball.Spawn(PE1);
Explo.SpawnExplosion(PE2);
Explo.SpawnParticle(PE2);
Explo.F_Plane.Spawn(PE2);
Explo.F_Ball.Spawn(PE2);
DestroyedMode = true;
NormalMode = false;
//zvuk
SoundLib.ExplodeLarge.SetPosition(Pos,ExplodeLarge_Scale);
SoundLib.ExplodeLarge.Play();
//zastav zvuk motora
Sound.Stop();
}
//zivoty
if (Life <= 0)
{
//particle
Explo.SpawnExplosion(PE1);
Explo.SpawnParticle(PE1);
Explo.F_Plane.Spawn(PE1);
Explo.F_Ball.Spawn(PE1);
Explo.SpawnExplosion(PE2);
Explo.SpawnParticle(PE2);
Explo.F_Plane.Spawn(PE2);
Explo.F_Ball.Spawn(PE2);
CrazyMode = true;
NormalMode = false;
//zvuk
SoundLib.ExplodeSmall.SetPosition(Pos,ExplodeSmall_Scale);
SoundLib.ExplodeSmall.Play();
//vypusti score particle
Score.DrawScore(Score_Bombarder,Pos);
//pripocita score
SpitFire.Score += Score_Bombarder;
}
}
else if(CrazyMode)
{
//kolizia zo zemov
if (GroundCollision == true)
{
//particle
Explo.SpawnExplosion(PE1);
Explo.SpawnParticle(PE1);
Explo.F_Plane.Spawn(PE1);
Explo.F_Ball.Spawn(PE1);
Explo.SpawnExplosion(PE2);
Explo.SpawnParticle(PE2);
Explo.F_Plane.Spawn(PE2);
Explo.F_Ball.Spawn(PE2);
DestroyedMode = true;
CrazyMode = false;
//zvuk
SoundLib.ExplodeLarge.SetPosition(Pos,ExplodeLarge_Scale);
SoundLib.ExplodeLarge.Play();
//zastav zvuk motora
Sound.Stop();
}
//crazy
Rot.Z += Power(0.01f);
Rot.X += Power(0.005f);
Pos.Y -= Power(2.0f);
//particle
Explo.SpawnSmokePlane(PE1);
Explo.SpawnSmokeHit(PE1);
Explo.SpawnSmokePlane(PE2);
Explo.SpawnSmokeHit(PE2);
}
else if(DestroyedMode)
{
Explo.SpawnSmokeGround(PE1);
Explo.SpawnSmokeGround(PE2);
ActiveTime += PowerTime(1.0f);
if (ActiveTime > Bombarder_DestroyTime)
Active = false;
}
//----------
//Render
//-----------
//Naboje
Bullet.Refresh();
//bomby
Bomb.Refresh();
//Normal
if ((NormalMode)||(CrazyMode))
{
//model
ModelLib.Bombarder_ModelNormal.Pos = Pos;
ModelLib.Bombarder_ModelNormal.Rot = Rot;
ModelLib.Bombarder_ModelNormal.Render();
//vrtula
VrtulaRotation += Power(Bombarder_Speed/20.0f);
ModelLib.Vrtula.Sca = Get3D(1.4f,1.4f,1.4f);
Engine.SetAlphaTest(true);
Engine.SetBlendTrans();
ModelLib.Vrtula.Pos = PVLeft;
ModelLib.Vrtula.Rot = Rot;
ModelLib.Vrtula.Rot.Z = VrtulaRotation;
ModelLib.Vrtula.Color.A = 0.6f;
ModelLib.Vrtula.Render();
ModelLib.Vrtula.Pos = PVRight;
ModelLib.Vrtula.Rot = Rot;
ModelLib.Vrtula.Rot.Z = VrtulaRotation+0.5f;
ModelLib.Vrtula.Color.A = 0.6f;
ModelLib.Vrtula.Render();
Engine.SetBlendNone();
ModelLib.Vrtula.Sca = F_Scale;
}
//destroyed
else if(DestroyedMode)
{
ModelLib.Bombarder_ModelDestroyed.Pos = Pos;
ModelLib.Bombarder_ModelDestroyed.Rot = Rot;
ModelLib.Bombarder_ModelDestroyed.Render();
}
}