Original Post
🔒 Locked
Alien wave pattern - how to?
Advertisement
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:
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:
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]
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::vectortMovementPath;
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]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement