-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ambush action to lion entity; update state machine and action bar…
… for new mechanics
- Loading branch information
Showing
18 changed files
with
180 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
games/hungry-lion/src/screens/play/game-world/state-machine/states/lion/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
games/hungry-lion/src/screens/play/game-world/state-machine/states/lion/lion-ambush-state.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { LionEntity } from '../../../entities/entities-types'; | ||
import { BaseStateData, State } from '../../state-machine-types'; | ||
|
||
/** | ||
* State data interface for lion ambush state | ||
*/ | ||
export interface LionAmbushStateData extends BaseStateData { | ||
/** Flag to indicate if speed boost should be applied when transitioning to chasing */ | ||
applySpeedBoost?: boolean; | ||
} | ||
|
||
/** | ||
* Lion ambush state implementation | ||
* In this state: | ||
* - Lion does not move | ||
* - Lion is less noticeable by prey (handled by prey behavior) | ||
* - Transitions to chasing state with speed boost when target acquired | ||
*/ | ||
export const LION_AMBUSH_STATE: State<LionEntity, LionAmbushStateData> = { | ||
id: 'LION_AMBUSH', | ||
|
||
update: (data, context) => { | ||
const { entity } = context; | ||
|
||
// Return to idle if ambush action is disabled | ||
if (!entity.actions.ambush.enabled) { | ||
return { | ||
nextState: 'LION_IDLE', | ||
data: { enteredAt: context.updateContext.gameState.time }, | ||
}; | ||
} | ||
|
||
// If we have a target and attack is enabled, transition to chasing with speed boost | ||
if (entity.target.entityId && entity.actions.attack.enabled) { | ||
entity.actions.ambush.enabled = false; | ||
return { | ||
nextState: 'LION_CHASING', | ||
data: { | ||
enteredAt: context.updateContext.gameState.time, | ||
applySpeedBoost: true, // Set flag for speed boost | ||
boostAppliedAt: context.updateContext.gameState.time, // Set timestamp for speed boost | ||
}, | ||
}; | ||
} | ||
|
||
// In ambush state: | ||
// - No movement (zero acceleration and velocity) | ||
// - Keep target direction updated if we have a target | ||
entity.acceleration = 0; | ||
|
||
// Update direction to face target if one exists | ||
if (entity.target.entityId) { | ||
const targetEntity = context.updateContext.gameState.entities.entities.get(entity.target.entityId); | ||
if (targetEntity) { | ||
const dx = targetEntity.position.x - entity.position.x; | ||
const dy = targetEntity.position.y - entity.position.y; | ||
entity.targetDirection = Math.atan2(dy, dx); | ||
entity.acceleration = 0.001; | ||
} | ||
} | ||
|
||
// Stay in ambush state | ||
return { | ||
nextState: 'LION_AMBUSH', | ||
data: { | ||
...data, | ||
lastTargetUpdate: context.updateContext.gameState.time, | ||
}, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.