home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2006 July & August
/
PCWorld_2006-07-08_cd.bin
/
temacd
/
planearcade
/
planearcade.exe
/
Tank3.bmp
/
bullets.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2004-10-08
|
8KB
|
327 lines
#include "main.h"
//Inicializacia zasobnika
//------------------------------------------------------------------
void BULLETSYSTEM::Initialize()
{
//log
LogPrint("Vytvaram zasobnik striel");
//vynulovanie
VertexBuffer = NULL;
ActBullet = 0;
Friendly = false;
UnFriendly = false;
//Vertex Buffer
if( FAILED( g_pd3dDevice->CreateVertexBuffer( Bullet_MaxBullets*3*sizeof(CUSTOMVERTEXBULLET),
D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,
D3DFVF_CUSTOMVERTEXBULLET,
D3DPOOL_DEFAULT, &VertexBuffer, NULL ) ) )
{
LogPrint(" chyba pri vytvarani Vertex Bufferu");
}
else
{
LogPrint(" Vertex Buffer vytvoreny");
}
}
//destruktor
//------------------------------------------------------------------
BULLETSYSTEM::~BULLETSYSTEM()
{
if (VertexBuffer)
VertexBuffer->Release();
VertexBuffer = NULL;
}
//resetuje hodnoty
//-----------------------------------------------------------------
void BULLETSYSTEM::Reset()
{
ActBullet = 0;
for (int i=0;i<Bullet_MaxBullets;i++)
{
Bullet[i].Active = false;
}
}
//refresh - vyrenderovanie a posunutie
//-----------------------------------------------------------------
void BULLETSYSTEM::Refresh()
{
int i;
///////////
//Process//
///////////
//posunie jednotlive gulky
VECTOR3D PomPos;
for (i = 0;i<Bullet_MaxBullets;i++)
{
if (Bullet[i].Active == false)
continue;
//ak je mimo hracej plochy tak deaktivuj
if ((Bullet[i].Pos.X > F_MapSize || Bullet[i].Pos.X < -F_MapSize) ||
(Bullet[i].Pos.Z > F_MapSize || Bullet[i].Pos.Z < -F_MapSize) ||
(Bullet[i].Pos.Y > F_MapSize || Bullet[i].Pos.Y < -F_MapSize))
Bullet[i].Active = false;
PomPos.X = Bullet[i].Pos.X + Power(Bullet_Speed)*(Bullet[i].Sme.X);
PomPos.Y = Bullet[i].Pos.Y + Power(Bullet_Speed)*(Bullet[i].Sme.Y);
PomPos.Z = Bullet[i].Pos.Z + Power(Bullet_Speed)*(Bullet[i].Sme.Z);
//kolizia
if (Collision(Bullet[i].Pos, PomPos) == true)
{
Bullet[i].Active = false;
}
//inak posun
Bullet[i].Pos = PomPos;
}
//////////
//Render//
//////////
int NumVertices = 0;
CUSTOMVERTEXBULLET *Vertices;
//zisti kolko bulletov
for (i = 0;i<Bullet_MaxBullets;i++)
{
if (Bullet[i].Active == false)
continue;
NumVertices++;
}
//ak ani jeden nerenderuj ak ano zresetuj pocitadlo chod dalej
if (NumVertices == 0)
return;
else
NumVertices = 0;
//Otvor VB
VertexBuffer->Lock(0, 0, (void**)&Vertices, D3DLOCK_DISCARD |
D3DLOCK_NOOVERWRITE ) ;
//zobrazi model do pola vertexov
for (i = 0;i<Bullet_MaxBullets;i++)
{
//ak nieje aktivovany preskoc
if (Bullet[i].Active == false)
continue;
//pridaj vertex
Vertices[NumVertices].pos.x = Bullet[i].Pos.X;
Vertices[NumVertices].pos.y = Bullet[i].Pos.Y;
Vertices[NumVertices].pos.z = Bullet[i].Pos.Z;
Vertices[NumVertices].color = 0xffff0000;
NumVertices++;
//pridaj vertex
Vertices[NumVertices].pos.x = (Bullet[i].Pos.X + Bullet_Size*Bullet[i].Sme.X) + (1.0f*(-Bullet[i].Sme.Z));
Vertices[NumVertices].pos.y = (Bullet[i].Pos.Y + Bullet_Size*Bullet[i].Sme.Y) + 1.0f ;
Vertices[NumVertices].pos.z = (Bullet[i].Pos.Z + Bullet_Size*Bullet[i].Sme.Z) + (1.0f*(Bullet[i].Sme.X)) ;
Vertices[NumVertices].color = 0xffffff00;
NumVertices++;
//pridaj vertex
Vertices[NumVertices].pos.x = (Bullet[i].Pos.X + Bullet_Size*Bullet[i].Sme.X) + (1.0f*(Bullet[i].Sme.Z));
Vertices[NumVertices].pos.y = (Bullet[i].Pos.Y + Bullet_Size*Bullet[i].Sme.Y) - 1.0f;
Vertices[NumVertices].pos.z = (Bullet[i].Pos.Z + Bullet_Size*Bullet[i].Sme.Z) + (1.0f*(-Bullet[i].Sme.X));
Vertices[NumVertices].color = 0xffffff00;
NumVertices++;
}
//uzavri VB
VertexBuffer->Unlock() ;
//vynuluj maticu
D3DXMATRIXA16 NullMatrix;
D3DXMatrixIdentity(&NullMatrix);
g_pd3dDevice->SetTransform( D3DTS_WORLD, &NullMatrix);
//vypni texturu
g_pd3dDevice->SetTexture(0,NULL);
//vyrenderuj
g_pd3dDevice->SetStreamSource( 0, VertexBuffer, 0, sizeof(CUSTOMVERTEXBULLET));
g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEXBULLET);
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0 , NumVertices/3 );
//reset
Engine.ResetToDefault();
}
//Vypusti bullet
//--------------------------------------------------------------
void BULLETSYSTEM::SpawnBullet(VECTOR3D Pos,VECTOR3D Rot)
{
Bullet[ActBullet].Pos = Pos;
//vypocita smerovy vektor
Bullet[ActBullet].Sme.X = cosf(Rot.X) * sinf(Rot.Y);
Bullet[ActBullet].Sme.Z = cosf(Rot.X) * cosf(Rot.Y);
Bullet[ActBullet].Sme.Y = -sinf(Rot.X);
//nepresnost
Bullet[ActBullet].Sme.X += RandomMinMax(-0.01f,0.01f);
Bullet[ActBullet].Sme.Y += RandomMinMax(-0.01f,0.01f);
Bullet[ActBullet].Sme.Z += RandomMinMax(-0.01f,0.01f);
Bullet[ActBullet].Active = true;
ActBullet++;
if (ActBullet == Bullet_MaxBullets)
ActBullet = 0;
}
//kolizia zo vsetkymi objektami
//----------------------------------------------------------------
bool BULLETSYSTEM::Collision(VECTOR3D P1, VECTOR3D P2)
{
int i;
//ZEM
//--------------
if (Level.Krajina.Collise(P1,P2) == true)
{
Explo.SpawnHit(Level.Krajina.IntPos);
return true;
}
///////////////////////
//NEPRIATELSKE STRELY//
///////////////////////
if (UnFriendly == true)
{
//kolizia so spitfirom
if (SpitFire.CollisionDetail(P1,P2) == true)
{
SpitFire.Life -= Bullet_Power;
Explo.SpawnHit(SpitFire.Pos);
return true;
}
}
//////////////////
//PLAYERS STRELY//
//////////////////
if (Friendly == true)
{
//
//MesserSchmitt
for (i=0;i<Max_MesserSchmitt;i++)
{
if (Level.MesserSchmitt[i].Active == false)
continue;
if (Level.MesserSchmitt[i].CollisionBox(P1,P2) == true)
{
Level.MesserSchmitt[i].Life -= Bullet_Power;
Explo.SpawnHit(Level.MesserSchmitt[i].Pos);
//prepni do uhybacieho modu
Level.MesserSchmitt[i].Uhybanie = true;
Level.MesserSchmitt[i].Sledovanie = false;
Level.MesserSchmitt[i].Vyhybanie = false;
return true;
}
}
//
//Volker
for (i=0;i<Max_Volkers;i++)
{
if (Level.Volker[i].Active == false)
continue;
if (Level.Volker[i].CollisionBox(P1,P2) == true)
{
Level.Volker[i].Life -= Bullet_Power;
Explo.SpawnHit(Level.Volker[i].Pos);
//prepni do uhybacieho modu
Level.Volker[i].Uhybanie = true;
Level.Volker[i].Sledovanie = false;
Level.Volker[i].Vyhybanie = false;
return true;
}
}
//
//Bombarder
for (i=0;i<Max_Bombarders;i++)
{
if (Level.Bombarder[i].Active == false)
continue;
if (Level.Bombarder[i].CollisionDetail(P1,P2) == true)
{
Level.Bombarder[i].Life -= Bullet_Power;
Explo.SpawnHit(ModelLib.Bombarder_ModelNormal.ColPosition);
return true;
}
}
//
//Strucure
for (i=0;i<Max_Structures;i++)
{
if (Level.Structure[i].CollisionDetail(P1,P2) == true)
{
Level.Structure[i].Life -= Bullet_Power;
Explo.SpawnHit(ModelLib.GetStructure(Level.Structure[i].ModelIndex)->ColPosition);
return true;
}
}
//
//Truck
for (i=0;i<Max_Trucks;i++)
{
if (Level.Truck[i].CollisionDetail(P1,P2) == true)
{
Level.Truck[i].Life -= Bullet_Power;
Explo.SpawnHit(ModelLib.Truck_ModelDestroyed.ColPosition);
return true;
}
}
}
return false;
}