Skip to content

Commit

Permalink
implement debuff system; add DebuffEffect interface and apply slow de…
Browse files Browse the repository at this point in the history
…buff in lion-prey interaction
  • Loading branch information
gtanczyk committed Jan 24, 2025
1 parent 7767452 commit 96223e9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
20 changes: 19 additions & 1 deletion games/hungry-lion/GENAICODE_INSTRUCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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
5 changes: 5 additions & 0 deletions games/hungry-lion/GENAICODE_TRACKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -54,4 +60,4 @@ export interface CarrionEntity extends Entity {
export type Entities = {
entities: Map<EntityId, Entity>;
nextEntityId: EntityId;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 96223e9

Please sign in to comment.