Class ComputerBoat


  • public class ComputerBoat
    extends Boat
    Represents a specific Computer controlled Boat.
    • Field Detail

      • moveArea

        private final Hitbox moveArea
        The area in which the computer boat will look for obstacles to avoid.
      • xOffset

        private final int xOffset
        The x-offset of the moveArea as the area is equal on both sides of the boat.
      • up

        private final com.badlogic.gdx.graphics.Texture up
        The texture for the up indicator when the Computer is off the screen but above.
      • down

        private final com.badlogic.gdx.graphics.Texture down
        The texture for the indicator when the Computer is off the screen but below.
      • randomWait

        private float randomWait
        The random amount of stamina to have before using stamina again.
      • waiting

        private boolean waiting
        If the ComputerBoat is currently regenerating stamina.
    • Constructor Detail

      • ComputerBoat

        public ComputerBoat​(BoatType boat,
                            Lane lane,
                            java.lang.String name,
                            int pickSpeedValue)
        Creates a computer boat with values from boat, in Lane lane, an identifying name and with a random speed.
        Parameters:
        boat - The BoatType to get values from.
        lane - The lane the boat is racing in.
        name - The name of the boat.
        pickSpeedValue - The speed of the boat is chosen based on this value.
    • Method Detail

      • update

        public void update​(float deltaTime)
        Update the position of the boat in respect to the time passed since the last frame.
        Overrides:
        update in class Boat
        Parameters:
        deltaTime - The time passed since the last frame.
      • render

        public void render​(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
        Renders the boat if it is onscreen, else will render the off-screen markers at their current x value.

        Also performs Boat's render after rendering the markers.

        Overrides:
        render in class Boat
        Parameters:
        batch - The SpriteBatch that the renders will be added to.
      • updateYPosition

        public void updateYPosition​(float playerY,
                                    float playerDistance)
        Update the vertical position of the boat according to its distance travelled versus the distance travelled by the player.
        Parameters:
        playerY - The y position of the player on the screen.
        playerDistance - The distance travelled by the player.
      • waitForRandomStamina

        private float waitForRandomStamina()
        Wait for a random stamina value before using stamina again.
        Returns:
        A float of the value to wait for before using stamina.
      • checkCollidables

        private Collidable checkCollidables()
        Check for obstacles in the area, specified by moveArea, to move away from.
        Returns:
        The closest Obstacle in the area or null if no obstacles are in the area.
      • moveFromObject

        private int moveFromObject​(Collidable closest)
        Move in the direction away from an object.
        Parameters:
        closest - The Obstacle to move away from.
        Returns:
        The direction to move in:
        • -1 if the boat should move to the left.
        • 1 if the boat should move to the right.
        • 0 if the boat should move neither way.
      • pickSpeed

        private float pickSpeed​(int pos)
        Pick a random speed so that the computer boat is likely to finish in the position specified.
        Parameters:
        pos - The position the boat should finish in.
        Returns:
        A float of the boats speed that it will travel at.