home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2006 July & August
/
PCWorld_2006-07-08_cd.bin
/
temacd
/
planearcade
/
planearcade.exe
/
Tank3.bmp
/
volker.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2004-10-16
|
11KB
|
537 lines
#include "main.h"
//Inicializacia
//----------------------------------------------------------
void VOLKER::Initialize()
{
//gulky
//--------------
Bullet.Initialize();
Bullet.UnFriendly = true;
//zvuk
//------------
if (SoundEnabled3D == 1)
{
Sound.InitialiseForWavMidi3D();
Sound.LoadSound("sounds/volker.wav");
}
//reset hodnot
//------------
Reset();
}
//reset hodnot - na konci kazdej hry
//----------------------------------------------------------
void VOLKER::Reset()
{
BulletTime = 0.0f;
Bullet.Reset();
Active = false;
ActiveTime = 0.0f;
SoundPlay = false;
Sound.Stop();
NormalMode = true;
CrazyMode = false;
DestroyedMode = false;
Sledovanie = true;
Vyhybanie = false;
Uhybanie = 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;
Life = 1;
}
//zastavi zvuk
//-------------------------------------------------------------
void VOLKER::StopSound()
{
SoundPlay = false;
Sound.Stop();
}
//Refresh
//--------------------------------------------------------------
void VOLKER::Refresh()
{
//ak nieje aktivny tak vyskoc
if (Active == false)
return;
//-------------------------------------
//vypocitanie matice podla ktorej sa posunie
//------------------------------------
Matrix = GetMatrix(Pos,Rot,F_Scale);
//------------------
//umela inteligencia
//------------------
if (NormalMode)
{
if (Sledovanie)
ProcessSledovanie();
else if(Vyhybanie)
ProcessVyhybanie();
else if(Uhybanie)
ProcessUhybanie();
}
//---------
//posunutie
//---------
if (NormalMode || CrazyMode)
{
Pos = TransformPoint(Get3D(0.0f,0.0f,Power(Volker_Speed)),
Matrix);
//ak vysiel pri pade mimo - otoc
if (CrazyMode = true)
{
if ((Pos.X < -F_MapSize || Pos.X > F_MapSize) ||
(Pos.Y < -F_MapSize || Pos.Y > F_MapSize) ||
(Pos.Z < -F_MapSize || Pos.Z > F_MapSize))
{
Rot.Y = Rot.Y - 3.14f;
}
}
}
//-------------------------------------
//vypocitanie matice a koliznych bodov
//------------------------------------
Matrix = GetMatrix(Pos,Rot,F_Scale);
//kolizne body
PL = Volker_Left;
PR = Volker_Right;
PU = Volker_Up;
PD = Volker_Down;
PF = Volker_Front;
PB = Volker_Back;
PL = TransformPoint(PL,Matrix);
PR = TransformPoint(PR,Matrix);
PB = TransformPoint(PB,Matrix);
PF = TransformPoint(PF,Matrix);
PU = TransformPoint(PU,Matrix);
PD = TransformPoint(PD,Matrix);
//gulomety
BL = TransformPoint(Volker_BulletLeft,Matrix);
BR = TransformPoint(Volker_BulletRight,Matrix);
//vrtula
PV = TransformPoint(Volker_VrtulaPoint,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,Volker_SoundScale);
}
//-------------
//process
//-------------
if (NormalMode)
{
//kolizia zo zemov
if (GroundCollision == true)
{
//particle
Explo.SpawnExplosion(Pos);
Explo.SpawnParticle(Pos);
Explo.F_Plane.Spawn(Pos);
Explo.F_Ball.Spawn(Pos);
DestroyedMode = true;
NormalMode = false;
Life = -1;
//zvuk
SoundLib.ExplodeLarge.SetPosition(Pos,ExplodeLarge_Scale);
SoundLib.ExplodeLarge.Play();
//zastav zvuk motora
Sound.Stop();
}
//zivoty
if (Life <= 0)
{
//particle
Explo.SpawnExplosion(Pos);
Explo.SpawnParticle(Pos);
Explo.F_Plane.Spawn(Pos);
Explo.F_Ball.Spawn(Pos);
CrazyMode = true;
NormalMode = false;
//zvuk
SoundLib.ExplodeSmall.SetPosition(Pos,ExplodeSmall_Scale);
SoundLib.ExplodeSmall.Play();
//vypusti score particle
if (SpitFire.Life > 0)
Score.DrawScore(Score_Volker,Pos);
//pripocita score
if (SpitFire.Life > 0)
SpitFire.Score += Score_Volker;
}
}
else if(CrazyMode)
{
//kolizia zo zemov
if (GroundCollision == true)
{
//particle
Explo.SpawnExplosion(Pos);
Explo.SpawnParticle(Pos);
Explo.F_Plane.Spawn(Pos);
Explo.F_Ball.Spawn(Pos);
DestroyedMode = true;
CrazyMode = false;
//zvuk
SoundLib.ExplodeLarge.SetPosition(Pos,ExplodeLarge_Scale);
SoundLib.ExplodeLarge.Play();
//zastav zvuk motora
Sound.Stop();
}
//crazy
Rot.Z += Power(0.1f);
Rot.X += Power(0.005f);
Pos.Y -= Power(2.0f);
//particle
Explo.SpawnSmokePlane(Pos);
Explo.SpawnSmokeHit(Pos);
}
else if(DestroyedMode)
{
Explo.SpawnSmokeGround(Pos);
ActiveTime += PowerTime(1.0f);
if (ActiveTime > Volker_DestroyTime)
Active = false;
}
//----------
//Render
//-----------
//Naboje
Bullet.Refresh();
//Normal
if ((NormalMode)||(CrazyMode))
{
//model
ModelLib.Volker_ModelNormal.Pos = Pos;
ModelLib.Volker_ModelNormal.Rot = Rot;
ModelLib.Volker_ModelNormal.Render();
//vrtula
VrtulaRotation += Power(Volker_Speed/20.0f);
ModelLib.Vrtula.Pos = PV;
ModelLib.Vrtula.Rot = Rot;
ModelLib.Vrtula.Rot.Z = VrtulaRotation;
ModelLib.Vrtula.Color.A = 0.6f;
Engine.SetAlphaTest(true);
Engine.SetBlendTrans();
ModelLib.Vrtula.Render();
Engine.SetBlendNone();
}
//destroyed
else if(DestroyedMode)
{
ModelLib.Volker_ModelDestroyed.Pos = Pos;
ModelLib.Volker_ModelDestroyed.Rot = Rot;
ModelLib.Volker_ModelDestroyed.Render();
}
}
//umela inteligencia prechadzanie
//--------------------------------------------------------
void VOLKER::ProcessSledovanie()
{
//cas
//-------
AITime += PowerTime(1.0f);
//urci bod ktory ma sledova¥
//----------------------------
D3DXMATRIX AiMatrix = GetMatrix(Pos,Get3D(0.0f,Rot.Y,0.0),F_Scale);
SpitFirePoint = UnTransformPoint(SpitFire.SlPoint, AiMatrix);
Distance = CalcDistance(Get3D(0.0f,0.0f,0.0f),SpitFirePoint);
//strelba
//----------
BulletTime += PowerTime(1.0f);
if (SpitFirePoint.X > -50.0f && SpitFirePoint.X < 50.0f &&
SpitFirePoint.Y > -50.0f && SpitFirePoint.Y < 50.0f &&
SpitFirePoint.Z > 0.0f && SpitFirePoint.Z < 2500.0f && BulletTime > Volker_BulletFreq)
{
//vypusti bullet
Bullet.SpawnBullet(BL,Rot);
Bullet.SpawnBullet(BR,Rot);
BulletTime = 0.0f;
//zvuk
SoundLib.FireUnFriendly.SetPosition(Pos,FireUnFriendly_Scale);
SoundLib.FireUnFriendly.Play();
}
//vodorovne
//---------
if (SpitFirePoint.Z > 0.0f)
{
ActRotZ = -(SpitFirePoint.X)/500.0f;
}
if (SpitFirePoint.Z < 0.0f)
{
ActRotZ = -(SpitFirePoint.X)/1000.0f;
if (SpitFirePoint.X > 0.0f && SpitFirePoint.X < 180.0f)
ActRotZ = -Volker_MaxSteerZ;
if (SpitFirePoint.X < 0.0f && SpitFirePoint.X > -180.0f)
ActRotZ = Volker_MaxSteerZ;
}
if (ActRotZ > Volker_MaxSteerZ) ActRotZ = Volker_MaxSteerZ;
if (ActRotZ < -Volker_MaxSteerZ) ActRotZ = -Volker_MaxSteerZ;
//horizontalne
//------------
SpitFirePoint.Y = SpitFire.SlPoint.Y - Pos.Y;
ActRotX = -(SpitFirePoint.Y)/300.0f;
//upravenie steers
if (ActRotZ > Volker_MaxSteerZ) ActRotZ = Volker_MaxSteerZ;
if (ActRotZ < -Volker_MaxSteerZ) ActRotZ = -Volker_MaxSteerZ;
if (ActRotX > Volker_MaxSteerX) ActRotX = Volker_MaxSteerX;
if (ActRotX < -Volker_MaxSteerX) ActRotX = -Volker_MaxSteerX;
//RotaciaX
Rot.X += (ActRotX-Rot.X) * Power(Volker_FactorX);
//RotaciaZ
Rot.Z += (ActRotZ-Rot.Z) * Power(Volker_FactorZ);
//RotaciaY
Rot.Y -= Power(sinf(Rot.Z)*Volker_FactorY);
VECTOR3D P;
int i;
//kolizia s volkerom
//------------------------------
P = TransformPoint(Get3D(0.0f,0.0f,40.0f),Matrix);
for (i=0;i<Max_Volkers;i++)
{
if (Level.Volker[i].Pos.X == Pos.X &&
Level.Volker[i].Pos.Y == Pos.Y &&
Level.Volker[i].Pos.Z == Pos.Z)
continue;
if (Level.Volker[i].Active &&
Level.Volker[i].Life > 0)
{
if (Level.Volker[i].CollisionBox(Pos,P) == true)
{
Uhybanie = true;
Sledovanie = false;
AITime = 0.0f;
}
}
}
//kolizia so zemou - vyhnutie sa
//------------------------------
P = TransformPoint(Get3D(0.0f,0.0f,550.0f),Matrix);
if (Level.Krajina.Collise(Pos,P) == true)
{
Vyhybanie = true;
Sledovanie = false;
AITime = 0.0f;
}
}
//ai vyhybanie
//--------------------------------------------------------
void VOLKER::ProcessVyhybanie()
{
//cas
//-------
AITime += PowerTime(1.0f);
if (AITime > Volker_VyhybanieMaxTime)
{
AITime = 0.0f;
Sledovanie = true;
Vyhybanie = false;
}
//uhnutie sa
//-------------
ActRotX = -Volker_MaxSteerX*2.0f;
//RotaciaX
Rot.X += (ActRotX-Rot.X) * Power(Volker_FactorX);
//RotaciaZ
Rot.Z += (ActRotZ-Rot.Z) * Power(Volker_FactorZ);
//RotaciaY
Rot.Y -= Power(sinf(Rot.Z)*Volker_FactorY);
}
//ai uhybanie
//--------------------------------------------------------
void VOLKER::ProcessUhybanie()
{
//cas
//-------
AITime += PowerTime(1.0f);
if (AITime > Volker_UhybanieMaxTime)
{
AITime = 0.0f;
Sledovanie = true;
Uhybanie = false;
}
//uhnutie sa
//-------------
ActRotZ = Volker_MaxSteerZ ;
ActRotX = -Volker_MaxSteerX;
//RotaciaX
Rot.X += (ActRotX-Rot.X) * Power(Volker_FactorX);
//RotaciaZ
Rot.Z += (ActRotZ-Rot.Z) * Power(Volker_FactorZ);
//RotaciaY
Rot.Y -= Power(sinf(Rot.Z)*Volker_FactorY);
}
//kolizia lietadla zo zemov a objektami
//--------------------------------------------------------
bool VOLKER::GetGroundCollision()
{
//Zem
//-------------
/* if (Level.Krajina.Collise(PR,PL) == true)
{
return true;
}
if (Level.Krajina.Collise(PD,PU) == true)
{
return true;
}
*/
if (Level.Krajina.Collise(PB,PF) == true)
{
return true;
}
return false;
}
//kolizia
//-------------------------------------------------------------
bool VOLKER::CollisionDetail(VECTOR3D P1, VECTOR3D P2)
{
//ak nieje aktivny tak vrat false
if (Active == false)
return false;
//ak je zostreleny vrat false
if (DestroyedMode == true)
return false;
return ModelLib.Volker_ModelNormal.CollisionDetail(P1,P2,Matrix);
}
//kolizia
//-------------------------------------------------------------
bool VOLKER::CollisionBox(VECTOR3D P1, VECTOR3D P2)
{
//ak nieje aktivny tak vrat false
if (Active == false)
return false;
//ak je zostreleny vrat false
if (DestroyedMode == true)
return false;
return ModelLib.Volker_ModelNormal.CollisionBox(P1,P2,Matrix);
}