Class Boat

  • Direct Known Subclasses:
    Opponent, Player

    public class Boat
    extends java.lang.Object
    Represents a Boat, controlled by either a Player or Opponent.
    See Also:
    Player, Opponent
    • Constructor Summary

      Constructors 
      Constructor Description
      Boat​(float yPosition, int width, int height, Lane lane, java.lang.String name)
      Creates a Boat instance in a specified Lane.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void AdvanceTextureFrame()
      Keeps track of which frame of the animation the boat's texture is on, and sets the texture accordingly.
      boolean ApplyDamage​(int obstacleDamage)
      Decreases the durability of the boat by the obstacle damage divided by the boat's robustness.
      void applyPenalty​(float penalty)  
      boolean CheckCollisions​(int backgroundOffset)
      Checks each obstacle in the Lane for a collision.
      boolean CheckIfInLane()
      Checks if the boat is between the left boundary and the right boundary of the Lane.
      void DecreaseSpeed()
      Decreases the speed of the boat by 0.015 if the resulting speed is greater than 0.
      void DecreaseTiredness()
      Decreases the tiredness of the boat by 1 if the tiredness is greater than 0.
      boolean finished()  
      void GenerateTextureFrames​(char boatName)
      Generates all frames for animating the boat.
      float getAcceleration()  
      float getCurrentSpeed()  
      int getDurability()  
      float getFastestTime()  
      int getHeight()  
      float getManeuverability()  
      int getMaxSpeed()  
      java.lang.String getName()  
      float getPenalty()  
      float getProgress​(int finishY)  
      int getRobustness()  
      float getTiredness()  
      int getX()  
      int getY()  
      void IncreaseSpeed()
      If the boat has enough stamina, increase the speed of the boat by the boat's acceleration, if not, do nothing.
      void IncreaseTiredness()
      Increases the tiredness of the boat by 0.75 if the tiredness is less than 100.
      void MoveForward()
      Increases the y-position of the boat respective to the boat's speed, and decreases the speed by 0.08%.
      void Reset()
      Resets necessary stats for the next race.
      void ResetFastestLegTime()
      Resets the boat's fastest leg time.
      void setFinished​(boolean f)  
      void setLane​(Lane lane)  
      void setStats​(char boatLabel)
      Interpolates predetermined stats from a boat label, and sets the stats based on those.
      void setStats​(int maxspeed, int robustness, float acceleration, float maneuverability)
      Implicitly sets the stats of the boat, given each attribute.
      void setTexture​(com.badlogic.gdx.graphics.Texture t)  
      void setTextureFrames​(com.badlogic.gdx.graphics.Texture[] frames)  
      void SteerLeft()
      Decreases the x-position of the boat respective to the boat's maneuverability and speed, and decreases the speed by 3%.
      void SteerRight()
      Increases the x-position of the boat respective to the boat's maneuverability and speed, and decreases the speed by 3%.
      void UpdateFastestTime​(float elapsedTime)
      Updates the boat's fastest time.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • yPosition

        protected float yPosition
      • xPosition

        protected float xPosition
      • penalties

        protected float penalties
      • width

        protected int width
      • height

        protected int height
      • lane

        protected Lane lane
      • texture

        public com.badlogic.gdx.graphics.Texture texture
    • Constructor Detail

      • Boat

        public Boat​(float yPosition,
                    int width,
                    int height,
                    Lane lane,
                    java.lang.String name)
        Creates a Boat instance in a specified Lane.
        Parameters:
        yPosition - Y-position of the boat.
        width - Width of the boat.
        height - Height of the boat.
        lane - Lane object.
        name - String identifier.
    • Method Detail

      • SteerLeft

        public void SteerLeft()
        Decreases the x-position of the boat respective to the boat's maneuverability and speed, and decreases the speed by 3%.
      • SteerRight

        public void SteerRight()
        Increases the x-position of the boat respective to the boat's maneuverability and speed, and decreases the speed by 3%.
      • MoveForward

        public void MoveForward()
        Increases the y-position of the boat respective to the boat's speed, and decreases the speed by 0.08%.
      • IncreaseSpeed

        public void IncreaseSpeed()
        If the boat has enough stamina, increase the speed of the boat by the boat's acceleration, if not, do nothing.
      • DecreaseSpeed

        public void DecreaseSpeed()
        Decreases the speed of the boat by 0.015 if the resulting speed is greater than 0.
      • CheckCollisions

        public boolean CheckCollisions​(int backgroundOffset)
        Checks each obstacle in the Lane for a collision.
        Parameters:
        backgroundOffset - How far up the course the player is.
        Returns:
        Boolean representing if a collision occurs.
      • ApplyDamage

        public boolean ApplyDamage​(int obstacleDamage)
        Decreases the durability of the boat by the obstacle damage divided by the boat's robustness.
        Parameters:
        obstacleDamage - Amount of damage an Obstacle inflicts on the boat.
        Returns:
        Boolean representing whether the durability of the boat is below 0.
      • CheckIfInLane

        public boolean CheckIfInLane()
        Checks if the boat is between the left boundary and the right boundary of the Lane.
        Returns:
        Boolean representing whether the Boat is in the Lane.
      • UpdateFastestTime

        public void UpdateFastestTime​(float elapsedTime)
        Updates the boat's fastest time.
        Parameters:
        elapsedTime - Time it took the boat to finish the current race.
      • IncreaseTiredness

        public void IncreaseTiredness()
        Increases the tiredness of the boat by 0.75 if the tiredness is less than 100.
      • DecreaseTiredness

        public void DecreaseTiredness()
        Decreases the tiredness of the boat by 1 if the tiredness is greater than 0.
      • AdvanceTextureFrame

        public void AdvanceTextureFrame()
        Keeps track of which frame of the animation the boat's texture is on, and sets the texture accordingly.
      • GenerateTextureFrames

        public void GenerateTextureFrames​(char boatName)
        Generates all frames for animating the boat.
        Parameters:
        boatName - Boat name, used to get correct asset.
      • Reset

        public void Reset()
        Resets necessary stats for the next race.
      • ResetFastestLegTime

        public void ResetFastestLegTime()
        Resets the boat's fastest leg time.
      • setTexture

        public void setTexture​(com.badlogic.gdx.graphics.Texture t)
        Parameters:
        t - Texture to use.
      • setTextureFrames

        public void setTextureFrames​(com.badlogic.gdx.graphics.Texture[] frames)
        Parameters:
        frames - Texture frames for animation.
      • getFastestTime

        public float getFastestTime()
        Returns:
        Float representing fastest race/leg time.
      • getX

        public int getX()
        Returns:
        Int representing x-position of boat.
      • getY

        public int getY()
        Returns:
        Int representing y-position of boat.
      • getHeight

        public int getHeight()
        Returns:
        Int representing the y coordinate range of the boat (length).
      • getName

        public java.lang.String getName()
        Returns:
        String representing name of the boat.
      • finished

        public boolean finished()
        Returns:
        Boolean representing if the boat has finished the current race.
      • setFinished

        public void setFinished​(boolean f)
        Parameters:
        f - Boolean representing if the boat has finished the race.
      • getCurrentSpeed

        public float getCurrentSpeed()
        Returns:
        Float representing the current speed of the boat.
      • getProgress

        public float getProgress​(int finishY)
        Parameters:
        finishY - Y-position of the finish line.
        Returns:
        Float representing the progress of the boat from 0 to 1.
      • setStats

        public void setStats​(int maxspeed,
                             int robustness,
                             float acceleration,
                             float maneuverability)
        Implicitly sets the stats of the boat, given each attribute.
        Parameters:
        maxspeed - Top speed the boat can reach.
        robustness - How resilient to obstacle damage the boat is.
        acceleration - How much the speed increases each frame.
        maneuverability - How easily the boat can move left or right.
      • setStats

        public void setStats​(char boatLabel)
        Interpolates predetermined stats from a boat label, and sets the stats based on those.
        Parameters:
        boatLabel - A character between A-G representing a specific boat.
      • getManeuverability

        public float getManeuverability()
        Returns:
        Float representing the manouverability of the boat.
      • getAcceleration

        public float getAcceleration()
        Returns:
        Float representing the acceleration of the boat.
      • getRobustness

        public int getRobustness()
        Returns:
        Int representing the robustness of the boat.
      • getDurability

        public int getDurability()
        Returns:
        Int representing the durability of the boat.
      • getMaxSpeed

        public int getMaxSpeed()
        Returns:
        Int representing the maximum speed of the boat.
      • getTiredness

        public float getTiredness()
        Returns:
        Float representing the tiredness of the boat crew.
      • getPenalty

        public float getPenalty()
        Returns:
        Float representing the time penalty incurred for the current race.
      • applyPenalty

        public void applyPenalty​(float penalty)
        Parameters:
        penalty - Float to add to the boat's penalty total for the current race.
      • setLane

        public void setLane​(Lane lane)
        Parameters:
        lane - Lane object for the boat.