Skip to content

How to create a new Enemy

Simon edited this page Sep 29, 2019 · 5 revisions

An enemy is treated as a character from a code point of view. It is not different to the player or NPCs.

Follow these steps to create a new enemy. All code adjustments are done in the core project:

  1. Add a new enum value to the Character enum in the Character.kt file
  2. Add a new enum value to the ModelType enum in the AnimationComponent.kt file
  3. Add a new configuration for the enum value that you have created in step 1 within the initCharacterConfigurations method of the GameScreen.kt file. Let's say that you have added the value BAT to both enums then a new configuration might look like this:
    cfg(Character.BAT, EntityType.ENEMY, ModelType.BAT) {
        speed = 0.3f
        size(0.5f, 0.5f)
        attackRange = 0.15f
        attackCooldown = 2f
        damage = 2f
        life = 10f
        defaultState = DefaultEnemyState.IDLE
        aggroRange = 2.5f
    }
    To see all possible options for a configuration, refer to the CharacterCfg class of the Character.kt file
  4. Finally, to link your new character to the correct graphics go to the graphics_raw/gameObjects folder of the root project. Create a new folder using the same name as the enum value of the ModelType value that you have added.
  5. Add your graphics to this folder, start the graphicsTexPackProject.tpproj texture packer project located in the graphics_raw folder and repack the gameObjects atlas.
    The convention for the file names is the following: "AnimationType_INDEX" (refer to AnimationComponent.kt file).
    For example if you have a run animation with three frames then the names of the files would be: RUN_0, RUN_1, RUN_2