27 for (
auto entityId : entities) {
31 weapon.
setCooldown(std::max(0.0F, weapon.getCooldown() - deltaTime));
38 if (weapon.shouldShoot() && weapon.getCooldown() <= 0.0F) {
43 if (weapon.shouldShoot() && weapon.getCooldown() <= 0.0F) {
45 if (!weapon.isCharging()) {
46 weapon.setCharging(
true);
47 weapon.setChargeLevel(0.0F);
51 float newCharge = weapon.getChargeLevel() + (weapon.getChargeRate() * deltaTime);
52 weapon.setChargeLevel(newCharge);
55 if (weapon.getChargeLevel() >= 1.0F) {
56 weapon.setChargeLevel(1.0F);
58 }
else if (!weapon.shouldShoot() && weapon.isCharging()) {
60 float chargeLevel = weapon.getChargeLevel();
63 bool isFriendly =
true;
67 weapon.setCharging(
false);
68 weapon.setChargeLevel(0.0F);
71 float fireRate = weapon.getFireRate();
72 if (fireRate > 0.0F) {
73 weapon.setCooldown(1.0F / fireRate);
75 weapon.setCooldown(1.0F / 7.0F);
77 }
else if (!weapon.shouldShoot() && !weapon.isCharging()) {
79 weapon.setChargeLevel(0.0F);
93 float baseSpeed = 500.0f;
115 fireMultipleShots(registry, ownerId, damage, baseSpeed, isFriendly,
false, shotCount);
123 return createProjectile(registry, ownerId, projectileTransform, projectileVelocity, damage,
129 float dirX = isFriendly ? 1.0F : -1.0F;
130 return Velocity(dirX, 0.0F, baseSpeed);
143 float offsetX = isFriendly ? 40.0F : -40.0F;
144 return Transform(ownerPos.x + offsetX, ownerPos.y);
147 return defaultTransform;
153 const float CHARGE_THRESHOLD = 0.5F;
155 if (chargeLevel < CHARGE_THRESHOLD) {
157 return fireWeapon(registry, ownerId, isFriendly);
168 float damageMultiplier = 1.0F + chargeLevel * 1.5F;
169 float speedMultiplier = 1.0F + chargeLevel * 0.5F;
171 float chargedDamage = weapon.
getDamage() * damageMultiplier;
172 float chargedSpeed = 500.0f * speedMultiplier;
194 fireMultipleShots(registry, ownerId, chargedDamage, chargedSpeed, isFriendly,
true, shotCount);
202 return createProjectile(registry, ownerId, projectileTransform, projectileVelocity, chargedDamage,
207 return (1ULL << getComponentType<Weapon>()) | (1ULL << getComponentType<Transform>());
212 float damage,
bool isFriendly,
bool isCharged) {
213 auto projectileId = registry.
newEntity();
221 uint32_t layer = isFriendly ? 4 : 8;
222 registry.
setComponent(projectileId,
Collider(10.0f, 10.0f, 0.0f, 0.0f, layer, 0xFFFFFFFF,
false));
229 std::string animationName = isCharged ?
"charged_projectile_1" :
"projectile_fly";
231 float scale = isCharged ? 2.5f : 2.0f;
234 ecs::Sprite projSprite(
"Projectiles", projRect, scale, 0.0f,
false,
false, 0);
241 if (fireRate > 0.0F) {
242 weapon.setCooldown(1.0F / fireRate);
252 static_cast<int>(damage), isFriendly);
259 bool isFriendly,
bool isCharged,
int shotCount) {
265 float angleSpread = 0.0f;
266 float startAngle = 0.0f;
283 startAngle = -(angleSpread * (shotCount - 1)) / 2.0f;
290 for (
int i = 0; i < shotCount; i++) {
291 float angle = startAngle + (i * angleSpread);
292 float angleRad = angle * 3.14159f / 180.0f;
295 float baseDir = isFriendly ? 1.0F : -1.0F;
296 float dirX = baseDir * std::cos(angleRad);
297 float dirY = std::sin(angleRad);
298 Velocity projectileVelocity(dirX, dirY, speed);
301 Transform projectileTransform = baseTransform;
303 projectileTransform.
setPosition(pos.x, pos.y + (i - shotCount / 2) * 5.0f);
305 createProjectile(registry, ownerId, projectileTransform, projectileVelocity, damage, isFriendly,
Component containing all available animations for an entity.
Component managing current animation playback state.
Component managing active buffs on an entity.
bool hasBuff(BuffType type) const
Check if entity has a specific buff.
Component for collision detection and physics interactions.
Component identifying an entity as an enemy with AI behavior.
Component for projectile entities (bullets, missiles, etc.).
Manages entities, their signatures and component type registrations.
std::vector< Address > getEntitiesWithMask(Signature requiredMask)
Get all entities matching a specific component mask.
Address newEntity()
Create and register a new entity, returning its Address.
T & getComponent(Address address)
Get a component from an entity.
bool hasComponent(Address address)
Check if an entity has a specific component.
void setComponent(Address address, const T &component)
Set/add a component to an entity with its data.
Component representing a visual sprite from a texture.
Component representing movement direction and speed.
Vector2 getDirection() const
Get the direction vector.
float getSpeed() const
Get the movement speed.
std::uint32_t fireChargedShot(Registry ®istry, std::uint32_t ownerId, float chargeLevel, bool isFriendly)
Fire a charged shot if charge is sufficient, otherwise fire normal shot.
void update(Registry ®istry, float deltaTime) override
Manages weapon cooldowns for all entities.
std::uint32_t fireWeapon(Registry ®istry, std::uint32_t ownerId, bool isFriendly)
Fire a weapon from an entity, spawning a projectile.
ProjectileCreatedCallback _projectileCreatedCallback
std::uint32_t createProjectile(Registry ®istry, std::uint32_t ownerId, const Transform &transform, const Velocity &velocity, float damage, bool isFriendly, bool isCharged)
Create a single projectile with specified properties.
ComponentMask getComponentMask() const override
Gets the component mask for this system.
void fireMultipleShots(Registry ®istry, std::uint32_t ownerId, float damage, float speed, bool isFriendly, bool isCharged, int shotCount)
Fire multiple projectiles based on multishot buff.
Velocity calculateProjectileVelocity(float baseSpeed, bool isFriendly)
Calculate projectile initial velocity based on owner's velocity.
Transform calculateProjectileTransform(Registry ®istry, std::uint32_t ownerId, bool isFriendly)
Calculate projectile spawn position based on owner position.
Component for entities capable of shooting projectiles.
float getDamage() const
Get damage value.
float getFireRate() const
Get fire rate.
void setCooldown(float cooldown)
Set cooldown timer.
ecs::AnimationSet createPlayerBulletAnimations()
Create player bullet animations.
Maximum number of distinct component types supported by the Registry.
@ TripleShot
Fire three projectiles at once.
@ MultiShot
Shoot in multiple directions.
@ DoubleShot
Fire two projectiles at once.
std::uint64_t ComponentMask
Type alias for component bitmask.
Rectangle structure defining a region in a texture.