For "fire:" this is supposed to represent the enemy firing a stream of force in the direction of the player, not killing them but knocking them back. Mechanically speaking, it is drawing a straight line and altering the speed of whatever the line collides with, and the line remains active for five seconds (this is an example time; we may alter the amount of time firing or the pause time in the final implementation).
The enemy does not move from its position, but it quickly aims at and locks onto the player by rotating in the appropriate direction. The rotation speed will likely be high and its aim precise. The enemy's only real weakness is that once it starts firing, it is immobile for the duration, so this is what the player will need to learn to take advantage of. It is worth noting that if the player is clever with their timing, they can actually use this enemy's blast to their advantage, launching them past obstacles and toward their goal.
To function, the class controlling the enemy needs the following data as input at least:
- the player's current position (which can be used to calculate the desired angle of rotation)
- elapsed time
- desired angle (see above)
- current angle
- rotation speed
- range
- force (how much the player's speed is affected if hit by the enemy's blast)
- a boolean value to indicate which of its two states the AI is currently in
If (!firing) // firing is the boolean value mentioned above
Aim();
else
Fire();
function Aim()
{
if (player is visible, not behind a wall)
{
desired angle = new angle calculated from player's current X/Y position;
if (desired angle > current angle)
current angle += rotation speed;
else if (desired angle < current angle)
current angle -= rotation speed;
else if (desired angle == current angle AND calculated distance to player < range)
firing = true;
}
}
function Fire()
{
animate sprite charging graphic (if applicable);
if (pause time has elapsed)
{
animate firing effect at current angle;
if (player collides with line at current angle)
player speed -= force; //we may make this affect other objects as well, but likely will not
}
if (total firing time has elapsed)
firing = false;
}
No comments:
Post a Comment