Skip to content

obj_enemy

Brandyn Britton edited this page Aug 12, 2017 · 1 revision

What is it?

The obj_enemy object is intended to be a base class for all enemies within the game. The enemy will chase the obj_player within a certain radius, deal damage when it touches the player and then rest for a certain period before attempting to chase the player again.

The enemy has several states:

  • IDLE - Not doing anything
  • WANDERING - Wandering around the room
  • CHASING - Currently chasing the player
  • ATTACKING - Currently dealing damage to the player
  • ATTACK_COOLDOWN - Currently on cooldown after attacking the player (similar to IDLE)

Create

In the create section of obj_enemy, we define several class fields including:

  • states - An enumerator that contains all the possible states of the enemy
  • current_state - The current state of the enemy, chosen from states
  • move_speed - The speed at which the enemy moves
  • cool_down - The cooldown period after the enemy attacks
  • detect_radius - The radius in which it will start chasing the player
  • wander_x_dir and wander_y_dir - The direction (-1, 0, 1) along x and y axis the enemy will wander along
  • max_damage - The max damage the enemy can deal to the player

Step

The step event will control the enemies states and movement. First off, if the obj_player is within range of the enemy, the enemy will begin chasing the player. If the obj_player is not within range, the enemy will randomly transition between IDLE and WANDERING states. If the enemy collides with the obj_player, alarm[0] will be triggered and the enemy will remain motionless until the alarm finishes.

The step event will also check for collisions with environment objects such as obj_solid as well as obj_player[1]. If a collision occurs with obj_player, a random damage between 0 and max_damage is dealt to the obj_player.

Alarms

  1. Sets current_state to CHASING

[1] - Although this is done using the collision event in other objects, within the enemy this is handled directly through code just to offer alternate ways of handling things

Clone this wiki locally