Class: Sprite

Sprite(game, id, posX, posY, width, height, velocity, direction, hitPoints)

HTML DOM based sprite used for enemies, bullets, bombs etc Handles drawing, collision detection base routines

Constructor

new Sprite(game, id, posX, posY, width, height, velocity, direction, hitPoints)

Create a new sprite, sets properties.
Parameters:
Name Type Description
game Game The game instance.
id string Unique DOM element id.
posX number Position in the world / screen.
posY number Position in the world / screen.
width number Element width
height number Element height
velocity number Speed of element, pixels move per frame
direction number Direction of element, bearing in degress from north. 0-up, 180-down etc
hitPoints number Number of hit points to start with
Properties:
Name Type Description
id string Unique HTML DOM id
isActive string Is this sprite active or not
game string The main game instance
posX string X position in the world (HTML DOM coords)
posY string X position in the world (HTML DOM coords)
width string Width of this sprite in pixels
height string Height of this sprite in pixels
velocity string Speed this sprite is moving (pixels per frame)
direction string Bearing from north in degrees
hitPoints string Current hit points / health
domElement string The HTML DOM element of this sprite (usually a div)
Author:
Source:

Methods

destroyDomElement() → {boolean}

Remove this DOM element from the HTML document.
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.
Source:
Returns:
True if collision
Type
boolean

draw()

Update the DOM Element style properties to move the sprite
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.
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.
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.
Source:
Returns:
Type
boolean

move() → {boolean}

Move the sprite, overide this method in classes extending the Sprite class. Called on every game loop.
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.
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.
Source:
Returns:
Type
boolean

update() → {boolean}

Update loop, call the move() and draw() methods.
Source:
Returns:
Type
boolean