hi its in 2d..
this is what i have at the moment and it will do the job i suppose.
Basically when a collsion occurs startexplosion is called to initialize the
values needed, such as the position of the ship and random directions to
move in, live span of each particle. each time updateexplosion is called
from a timer it moves each bit in the velocity it has and decrements the
live of the particle.
any ideas of how to improve it? or a better way to tackle it even?
oh and any idea how to stretch an image to set as background of the form?
thanks
gav
struct vector{
float x;
float y;
};
struct Bullet{
vector position;
vector newpos;
vector velocity;
int timetoLive;
bool alive;
};
Bullet explode[MAX_EXPLOSION_BITS];
void InitExplosion(){
// at start of program explosion bits are not visible
for(int i=0;i<MAX_EXPLOSION_BITS;i++){
explode[i].alive=false;
}
}
void StartExplosion(Ship* ship){
// this sould be called when the ship hits a rock
int iVelTest = 0;
// give the explosion bits initial values for position, speed,
velocity etc
for (int i = 0;i<MAX_EXPLOSION_BITS;i++)
{
explode[i].position = ship->position ;
iVelTest = rand()%2;
if (iVelTest == 0)
{
explode[i].velocity.x = (rand()%10);
}
else
{
explode[i].velocity.x = -(rand()%10);
}
iVelTest = rand()%2;
if (iVelTest == 0)
{
explode[i].velocity.y = (rand()%10);
}
else
{
explode[i].velocity.y = -(rand()%10);
}
explode[i].alive = true;
explode[i].timetoLive = (rand()%25)+1;
}
ship->lives--;
}
void UpdateExplosion(){
//move the explosion pieces for the next frame
for (int i = 0;i<MAX_EXPLOSION_BITS;i++)
{
explode[i].position = Add(explode[i].position ,
explode[i].velocity );
explode[i].timetoLive--;
if (explode[i].timetoLive == 0)
{
explode[i].alive = false;
}
}
}
void DrawExplosion(){
// draw each of the explosion bits
vector pos;
Form1->Canvas->Pen->Color = clGreen;
for (int i = 0;i<MAX_EXPLOSION_BITS;i++)
{
if (explode[i].alive == true)
{
Form1->Canvas->MoveTo(explode[i].position.x,
explode[i].position.y);
pos = Add(explode[i].position ,
explode[i].velocity );
Form1->Canvas->LineTo(pos.x, pos.y);
}
}
}
>From: Thomas Hruska <[EMAIL PROTECTED]>
>Reply-To: [email protected]
>To: [email protected]
>Subject: Re: [c-prog] asteroids explosion vector graphics
>Date: Mon, 02 Apr 2007 11:16:46 -0400
>
>glogic_1 wrote:
> > hey all
> > anyone any good at programming with vector graphics? im trying to
> > create an explosion with particles from a given position that fade out
> > the further they move away from the position but im having no luck at
> > the moment. the idea im working with is to create an array of
> > particles and loop through them giving each a vector that it should
> > travel in. also give each a life time with counts down each time they
> > move. that even sound as if im going in the right direction?
> > coz at the moment im lost with it
> > thanks
> > g
>
>Are we talking 2D or 3D?
>
>--
>Thomas Hruska
>CubicleSoft President
>Ph: 517-803-4197
>
>*NEW* VerifyMyPC 2.4
>Change tracking and management tool.
>Reduce tech. support times from 2 hours to 5 minutes.
>
>http://www.CubicleSoft.com/VerifyMyPC/
>
_________________________________________________________________
Live Search Maps find all the local information you need, right when you
need it. http://maps.live.com/?icid=hmtag2&FORM=MGAC01
To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/c-prog/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/c-prog/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/