2 mins
As explained in a previous dev diary, the code for the dash enemy was a temporary fix to test it out for the game. It didn’t really work well and I discuessed with the team and we decided to change how the level would work. We changed to so the layput of the level would remain the same but the way the boss worked would change.
Instead of dashing in random directions, it would target the player and then after a few seconds it would dash towards the player and if it collided with the player then they would be reset to the start of the level. They will dash for a few seconds and then it will restart at a random point and start targeting the player again. This is inspired by the Revek enemy from Hollow Knight.
To see an example of the Revek follow the link below.
The code below shows a part of how the dash works. Whist the count is less then the timeout, it gets the difference between the player position and its position and works out the directional vector using the normalise function. It then multiplies that vector by 4000, this is the magitude of the vector. Once the count reaches the timeout, it resets the count, switches the state to DASH, using an else if statement, and then it updates the x and y position using the vector.
if (timer->count < timer->timeout)
{
direction.setX(player_pos.x - (sprite.xPos()));
direction.setY(player_pos.y - (sprite.yPos()));
direction.normalise();
direction = direction * 4000;
}
else
{
timer->count = 0;
state = DASH;
}
The gif below shows the dash boss in action.
The issue with the randomiser in a previous dev diary was fixed this time around. I was using random_device instead of using a seed generator. The new code is shown below, so it generates a seed using a value and then it generates a number between the max and min, which are passed in.
std::mt19937 generator(seed);
std::uniform_int_distribution<int> distr{ min, max };
distr(generator);
Subscribe to this blog via RSS.
Low level programming dev diary 28
Text based adventure dev diary 6
Level design developer diary 3
Game engine programming dev diary 14
Audio-visual production dev diary 7
Audio-Visual Production: Particle System Mesh Spawning Issues
Posted on 20 Feb 2020Low level programming dev diary (28) Text based adventure dev diary (6) Level design developer diary (3) Post mortem (4) Ex-machina dev diary (11) Game engine programming dev diary (14) Network game dev diary (11) Audio-visual production dev diary (7)