Package com.dragonboat.game
Class Boat
- java.lang.Object
-
- com.dragonboat.game.Boat
-
-
Field Summary
Fields Modifier and Type Field Description protected float
ACCELERATION
static int
bankWidth
protected float
currentSpeed
protected int
durability
protected float
fastestLegTime
protected boolean
finished
protected int
frameCounter
protected int
height
protected char
label
protected int
laneNo
protected Lane[]
lanes
protected float
lastFrameY
protected float
MANEUVERABILITY
static int
MAX_DURABILITY
static float
MAX_TIREDNESS
protected float
MAXSPEED
protected java.lang.String
name
protected float
penalties
protected int
ROBUSTNESS
com.badlogic.gdx.graphics.Texture
texture
protected com.badlogic.gdx.graphics.Texture[]
textureFrames
protected int
threshold
protected float
tiredness
protected int
width
protected float
xPosition
protected float
yPosition
-
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
ChooseBoat(char boatChar)
Assigns the selected boat template to the boat.void
ChooseBoat(int boatNo)
Assigns the selected boat template to the boat.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()
float
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[] lanes, int laneNo)
void
setStats(char boatLabel)
Interpolates predetermined stats from a boat label, and sets the stats based on those.void
setStats(float 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.
-
-
-
Field Detail
-
ROBUSTNESS
protected int ROBUSTNESS
-
ACCELERATION
protected float ACCELERATION
-
MANEUVERABILITY
protected float MANEUVERABILITY
-
MAXSPEED
protected float MAXSPEED
-
durability
protected int durability
-
yPosition
protected float yPosition
-
xPosition
protected float xPosition
-
penalties
protected float penalties
-
width
protected int width
-
height
protected int height
-
currentSpeed
protected float currentSpeed
-
fastestLegTime
protected float fastestLegTime
-
tiredness
protected float tiredness
-
lanes
protected Lane[] lanes
-
laneNo
protected int laneNo
-
textureFrames
protected com.badlogic.gdx.graphics.Texture[] textureFrames
-
frameCounter
protected int frameCounter
-
lastFrameY
protected float lastFrameY
-
texture
public com.badlogic.gdx.graphics.Texture texture
-
name
protected java.lang.String name
-
label
protected char label
-
finished
protected boolean finished
-
threshold
protected int threshold
-
bankWidth
public static int bankWidth
-
MAX_DURABILITY
public static int MAX_DURABILITY
-
MAX_TIREDNESS
public static float MAX_TIREDNESS
-
-
Constructor Detail
-
Boat
public Boat(float yPosition, int width, int height, Lane[] lanes, int laneNo, java.lang.String name)
Creates an instance of the player boat.- Parameters:
yPosition
- Y-position of the boat.width
- Width of the boat.height
- Height of the boat.lanes
- Lanes for the boat.laneNo
- Lane number for the boat.name
- Name of the boat.
-
-
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.
-
ChooseBoat
public void ChooseBoat(int boatNo)
Assigns the selected boat template to the boat.
This includes stats and texture.
- Parameters:
boatNo
- Number of the boat template selected.
-
ChooseBoat
public void ChooseBoat(char boatChar)
Assigns the selected boat template to the boat.
This includes stats and texture.
- Parameters:
boatChar
- Character of the boat template selected.
-
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(float 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 maneuverability 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 float 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[] lanes, int laneNo)
- Parameters:
lanes
- Lanes object for the boat.laneNo
- This boat's lane number.
-
-