All checks were successful
Build and Publish Docker Image / Build and Validate (pull_request) Successful in 9s
- Added Invincibility component to manage invincibility state and duration. - Introduced InvincibilitySystem to handle visual effects during invincibility. - Updated Game class to integrate combo multiplier mechanics and high score tracking. - Enhanced UI to display current combo status and high score. - Configured GameConfig for centralized game settings, including obstacle damage and invincibility duration. - Updated game logic to reset combo on damage and manage health regeneration. This update enhances gameplay dynamics by introducing invincibility frames and a scoring combo system.
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
import { System } from '../ecs/System.js';
|
|
import { Invincibility } from '../components/Invincibility.js';
|
|
import { MeshComponent } from '../components/MeshComponent.js';
|
|
import { GameConfig } from '../game/GameConfig.js';
|
|
|
|
/**
|
|
* InvincibilitySystem - handles invincibility flashing effect
|
|
*/
|
|
export class InvincibilitySystem extends System {
|
|
constructor() {
|
|
super();
|
|
this.flashTimer = 0;
|
|
}
|
|
|
|
/**
|
|
* Update invincibility timers and flash effect
|
|
* @param {number} deltaTime - Time since last frame in seconds
|
|
*/
|
|
update(deltaTime) {
|
|
const entities = this.getEntities(Invincibility, MeshComponent);
|
|
|
|
this.flashTimer += deltaTime;
|
|
|
|
for (const entityId of entities) {
|
|
const invincibility = this.getComponent(entityId, Invincibility);
|
|
const meshComp = this.getComponent(entityId, MeshComponent);
|
|
|
|
if (!invincibility || !meshComp) continue;
|
|
|
|
// Update invincibility timer
|
|
invincibility.update(deltaTime);
|
|
|
|
// Flash effect - toggle visibility based on flash rate
|
|
if (invincibility.getIsInvincible()) {
|
|
const flashInterval = Math.floor(this.flashTimer / GameConfig.INVINCIBILITY_FLASH_RATE);
|
|
meshComp.mesh.visible = flashInterval % 2 === 0;
|
|
} else {
|
|
// Always visible when not invincible
|
|
meshComp.mesh.visible = true;
|
|
}
|
|
}
|
|
|
|
// Reset flash timer periodically to prevent overflow
|
|
if (this.flashTimer > 10) {
|
|
this.flashTimer = 0;
|
|
}
|
|
}
|
|
}
|
|
|