diff --git a/games/hungry-lion/GENAICODE_INSTRUCTIONS.md b/games/hungry-lion/GENAICODE_INSTRUCTIONS.md index 630c11e9..7b132384 100644 --- a/games/hungry-lion/GENAICODE_INSTRUCTIONS.md +++ b/games/hungry-lion/GENAICODE_INSTRUCTIONS.md @@ -237,4 +237,22 @@ When implementing ambush state and mechanics: - Balance risk/reward of ambush state - Consider prey behavior modifications -Remember: Documentation is as important as code. Every code change should be reflected in the project's documentation to maintain clarity and facilitate future development. \ No newline at end of file +Remember: Documentation is as important as code. Every code change should be reflected in the project's documentation to maintain clarity and facilitate future development. +### Debuff Mechanics Pattern +When implementing temporary effects on entities (debuffs): + +1. Debuff Definition: + - Use the `DebuffEffect` interface to define temporary effects + - Include start time and duration properties + - Consider the effect type and strength + +2. Application Guidelines: + - Apply debuffs through interaction definitions + - Set appropriate duration based on game balance + - Consider frame-rate independence for timing + +3. Processing and Cleanup: + - Check and process debuffs in entity update + - Apply effects consistently across all entity types + - Automatically clear expired debuffs + - Reset affected properties when debuff expires diff --git a/games/hungry-lion/GENAICODE_TRACKER.md b/games/hungry-lion/GENAICODE_TRACKER.md index 33c5045b..794a680f 100644 --- a/games/hungry-lion/GENAICODE_TRACKER.md +++ b/games/hungry-lion/GENAICODE_TRACKER.md @@ -103,6 +103,11 @@ * ✅ Implemented health reduction when touched by lion * ✅ Added force application towards lion * ✅ Implemented conversion to carrion when health reaches 0 + * ✅ Implemented Debuff System + * ✅ Added generic DebuffEffect interface + * ✅ Implemented velocity reduction during debuff + * ✅ Added debuff application in lion-prey interaction + * ✅ Added automatic debuff cleanup * ✅ Natural Prey Movement Behavior * ✅ Added idle states where prey sometimes stand still * ✅ Implemented social behaviors where prey sometimes follow others diff --git a/games/hungry-lion/src/screens/play/game-world/entities/entities-types.ts b/games/hungry-lion/src/screens/play/game-world/entities/entities-types.ts index 3a29a611..dbfa1f85 100644 --- a/games/hungry-lion/src/screens/play/game-world/entities/entities-types.ts +++ b/games/hungry-lion/src/screens/play/game-world/entities/entities-types.ts @@ -16,6 +16,12 @@ export interface Entity { forces: Vector2D[]; velocity: Vector2D; stateMachine?: [StateType, StateData]; + debuff?: DebuffEffect; +} + +export interface DebuffEffect { + startTime: number; + duration: number; } export interface LionEntity extends Entity { @@ -54,4 +60,4 @@ export interface CarrionEntity extends Entity { export type Entities = { entities: Map; nextEntityId: EntityId; -}; \ No newline at end of file +}; diff --git a/games/hungry-lion/src/screens/play/game-world/entities/entity-update.ts b/games/hungry-lion/src/screens/play/game-world/entities/entity-update.ts index 6c18dc5b..dfe680a7 100644 --- a/games/hungry-lion/src/screens/play/game-world/entities/entity-update.ts +++ b/games/hungry-lion/src/screens/play/game-world/entities/entity-update.ts @@ -17,6 +17,16 @@ export function entityUpdate(entity: Entity, updateContext: UpdateContext) { ); entity.forces.push(accelerationForce); + // Handle debuff effect + if (entity.debuff) { + const debuffElapsed = updateContext.gameState.time - entity.debuff.startTime; + if (debuffElapsed < entity.debuff.duration) { + entity.velocity = vectorScale(entity.velocity, 0.5); // Reduce velocity by 50% while debuffed + } else { + entity.debuff = undefined; // Clear expired debuff + } + } + entity.velocity = vectorAdd(entity.velocity, entity.forces.reduce(vectorAdd, { x: 0, y: 0 })); // TODO: Introduce angular velocity entity.direction = entity.targetDirection; diff --git a/games/hungry-lion/src/screens/play/game-world/interactions/definitions/lion-prey-interaction.ts b/games/hungry-lion/src/screens/play/game-world/interactions/definitions/lion-prey-interaction.ts index 37ae7639..68d8f25c 100644 --- a/games/hungry-lion/src/screens/play/game-world/interactions/definitions/lion-prey-interaction.ts +++ b/games/hungry-lion/src/screens/play/game-world/interactions/definitions/lion-prey-interaction.ts @@ -18,12 +18,18 @@ export const LION_PREY_INTERACTION: InteractionDefinition = { return distance < 30; // Same as maxDistance for consistency }, - perform: (source, target) => { + perform: (source, target, updateContext) => { const prey = target as PreyEntity; // Reduce prey health prey.health = Math.max(prey.health - HEALTH_DECREMENT, 0); + // Apply slow debuff + prey.debuff = { + startTime: updateContext.gameState.time, + duration: 500, // 500ms slow duration + }; + // Apply force towards lion const direction = vectorNormalize(vectorSubtract(source.position, prey.position)); const force = vectorScale(direction, FORCE_STRENGTH);