NPC Movement

If the rooms are actually arranged like this, there is a simpler way to implement this.

First, number the rooms in either a clockwise or counterclockwise manner, you can still name the rooms differently, but for the movement this scheme is more convenient.

Now, you can randomly set the monster’s location and create the variable for movements.

*comment set initial monster location
*create monster_location 4
*create monster_movement 0

Then, when updating the position, you randomly generate an integer -1, 0, or 1 corresponding to (in this case) counterclockwise movement, no movement, and clockwise movement.

*comment determining monster movement
*rand monster_movement 1 3
*set monster_movement (monster_movement - 2)

*set monster_location (monster_location + monster_movement)
*if monster_location > 4
    *set monster_location (monster_location modulo 4)

If your actual room layout is more complex, other logic will be needed and more complex systems will be needed.

7 Likes