-
Notifications
You must be signed in to change notification settings - Fork 21
How to create a new Enemy
Simon edited this page Mar 29, 2020
·
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:
- Add a new enum value to the
Character
enum in theCharacter.kt
file - Add a new enum value to the
ModelType
enum in theAnimationComponent.kt
file - Add a new configuration for the enum value that you have created in step 1 within the
loadCharacterConfigurations
method of theCharacter.kt
file. Let's say that you have added the value BAT to both enums then a new configuration might look like this:To see all possible options for a configuration, refer to thecfg(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 }
CharacterCfg
class of theCharacter.kt
file - 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. - 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 toAnimationComponent.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 - Sometimes the graphic does not exactly match the physic boundaries. In that case you can use the
collisionBodyOffset
of aCharacterCfg
.
Example: To correct the physic body by moving it 3 pixels to the right we can adjust the configuration from above to 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 + collisionBodyOffset(3f * UNIT_SCALE, 0f) }
- Sometimes you want to play a sound effect when a certain animation is played. You can configure that in the
getSound
function of theAnimationSystem
.