Gw Temp

Menu

Tutorial - 'Strategy Game Movement - Cursors' by Guest

An item about Gamemaker posted on

Blurb

A tutorial containing the code necessary to make a strategy game's movement cursor that appears to show where a unit's going and disappears when a unit reaches that location.

Body

Very Good, Very Simple ^^
Get ready.. open your v6.0 Gamemaker get a cup of coffee, relax and let's do it.

In this tutorial you'll learn the following things
1. How to make a marker appear when you right click and make the main character go to it.
2. How to destroy the marker when it collides with your char
3. In case you click and you click again before player is at it, the marker will dissapear and appear at the new mouse co-ordinates (something like red alert..)

First of all we will need 3 cool sprites, 1 for the cursor, 1 for the marker and 1 for the player.
Let's name them : sprCursor, sprMarker and sprPlayer
Make 1 new room and 4 new object
name the objects, objController, objCursor, objPlayer and objMarker and give them their sprites
at the "create" event of the objController set a the sprCursor as the sprite for your mouse.. and make the mouse not appear and randomly put it somewhere in the room and now the 3 important parts:
1. objCursor
At objCursor from the mouse events choose "Global Right Click" (or left if you want left..).
And add this code to it

if instance_exists(objMarker)
then instance_destroy()
instance_create(mouse_x,mouse_y,objMarker);

2. objPlayer
at objPlayer do the following: Create a "Step" event and add this code to it

if instance_exists(objMarker)
move_towards_point(objMarker.x,objMarker.y,5);
if !instance_exists(objMarker)
speed = 0;

Now add a collision event with objMarker and add this code to it

speed = 0;

3. objMarker
At objMarker create a "Right Global Click" event from mouse events and add this code

if instance_exists(objMarker)
then instance_destroy()
instance_create(mouse_x,mouse_y,objMarker);

That's all dudes.. now that wasn't not hard at all, was it?..
Now we will have the result we wanted ^^
Peace