new BHell_Enemy_Base()
Enemy base class. Each enemy's behaviour is controlled by a mover, an array of emitters and a parameter object, but this modularity can be overridden in derived classes.
Parameters shared between all enemies:
- hp: Hitpoints of the enemy,
- speed: Movement's speed (the unit is determined by the specific mover used),
- period: Emitters' period,
- hitbox_w: Width of the hitbox used for collisions with bullets and the player,
- hitbox_h: Height of the hitbox,
- angle: Shooting angle,
- aim: Aim parameter for the emitters,
- always_aim: Always_aim parameter for the emitters,
- rnd: If the emitters aren't aimed at the player and rnd = true, every shot's direction is randomized,
- score: Score points awarded for each successful bullet hit,
- kill_score: Score points awarded on enemy's death,
- boss: If true, an hp bar will be shown,
- boss_bgm: If defined, plays this BGM instead of the one defined on the map,
- suppress_warning: If true (together with boss), doesn't show the warning sign,
- resume_bgm: If true, when the monster is defeated, resumes the previous BGM,
- bullet: bullet parameters (see
BHell.BHell_Bullet
).
- Source:
Extends
Methods
checkCollision(x, y) → {boolean}
Checks if the given coordinates are inside the enemy's hitbox. In case of collision, stores the coordinates into this.lastX and this.lastY (useful for spawning explosions, for example).
Parameters:
Name | Type | Description |
---|---|---|
x |
X coordinate. |
|
y |
Y coordinate. |
- Source:
Returns:
true if (x, y) is inside the hitbox.
- Type
- boolean
crash() → {boolean}
Crashes the enemy, destroying it.
- Source:
Returns:
True if the crash has succeded (e.g. bosses immune to crashing will return false).
- Type
- boolean
destroy()
Destroys the enemy sprite and removes it from the controller's array of enemies.
- Source:
die()
Awards the killing score and destroys the enemy.
- Source:
hasCrashed(player) → {boolean}
Checks if the enemy has collided with the player.
Parameters:
Name | Type | Description |
---|---|---|
player |
Player object. |
- Source:
Returns:
True if there is a collision.
- Type
- boolean
hit()
Makes the enemy lose one hit point, possibly killing it.
- Source:
initialize(x, y, image, params, parent, enemyList)
Constructor. Sets the parameters shared between all classes.
Parameters:
Name | Type | Description |
---|---|---|
x |
X spawning coordinate. |
|
y |
Y spawning coordinate. |
|
image |
Enemy sprite. |
|
params |
Setup parameters. |
|
parent |
Container for the enemy's, emitters' and bullets' sprites. |
|
enemyList |
Array in which the enemy will be pushed. |
- Overrides:
- Source:
isOutsideMap() → {boolean}
Checks if the enemy has left the map, but only after it has appeared on screen to avoid triggering the enemy's destruction when it's just spawned.
The controller relies on this method to destroy enemies, so enemies which shouldn't be destroyed when leaving the map should always return false.
- Source:
Returns:
True if the enemy has appeared on the screen and is currently outside the screen.
- Type
- boolean
move()
Moves the enemy and all its emitters, delegating the calculations to its mover.
- Source:
shoot(t)
Enables/disables shooting for every emitter (but only if the player is ready to move).
Parameters:
Name | Type | Description |
---|---|---|
t |
True to enable shooting, false otherwise. |
- Source:
update()
Update function, called every frame.
- Overrides:
- Source:
updateCharacterFrame()
Updates the charset frame, calculating the correct offsets.
- Inherited From:
- Source: