Hi guys,
Am working on some extremely basic enemy movement patterns and just can't get it to work. Can anyone see any problems with this please?
First the pattern is loaded:
enemy.cpp
void Enemy::setPattern(int directions, ...)
{
va_list arguments;
va_start(arguments, directions);
for(int x = 0; x < directions; x++)
{
m_Movement.push_back(va_arg(arguments, int))
};
m_Patterns = directions;
va_end(arguments);
}
main.cpp
Enemy enemy;
enemy.setPattern(LEFT, LEFT, STOPPED, RIGHT, RIGHT, STOPPED);
Then in each frame the enemy should be moved:
enemy.cpp
void Enemy::move()
{
switch (m_Movement.at(m_PatternPlace))
{
case STOPPED:
break;
case LEFT:
addX(-ENEMYMOVE);
break;
case RIGHT:
addX(ENEMYMOVE);
break;
case UP:
addY(-ENEMYMOVE);
break;
case DOWN:
addY(ENEMYMOVE);
break;
}
m_PatternPlace++;
if(m_PatternPlace == m_Patterns)
{
m_PatternPlace = 0;
}
}
main.cpp
enemy.move();
enemy.draw();
The directions are an enumeration (STOPPED, LEFT, RIGHT, UP, DOWN).
I know the movement will be extremely fast for now, but will slow it down once I get it moving properly.
Thanks.