a puzzlescript problem

Skip to first unread message

Erich Friedman

Oct 15, 2021, 6:04:14 PM10/15/21
to PuzzleScript
greetings everyone.  i am new to puzzlescript and this is my first post.  be gentle.

i am trying to design a game in which ghosts move towards players, but only in response to the player moving in the same row or column as the ghost.  so far so good, this code will do that:

[> Player|no obstacle]->[> Player|step]

[step|...|Ghost]->[step|...|< Ghost] 

late [step]->[ ]

but what i really want is that ghosts don't move towards the player if there is an obstacle in the way.  i only want ghosts that "see" the player horizontally or vertically to move towards the player.

how do i do that?



Oct 16, 2021, 11:13:27 PM10/16/21
to PuzzleScript
Just found a solution. You want to do this if you want the ghosts to not move when the player is behind walls:

[ step|…|no obstacle | ghost] -> [step |…| no obstacle | < Ghost ]

It’s a common mistake. But hey! Now you know.

Jack Kutilek

Oct 18, 2021, 8:55:26 PM10/18/21
to PuzzleScript
one option is to do a raycast. create an object on the ghost for each direction, then advance them all along their given direction until they hit a wall or a player. if one hits a player then send a response ray back to the ghost which tells it to move. you can do this all within a single turn, but it does get a little cumbersome because you have to make separate objects for each direction, and separate rules to advance each object along its direction.

So something like the following (for just a left ray):

[ghost no left_ray]->[ghost left_ray]
left [left_ray | no wall no player] -> [ | left_ray]
left [left_ray | wall]->[ | wall]
left [left_ray | player]->[right_response_ray | player]

right [right_response_ray | no wall no player] -> [ | right_response_ray]
right [right_response_ray | stationary ghost]->[ | left ghost]

(checking for the stationary ghost should resolve some problems where two ghosts are in the same line of sight to the player, if that is a possibility)
Reply all
Reply to author
0 new messages