Class ComputerBoat
- java.lang.Object
-
- com.dragonboatrace.entities.Entity
-
- com.dragonboatrace.entities.boats.Boat
-
- com.dragonboatrace.entities.boats.ComputerBoat
-
public class ComputerBoat extends Boat
Represents a specific Computer controlled Boat.
-
-
Field Summary
Fields Modifier and Type Field Description private com.badlogic.gdx.graphics.Texture
down
The texture for the indicator when the Computer is off the screen but below.private Hitbox
moveArea
The area in which the computer boat will look for obstacles to avoid.private float
randomWait
The random amount of stamina to have before using stamina again.private com.badlogic.gdx.graphics.Texture
up
The texture for the up indicator when the Computer is off the screen but above.private boolean
waiting
If the ComputerBoat is currently regenerating stamina.private int
xOffset
The x-offset of the moveArea as the area is equal on both sides of the boat.-
Fields inherited from class com.dragonboatrace.entities.boats.Boat
agility, boatType, buff, collisionTime, distanceTravelled, generator, health, healthFont, lane, laneBox, layout, maxStamina, name, nameFont, parameter, penaltyTime, recentCollision, speed, stamina, staminaFont, time, totalTime
-
-
Constructor Summary
Constructors Constructor Description 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private Collidable
checkCollidables()
Check for obstacles in the area, specified by moveArea, to move away from.private int
moveFromObject(Collidable closest)
Move in the direction away from an object.private float
pickSpeed(int pos)
Pick a random speed so that the computer boat is likely to finish in the position specified.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.void
update(float deltaTime)
Update the position of the boat in respect to the time passed since the last frame.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.private float
waitForRandomStamina()
Wait for a random stamina value before using stamina again.-
Methods inherited from class com.dragonboatrace.entities.boats.Boat
addHealth, addSpeed, addStamina, checkCollisions, dispose, equals, getAgility, getBoatType, getBuff, getDistanceTravelled, getHealth, getLane, getName, getPenaltyTime, getSpeed, getStamina, getTime, getTotalTime, getVelocity, regenerateStamina, restore, save, setBuff, setTestTime, setTime, setTotalTime, updateYPosition, useStamina, velocityPercentage
-
Methods inherited from class com.dragonboatrace.entities.Entity
getHitBox, getTexture, restore, save
-
-
-
-
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.
-
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.
-
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.
-
-