How To Check Movement Direction – PuzzleScript

This post is part of a series in learning how to make games with PuzzleScript. If you haven’t read my previous tutorials, I recommend you do so here, as that is assumed knowledge for this post.

Specifying Directions

There might be times when you want to check for something only in a certain direction. You might, for example, want to create blocks that can only be pushed horizontally. Or you might want to create a duck that can only walk left.

Whatever your reasons, you specify things to occur only in specific directions.

Open up PuzzleScript, make a new game based on the Basic example and replace their Rules with the following code:

[ Left Player ] -> [ Crate ]

Run the game and see what happens.

If you try and walk left at any point, the player will turn into a crate. This is a really good example of how specifying directions works.

We’re used to this format I’ve used before to explain code in PuzzleScript:

[ Condition ] -> [ Event ]

If the condition is true, the event will occur.

But now that we want to check for directions, it follows new rules:

[ Movement Direction Object Affected ] -> [ New State of Object ]

So our previous code:

[ Left Player ] -> [ Crate ]

Is checking if the player is moving Left. If it is, swap the player with the crate object.

Direction Types

The different types of directions you can choose from are:

  • Up
  • Down
  • Left
  • Right
  • Horizontal (checks to see if there is any horizontal movement)
  • Vertical (checks to see if there is any vertical movement)

Conclusion

The nest tutorial is on how to create custom movements. If you have any questions you can leave a comment below.

Follow this blog for more tutorials on Puzzle Script, games development and updates on my projects.

Next Tutorial >

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s