0
votes

- Tutorial: Conditions & Actions system for Statemachines

Statemachines become much more powerful with predefined conditions which, when satisfied, change to another state. When changing to another state, actions can be performed.

Conditions and actions are classes with a predefined interface that allows them to be added to any state, while a state subclass makes it easy to evaluate the conditions and perform the actions.

This tutorial explains how to setup such a system so that you can write Statemachines without having to write the same boilerplate code (such as checking distance between nodes) over and over again.

Pseudo example use:

AAPLEnemyChaseState *chase = [[AAPLEnemyChaseState alloc] initWithGame:game entity:enemy];
// automatically enter chase when player closer than "50" and own health above 25%
[chase addConditions:@[PlayerInRange(50), OwnerHealthPercent(GreaterThan, 25)]];

AAPLEnemyFleeState *flee = [[AAPLEnemyFleeState alloc] initWithGame:game entity:enemy];
// enter flee state when owner health below 25%, if so, play a sound once
[chase addConditions:@[OwnerHealthPercent(LessThan, 25)]];
[chase addActions:@[PlaySound(@"crybaby.wav")]];

Estimation: 2-3 days

Author: Steffen Itterheim, 25.06.2015, 20:19
Idea status: under consideration

Comments

Nobody commented on this idea

Leave a comment

Copyright - 2017 Informer Technologies, Inc. All Rights Reserved. Feedback system is used Idea.Informer.com