Skip to main content
gamedev.net
🔒 Locked

Alien wave pattern - how to?

Started by Specchum Apr 15, 2004 at 2:10 AM 2 replies 600+ views
Original Post
Specchum
Specchum
How do I create alien wave attack patterns for a vertical scrolling shoot ''em up? How does one go about creating structures for such patterns and associate them with different sprites? "There is no dark side of the moon." - Pink Floyd
"There is no dark side of the moon." - Pink Floyd
Endurion
Endurion
That's not too difficult, you just have to make all the little steps.

For the wave pattern concentrate on one alien for now, having a movement path. Let the path be several frames, with each frame being a relative movement in a specific direction.

For example:


struct tPathFrame
{
vector2 m_vDistance;
float m_fFrameLength;
};

typedef std::vector tMovementPath;


Now you can store any predefined paths in an array or vector or a list. Give every alien an ID to the path entry. Every alien also needs an Update with the elapes time.

For example:


class CAlien
{
public:

vector2 m_vecPos;

int m_iPathID;
int m_iCurrentPathFrame;
float m_fCurrentFramePos;

CAlien() :
m_iPathID( 0 ),
m_iCurrentPathFrame( 0 ),
m_fCurrentFramePos( 0.0f )
{
}

void Update( float fElapsedTime )
{
tMovementPath& MyPath = .....

while ( fElapsedTime > 0.0f )
{
// retrieve current Path Frame

tPathFrame& Frame = MyPath[m_iCurrentPathFrame];

if ( fElapsedTime >= Frame.m_fFrameLength - fCurrentFramePos )
{
// move to Frame end position

m_vecPos += ( Frame.m_fFrameLength - fCurrentFramePos ) / Frame.m_fFrameLength * Frame.m_vDistance;

// this Frame is done

fCurrentFramePos = 0.0f;
m_iCurrentPathFrame++;
if ( m_iCurrentPathFrame >= MyPath.size() )
{
// reached the end, loop

m_iCurrentPathFrame = 0;
}

// adjust remaining time

fElapsedTime -= Frame.m_fFrameLength - fCurrentFramePos;
}
else
{
// move

m_vecPos += fElapsedTime / Frame.m_fFrameLength * Frame.m_vDistance;

fCurrentFramePos += fElapsedTime;
fElapsedTime = 0.0f;
}
}

}
};



This is pseudo code out of my head, it misses safety checks and maybe got an error or two, but should show the general direction.

[edited by - Endurion on April 15, 2004 3:33:44 AM]

[edited by - Endurion on April 15, 2004 3:34:30 AM]
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
Peon
Peon
Yep, that''s how I''d do it. I''d also use bool arrays to define the initial formations of the alien ships, and then just assign them paths, as Endurion said.
Peon
Specchum
Specchum
Cool. That''s pretty much what I had figured. Thanks for the help!

"There is no dark side of the moon." - Pink Floyd
"There is no dark side of the moon." - Pink Floyd

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.