Skip to main content

EnemyEntityFactory

EnemyEntityFactory creates an enemy entity. The EnemyType passed at init determines the sprite, scale, and mass of the resulting entity.

Usage

EnemyEntityFactory(at: position, type: .mummy, baseScale: scale).make(in: world)

// baseScale defaults to 1 if omitted
EnemyEntityFactory(at: position, type: .tower).make(in: world)

Parameters

ParameterTypeDefaultDescription
positionSIMD2<Float>Spawn position in world space
typeEnemyTypeDetermines texture, scale multiplier, and mass
baseScaleFloat1Base scale — multiplied by type.scale to get the final world scale

EnemyType

EnemyType is defined in EnemyEntityFactory.swift. Each case provides a texture name, a scale multiplier, and a mass value used by KnockbackSystem.

TypeTextureScaleMass
.charger"Charger"1.015
.mummy"Mummy"1.010
.ranger"Ranger"0.755
.tower"Tower"1.520

The final in-world scale is baseScale × type.scale.

Components Added

ComponentInitial Value
TransformComponentposition, rotation 0, baseScale × type.scale
SpriteComponenttype.textureName, layer .entity
EnemyTagComponenttype.textureName, final scale
VelocityComponentZero
EnemyStateComponentDefault AI config
CollisionBoxComponentplayerSize × finalScale
MassComponenttype.mass

Adding a New Enemy Type

See Enemies — Adding a New Enemy Type.