VeryVariable: Mini-Map Interaction

2

Stats

2,642 visits, 3,793 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 29 Feb, 2012. Last updated 19 Feb, 2019

In the other tutorial we learned how to map the players position on a layout to a Mini-Map. Now we will take things one step further. Instead of just using the Mini-Map to display where the Player is we will also use it as an interactive part of the game.

What we will be doing is creating variables to store information based on the Mini-Map and apply it to the whole layout. More specifically we will use a mouse click on the Mini-Map to reposition the Player somewhere else on the layout.

With the Mini-Map already in place we will add the following variables and events.

First off, there are 2 global variables named mapclick_x and mapclick_y. These are used to store information about where the Mini-Map was clicked and where we want the Player to move to.

In the event, the actions are only activated when the mouse clicks over the object Map. When that happens the mapclick variables will be set to a specific formula.

Let's break down the parts of the formula.

(Mouse.AbsoluteX - Map.X)

This part gets the value of X relative to the map and not the layout. In the picture, when the mouse is at the position of the red arrow the AbsoluteX is 463 and the Map.X is 438. If we subtract AbsoluteX from Map.X we get 25, or the distance of the red line. This gives us where the Mini-Map was clicked relative to the position of the Mini-Map.

-AbsoluteX is used instead of just X because X is relative to the whole layout, but AbsoluteX shows the X position relative to the part of the layout you're looking at.

-Map.X is measured based on the top-left corner of the Mini-Map. Remember, in the previous tutorial we set the image point at this corner.

(Mouse.AbsoluteX - Map.X)/Map.Width

Next, we take this value and divide it by the width of the Mini-Map. This gives us the X value in a percentage format. Using the example in the picture, the red line would be 25 and the width of the Mini-Map is 180, so 25/180 is about 0.14. This means that the mouse is at 14% of the Mini-Map. If the mouse was at the left edge of the map it would be 0% and if it was at the right edge it would be 100%.

(Mouse.AbsoluteX - Map.X)/Map.Width * LayoutWidth

Now we want to take that percentage value and multiply it by the width of the layout. This translates the position clicked on the Mini-Map to the whole layout. So, since the value on the map was 0.14, or 14%, we also want to be at 14% on the layout. The layout width I have is 2500, so 14% of 2500 would be 350.

Going back to the whole event, the final actions will map the X position of the Player to this new number by setting it to mapclick_x. In our example, it would move the Player to 350 on the layout if you clicked on the Mini-Map where the red arrow is pointing. The same idea can be applied to the Y coordinate as well to move the Player anywhere you click on the Mini-Map.

Additional Notes

Also, note that in this example the game type is a platformer. This means 2 things:

1) That there is gravity

Since there is gravity if you reposition the Player in the air somewhere it will fall. The same happens if you position the Player over a hole or a pit.

2) The layout scrolls to the position of the Player.

This means wherever you click on the Mini-Map is where your Player will go, but also where you will view. If you didn't want the Player to move but you wanted to scroll when you clicked on the map you can replace the 'Set X/Y' action for the Player to a 'Scroll to' action for the System.

Various Ways to Use: Beginner

Teleport the Player

Move it wherever you want. Use it as part of the gameplay.

Teleport something else

Who says that you have the move the player? Maybe you could try moving other objects on the level.

Viewing Window

A viewing window could be used to view different parts of the level without moving any units around. A box over the Mini-Map could be added to indicate which part of the layout is being viewed.

Various Ways to Use: Advanced

Target Sites

When you click on the Mini-Map, instead of moving something or scrolling to that part of the layout the variables could be used to set a target. Maybe for missiles, maybe as a teleport exit, or to put up walls. There are many ways such a target site can be used.

  • 0 Comments

Want to leave a comment? Login or Register an account!