• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Tactics screen with waypoints for a manager game.

M

Molakar

Guest
I'm creating a manager game where a part of the game will focus around the creation of tactics using a waypoint system for the "players" you control. I've successfully experimented with making the "player" move from their starting position to a set of coordinates by letting them create their own path (if I recall correctly it was the mp_grid_path function) but now I want to take it one step further and have you, the manager, create a path for your players to follow.

Imagine something like Football Manager but instead of plotting out where on the football field the players shall position themselves I want to move my players using a system of waypoints. What I've thought up is a "tactics screen" where you place the waypoints for each player and then save them, when the corresponding "simulation room" loads the waypoints for each player also loads. The players then follow their respective route until completion.

Below is a quick sketch of what I'd imagine.



I've made a room with obstacles, made a copy of that room and then added a "_tactics" to the end of the name. My idea is to have manager enter the "tactics room", fiddle with the tactics, save it and then watch it all play out in the "simulation room" (the one without the "_tactics" at the end of its name).

I have an object called "obj_player_icon", that is what you see in the lower right corner of the image of the tactics screen. The object has the following events:

Create event
Code:
player_selected = false; //Player object initially starts out as deslected
array_x[0] = 0; 
array_y[0] = 0; 
markers = 0;
count = 0;

Alarm [0]
Code:
if markers > count  
{
    grid = mp_grid_create(0, 0, (room_width/8), (room_height/8), 8, 8);
    path = path_add();
    mp_grid_add_instances(path, obj_wall,1);
    mp_grid_path(grid,path, x, y, array_x[count], array_y[count], 1);
    path_start(path, 3, path_action_stop, 1);
    alarm[1] = 1; 
}
else
    if markers = count
    {
        count = 0;
        markers = 0; 
    }

Alarm[1]
Code:
if obj_player_icon.x = array_x[count] and obj_player_icon.y = array_y[count]
{
    count ++;
    alarm[0] = 1;
}
else
{
    alarm[1] = 1;
}

I also have three "mouse-events"

Left pressed
Code:
//Selects player with press of LMB if player is not selected
//Changes sprite from spr_player to _spr_player_selected
if player_selected = false 
{
    player_selected = true; 
    sprite_index = spr_player_selected;
}
//If player is selected deselct player and change back sprite from spr_player_selected to spr_player
else
{
    player_selected = false; 
    markers = 0;
    sprite_index = spr_player;
}

Global Left Pressed
Code:
//If player is selected create a checkpoint/"marker" where mouse pointer is
//Store mouse coordinates in array called [markers]
if player_selected = true  
{
    array_x[markers] = mouse_x;
    array_y[markers] = mouse_y;
    markers ++;
   
    instance_create_layer(mouse_x, mouse_y, "Checkpoints", obj_chkpnt); //Places waypoint on map
}

Global Right Pressed (this was mostly to check if everything worked, it "starts" the player when the RMB is pressed and the player is selected)

Code:
//If player is selected, deslect when RMB is pressed
//Change back to deselected sprite (spr_player)
if player_selected = true
{
    player_selected = false; 
    alarm[0] = 1; 
    sprite_index = spr_player; //changes sprite from selected (spr_player_selected) to deselected (spr_player)
}

For the object I use as waypoints ("obj_chkpnt") I have a Collision event that checks if obj_chkpnt collides with obj_player and if they do I destroy the waypoint so that the player can move towards the next waypoint. This was just added because I wanted to test how my player would move with multiple waypoints instead of just moving to a final destination. I'm guessing I have to come up with some other way to remove the waypoints from the array when in the simulation room.

Code:
instance_destroy();  //Destroy obj_chkpnt when obj_player touches it


So, where I'm at now is that I've checked that everything works and it does. The player moves towards the waypoints in order (doesn't matter which waypoint is closest, it always goes for the first placed waypoint, exactly like I want it to behave) and the waypoints gets destroyed when the player touches them. But I am unsure how to proceed to "transfer" the tactic made in one room so I can simulate the movement in another room? Do I need like a controller object or something like that that I store the arrays in and then access them in the room where I simulate everything?

TL;DR:
I have two identical rooms (room A and B) and want to use one room for making tactics with waypoints and the other room for simulating how those tactics are carried out by "players". So waypoints from room A have to be stored in an array that the "player" can access when in room B but I don't know how to do it.

I'm using IDE Version 2.2.3.436.
 

Goldoche

Member
Do I need like a controller object or something like that that I store the arrays in and then access them in the room where I simulate everything?
Yes. I'd say store the coordinates in a controller object and access it when you want to create the waypoints in room B.
 
M

Molakar

Guest
Yes. I'd say store the coordinates in a controller object and access it when you want to create the waypoints in room B.
Thank you. Then I need to read up on controller objects. Do you have any favorite practices when it comes to them that will help a beginner out?
 

Goldoche

Member
Thank you. Then I need to read up on controller objects. Do you have any favorite practices when it comes to them that will help a beginner out?
Sorry it took me so long to reply. Hopefully you have solved your problem by now. Nothing immediately comes to mind except you shouldn't ever have more than one existing at all times.
 
C

CedSharp

Guest
Thank you. Then I need to read up on controller objects. Do you have any favorite practices when it comes to them that will help a beginner out?
Controllers, Managers, "stats" objects are usually an object without a sprite and without any movement/collision/drawing logics.
They contain variables that you want to access from other objects but don't want to make global.

Since GameMaker doesn't have a "room-global variable", we have to use objects to store the information.

By convention, those objects should not have more than a single instance in a room.
You can have different controllers in the same room, but for one controller, say WaypointController, you should have only one instance :p

If you find the need to make a controller persistent, then maybe you should be using a global variable instead,
unless you need it to do some logic. (for example, a grid controller could be listening for mouse events).

Other than that, a controller is so different from one game context to another that it's quite hard to make
a guide or a tutorial about them. Just make it in a way that's usable and efficient, and more importantly
comfortable to your coding.

If you need any help, I can help, but I suggest you try it out on your own, it's easier to do that it is to explain :)
 
Top