Here is the AI code for the monster that moves left and right in a game.
Note: movementRightFlag and movementLeftFlag variable gets turned on and off at different circumstances.
I am trying to get into better design habits mainly because program design was not taught in college.
I need criticisms on the code. I welcome all feedback.
Code is in Java.
public BatSprite(double x, double y) {
runOnce = true;
}
public void update(long milliseconds)
{
if(movementLeftFlag)
{
if(position.getY() > leastXPositionThreshold)
{
position.setX(position.getX() - 1);
if(position.getX() == leastXPositionThreshold)
{
runOnce = false;
movementRightFlag = true;
}
}
}
if(movementRightFlag)
{
movementLeftFlag = false;
position.setX(position.getX() + 1);
if(position.getX() > mostXPositionThreshold)
{
runOnce = true;
movementRightFlag = false;
}
}
// extra logic that changes the state of the monster direction
if(position.getY() == 50)
{
direction = "down";
if(runOnce)
{
movementLeftFlag = true;
}
}
}