Constructor
new ShieldGrid(game)
Create a new shield grid
Parameters:
Name | Type | Description |
---|---|---|
game |
SpaceInvaders | The current game instance |
Properties:
Name | Type | Description |
---|---|---|
shieldBlocks |
array | The main shield grid array, stores all the shield blocks |
shieldPattern |
array | A pattern to read and turn into the shield grid |
- 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:
getShieldBlockAt(x, y) → {ShieldBlock}
Return the ShieldBlock instance at the global pixel coord provided.
Converts to the local shieldGrid coords (40x4 grid)
Parameters:
Name | Type | Description |
---|---|---|
x |
number | Global X pixel position |
y |
number | Global y pixel position |
- Source:
Returns:
Or false if position is empty
- Type
- ShieldBlock
getShieldBlocksCollidingWith(sprite) → {Array.<ShieldBlock>}
Return the ShieldBlock(s) that are colliding with the supplied
Sprite instance. Uses the shieldGrid array to quickly find all
the blocks touching the sprite
Parameters:
Name | Type | Description |
---|---|---|
sprite |
Sprite | The sprite instance colliding with the shield. |
- Source:
Returns:
Array of shieldBlocks in collision with sprite.
- Type
- Array.<ShieldBlock>
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
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
makeGrid(pattern)
Make the grid pattern by creating new ShieldBlock instances
Populates the shieldBlocks array from shieldPattern
Parameters:
Name | Type | Description |
---|---|---|
pattern |
array | The shield pattern array to make |
- Source:
move() → {boolean}
Move the sprite, overide this method in classes extending the Sprite class.
Called on every game loop.
- Inherited From:
- Source:
Returns:
- Type
- boolean
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
reset()
Reset the shield to default. Remove all the shield blocks from the
shield grid HTML dom element.
- Source:
update() → {boolean}
Update loop, call the move() and draw() methods.
- Inherited From:
- Source:
Returns:
- Type
- boolean