Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Simple State Machine
- switch(State)
- {
- case Idle:
- //Idle in place
- if(Wait) {Wait -= 1;} else
- {
- //Move to a random location
- TargetX = irandom(room_width);
- TargetY = irandom(room_height);
- State = Moving;
- }
- break;
- case Moving:
- //We're vertical with target location
- if(TargetX = x)
- {
- //We're horizontal with target location
- if(TargetY = y)
- {
- //Stand in place for a few seconds
- Wait = 120 + irandom(120);
- State = Idle;
- }
- else
- {
- //Move horizontal towards target
- y += median(-Speed, (TargetY - y), Speed);
- }
- }
- else
- {
- //Move vertical towards target
- x += median(-Speed, (TargetX - x), Speed);
- //--//
- if(TargetY != y)
- {
- //Move diagonal towards target
- y += median(-Speed, (TargetY - y), Speed);
- }
- }
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment