Class: EnemyShip

EnemyShip(game, fleet, bombFactory, startX, startY, direction, id, css)

The basic enemy ship, bomb countdown, movement logic etc. Extended by other ship types.

Constructor

new EnemyShip(game, fleet, bombFactory, startX, startY, direction, id, css)

Create an enemy ship.
Parameters:
Name Type Description
game SpaceInvaders The current game.
fleet EnemyFleet Factory that created this instance.
bombFactory EnemyBombFactory Factory to create enemy bombs.
startX number Starting X position.
startY number Starting Y position.
direction number Direction ship is moving.
id string Unique DOM ID.
css string Additional CSS class to be assigned to this ship.
Properties:
Name Type Description
game SpaceInvaders
fleet EnemyFleet The Enemy Fleet factory instance.
scoreValue number Score player gets for shooting this ship down.
rotation number Rotation angle for death animation.
lastDirection number The last direction the ship was moving.
moveCounter number Counter used in the movement logic.
isDying boolean Is this ship in its death animation.
maxBombReload number Max number of frames before another bomb can be dropped.
Author:
Source:

Extends

Methods

destroyDomElement() → {boolean}

Remove this DOM element from the HTML document.
Inherited From:
Source:
Returns:
Type
boolean

detectCollisionWith(sprite) → {boolean}

Detect collision between two sprites. Checks for any gaps between the sprites.
Parameters:
Name Type Description
sprite Sprite The sprite we are checking for a collision with.
Inherited From:
Source:
Returns:
True if collision
Type
boolean

draw()

Update the DOM Element style properties to move the sprite
Inherited From:
Source:

inMe(x, y) → {boolean}

Is the x, y game world point inside this sprite.
Parameters:
Name Type Description
x number The X position.
y number The Y position.
Inherited From:
Source:
Returns:
True if inside
Type
boolean

kill()

Kills the enemy ship and starts the death animation loop, updates Score.
Source:

makeDomElement(css) → {boolean}

Make the DOM element for this sprite inside the Game element.
Parameters:
Name Type Description
css string CSS style to apply to the element.
Inherited From:
Source:
Returns:
Type
boolean

makeDomElementInside(parent, css) → {boolean}

Make the DOM element for this sprite inside the supplied element and assign it the supplied css class.
Parameters:
Name Type Description
parent Sprite The parent sprite or object with a DOM element.
css string CSS style to apply to the element.
Inherited From:
Source:
Returns:
Type
boolean

move()

Process the movememnt logic - Move till edge, move down for 25 frames, move back other direction.
Overrides:
Source:

receiveDamage(damage) → {boolean}

Receive damage on this sprite, what happens when hit points < 0 is handled by the class that extended the sprite class. If hit points < 0 returns True to indicate this was a kill
Parameters:
Name Type Description
damage number The amount of damage received.
Inherited From:
Source:
Returns:
True if this was a kill shot
Type
boolean

receiveHealth(health) → {boolean}

Receive health
Parameters:
Name Type Description
health number The amount of health / hit points received.
Inherited From:
Source:
Returns:
Type
boolean

startBombCountdown()

Reset the bomb counter to a random number, drops 1 each game loop. When it reaches 0 the update loop will trigger a new bomb to be created from the EnemyBombFactory.
Source:

update() → {boolean}

Main update loop called every animation frame. Dying - If the ship is dying rotate and shrink it until width < 5 Hit Points - If < 0 start the dying process Bomb launch - Check the countdown and if < 0 make new bomb Collision detection - player ship and shieldblock
Overrides:
Source:
Returns:
Success or failure.
Type
boolean