Feature: Implement invincibility and combo systems
All checks were successful
Build and Publish Docker Image / Build and Validate (pull_request) Successful in 9s
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.
This commit is contained in:
parent
e33f5a97a7
commit
54c2fa0380
6 changed files with 313 additions and 7 deletions
49
src/systems/InvincibilitySystem.js
Normal file
49
src/systems/InvincibilitySystem.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue