Class: Tank

TankGame.Tank(width, pos, colorVal)

Class Tank that represents the tank object

Constructor

new Tank(width, pos, colorVal)

Constructor for the tank object. The height is determined by the golden ratio with respect to the width.
Parameters:
Name Type Description
width number the width of the tank
pos p5.Vector the position of the tank
colorVal Array.<3, Number> the color of the tank
Source:

Methods

addDamage(damage)

Adds damage to the tank. Does not allow for damage outside of the range 0 to 100.
Parameters:
Name Type Description
damage number the damage to apply to the tank.
Source:

attachTo(gameEngine)

Attach the tank to the game engine and keep a handle for the game engine.
Parameters:
Name Type Description
gameEngine TankGame.GameEngine The game engine.
Source:
Throws:
param gameEngine should be instance of TankGame.GameEngine
Type
Error

checkOffScreen()

Check if the tank is off screen. Explodes the tank if it is below the bottom of the screen.
Source:

decreaseFiringSpeed()

Decrease the firing speed of the gun. Does not go below zero.
Source:

decreaseGunAngle()

Decrease the gun angle by 1 degree. Stops at 0.
Source:

draw()

Draw the entire tank calling the track, gun and body draw functions.
Source:

drawBody()

Draw the body of the tank in the color saved in this.color.
Source:

drawGun()

Draw the gun on the tank at the correct angle
Source:

drawHealthBar()

Draw the health bar above the tank
Source:

drawTracks()

Draw the tracks at the bottom of the tank
Source:

explode()

Explode the tank
Source:

getGunAngle() → {number}

Get the current angle
Source:
Returns:
- The current gun angle in degrees between 0 and 180
Type
number

increaseFiringSpeed()

Increase the firing speed of the gun. Only goes as high as the health of the tank.
Source:

increaseGunAngle()

Increase the gun angle by 1 degree. Stops at 180
Source:

isDead() → {Boolean}

Checks fi the tank is dead. Only returns true after the tanks is finished exploding.
Source:
Returns:
- if the tank is dead
Type
Boolean

moveLeft()

Move the tank to the left
Source:

moveRight()

Move the tank to the right
Source:

setGunAngle(newAngle)

Set the gun angle. If outside of the range 0 and 180 the gun remains at the same angle.
Parameters:
Name Type Description
newAngle number Angle in degrees between 0 and 180
Source:

shootProjectile() → {Boolean}

Shoots the chosen projectile from the tanks gun Contains a debouncing feature to prevent held down keys from shooting multiple projectiles
Source:
Returns:
If the projectile was successfully shot
Type
Boolean

update(dt)

Update the tanks position according to the game physics
Parameters:
Name Type Description
dt number The time between the current frame and the last one
Source:

Documentation generated by JSDoc 4.0.2 on Wed Oct 29 2025 23:51:02 GMT-0700 (Pacific Daylight Time)