GMS 2 Moving character in a 3X3 Grid (Battle Network)

iKiwed

Member
Hello! I'm new here. Before to post this topic I read both guidelines. I hope it's the right section, otherwise my apologies. I'm not a programmer, even if I know the basis. I'm more into giving ideas and making illustrations. This is why I use both GML and DnD, and I try to "experiment" before to watch video tutorials.

My objective is to make a simple game with a similar gameplay as Mega Man Battle Network.
The gameplay consists of a board with two grids 3X3 occupied by the player and the enemy.
Before to even think about shooting and enemies, I need to overpass my very first issue: Moving the character.

In Battle Network the player can "teleport" the character on their 3X3 grid (which means 9 platforms).
If, for example, the player is in the middle of the grid and press left, the player is automatically to the middle-left platform, without moving/slide animations whatsoever. Keep pressing the button in whatever direction won't automatically teleport the player to a farest platform, which means the player is forced by the gameplay to press the button again if they want to go to the other side of the grid.

I've been thinking of some ideas:
1) Jump the player to specific coordinates.
In my game the idea is to include the slide "animation" where the player moves from a platform to another.
In terms of gameplay nothing big changes, except I can't literally jump/teleport the player to a specific platform/coordinate. But even so, I don't like this idea because I'm not sure if it would work the same with a different screen or console platform. For example, even if it would work on my PC, I doubt it's the same on smartphone. So I need a smarter idea.

2) Collisions. Usually it's used everywhere, especially on 2D platforms, but I don't think it's the right choice.
Even if I would add collisions, I need to find a way to stop moving the player in the three top/middle/down centre platform. If I add a thin cross invisible collision point, the character must stop and then overpass the collision, which means the collision must be deleted, but when the character passed on another platform, the collision point must reappear. And I'm not sure if it's the right solution.
Not only that, but I also need to think of possible platform variables (in the future). In Mega Man Battle Network it's possible you have different platforms in your grid: They may be broken, with fire, Ice, etc. Even if I'm far from "finishing" the game, and I don't have much experience, so I don't want to worry about those platforms at the moment, but I must take note of these variables in the future, this is why I need a clearer and more adaptable idea, where the game automatically recognize the platform and understands if the player can pass on it or not. Collision isn't the right choice, imo.


4) Define the (object) obj_platform and the character. This is the current conclusion I have at the moment.
For example, the platform should have the acknowledge of its position between the 9 platforms because, let's say the player goes to the left, the leftmost platform must stop the player from going outside the grid. And if the player choose to press the left button for whatever reason, the character must stay on the centre of the platform instead of going to the border. Maybe it would be good to give a number to each platform or platform "area", for example.
The single platform in my game is 64x64, which means the character and/or the platform must recognize if they overlapped each other.

Again, I'm not a programmer. I know the basis like variables, if, switch,vectors, etc. But my vocabulary is still short. As first attempt, I just want to make this playable. graphically speaking isn't a problem, but it is for programming. So I ask you, wise members of the forum, your help and experience to find a way out of this.

Thank you very much.
(If you think it's too hard to make a game like this, I guess I could try something else, even if I don't know what.)
 

Ratsha

Member
There are multiple ways to do this. One approach would be to used data structure grid (http://docs2.yoyogames.com/source/_...reference/data_structures/ds grids/index.html). However, if you just want get some gameplay started (wish i believe is a great idea), your approach to have each platform as an object is a good start.

Assuming the platform are placed as in the picture and their origin is in the center, you can check if there are platform at the correct location in the Step Event of obj_character:
Code:
var nextPlatform = noone
if keyboard_check_released(ord("D"))
{
    nextPlatform = instance_place(x + 300, y, obj_platform)
}
else if keyboard_check_released(ord("A"))
{
    nextPlatform = instance_place(x - 300, y, obj_platform)
}
else if keyboard_check_released(ord("W"))
{
    nextPlatform = instance_place(x, y - 200, obj_platform)
}
else if keyboard_check_released(ord("S"))
{
    nextPlatform = instance_place(x, y + 200, obj_platform)
}
if nextPlatform != noone
{
    x = nextPlatform.x
    y = nextPlatform.y
}
Replace 300 with the width of the platforms and 200 with the height of the platforms.

This is the simplest I can come up with right now. Next step would be to prevent multiple instances at same platforms, animations to platform and combat. Please tell me if it works out.
 

iKiwed

Member
Sorry for the late message, I've been a little busy. Thank you for your assistance!
Yes, I've tried your code and it works! I've just changed the parameters like you suggested and the key commands (now I know what "ord" is).
I've also set the character's origin to botton-centre so that It could fit in the middle. As result the character can finally move around the blue grid.
What I find outstanding is that the character automatically reveals additional platforms to jump into, which is exactly what I wanted.

Now I was just reading the next step, which is preventing multiple instances at the same platforms. What do you mean? Does moving the character making invisible instances?
Or do you mean like having more than two characters (for example) in one platform?
 

TheouAegis

Member
He means you make it so the player can't move to the same cell as an enemy, or likewise make it so an enemy can't move to the same cell as another enemy.
 

iKiwed

Member
He means you make it so the player can't move to the same cell as an enemy, or likewise make it so an enemy can't move to the same cell as another enemy.
Oh. Well, I don't know if this might help, but I have two objects for the character and the enemy's platforms, respectively obj_Platform_Blue and obj_Platform_Red.
This means it's impossible for the player's character to move to the enemy's platforms, which is intended.

But ssually in Battle Network you fight more enemies than just one. So this means the enemies cannot move to the same platform, and there should be a "sort of" collision for whoever stands in one of the platforms. So this means I should start making the first enemy already, right?
 

Ratsha

Member
But ssually in Battle Network you fight more enemies than just one. So this means the enemies cannot move to the same platform, and there should be a "sort of" collision for whoever stands in one of the platforms. So this means I should start making the first enemy already, right?
Oh okay. I wasn't familiar with the genre. That would solve the problem.
Yes, creating enemies and prototyping gameplay ASAP is almost always preferred.
 

TheouAegis

Member
In Battle Network you can also change the size of the field. There are actions that make your tiles enemy tiles and vice_versa. There are actions which can place stuff like bombs inside your tiles that you can't move to.
 

iKiwed

Member
In Battle Network you can also change the size of the field. There are actions that make your tiles enemy tiles and vice_versa. There are actions which can place stuff like bombs inside your tiles that you can't move to.
Yep, this is why I think platforms as objecs may be a good start!
I bet there are clearer and better ways to make the game. And I wouldn't be surprised if I'll fail probably in something. But I guess this is also experience.

When I'll have a playable normal battle, I'd like to start making the first two platform variants: One with a hole and the first activable action which turns the enemy's first row of platform into the player's for a short time.

As for now, I think I'll follow Ratsha's suggestion and I'm trying to figure out how to move the enemy.
Since it's the first enemy, I think I could follow Mettaur's actions:
1) He follows the player's vertical direction until he faces the player for a short amount of time (probably less than half second).
2) He prepares a pre-animation and he shoots horizontally.
3) Comes back to follow the player's horizontal direction.

(EDIT: I changed the two grids direction. In Battle Network they're set horizontally, in my game they're set vertically).

In Battle Network, Mettaur's shot comes from the ground, and the platforms lighten up depending on where the shot is.
The first enemy in my game isn't a miner, it can shoot a red, slow plasma bullet which is visible even if the platforms light up.
But let's start with the first step. I need that the enemy follows the player's vertical horizontal direction.
I need to add I think two alarms: One for moving a little slower than the player, and one for the attack.

Update:
I tried to follow the manual and many, many videos about the alarm system, since I used to use the wait for system in another language, but it doesn't work. This is the code I used for the enemy:
Code:
var nextPlatform = noone;

if keyboard_check_released(vk_right)
    {
        nextPlatform = instance_place(x + 64, y, obj_Grid_Red) // width
    }


else if keyboard_check_released(vk_left)
{
    nextPlatform = instance_place(x - 64, y , obj_Grid_Red)   
}

if nextPlatform != noone
{
    x = nextPlatform.x
    y = nextPlatform.y
}
The code is very similar to Ratsha's code, but I removed the vertical movement.
So when the player presses right, the character and the enemy moves to the right at the same time.
My objective is to add a delay. After pressing the button, there should be a delay of about a second, and then automatically move to the platform.
So this means room_speed * 1 in alarm[0]. But I don't get something.
If I set the alarm in the create event and then add an easy code like game_end in the alarm event, the game successfully closes after 1 second.
But if I use the code with ifs and variables in the alarm event, it doesn't work. So this means there should be something to change.
Imo for what I think I learned in these 2 days the code I posted should remain in the step event and then I should set the alarm in an "if expression", but I'm clueless.

I've read some examples where, if you press the space button, the player shoots a bullet and wait an amount of time before to shoot again.
I thought it was simple, so I could just move the alarm expression above the nextPlatform expression. Something like:

Code:
if keyboard_check_released(vk_right)
    {
        alarm[0] = room_speed * 1;
        nextPlatform = instance_place(x + 64, y, obj_Grid_Red) // width
    }
But apparently it's wrong or not enough. What can I do? Sorry again for my ignorance. I read everywhere the alarm system is easy but unfortunately it's getting too much time, and I'm afraid I need to ask your help again.
Many thanks!
 

Ratsha

Member
Alarms are overwritten when set multiple times. For example, if you set alarm[0] = 60, and then 30 frames later do that again, the first occurrence will never happen. That means, if you press Right multiple times, the enemy do not follow you.
As I understand it you want an enemy with a delay and only refresh it's orientation every second. This delay should start only when the player moves. So if the player moves twice immediately, it takes the enemy two seconds to get to him. If the player moves [right, right, left, left] all within a single second, will the enemy only move right once and then detect the player is now left relative to itself? If so, you can have move your nextPlatform into an instance variable, instead of temporary, and check whether it is set, BOTH on right/left click and whenever alarm[0] ends. Alarm[0] repeats itself until it is at the player's horizontal position.
Create Event for obj_enemy:
Code:
nextPlatform = false;
Step Event for obj_enemy:
Code:
if (nextPlatform == noone)
{
    if keyboard_check_released(vk_right)
    {
        nextPlatform = instance_place(x + 64, y, obj_Grid_Red)
    }
    else if keyboard_check_released(vk_left)
    {
        nextPlatform = instance_place(x - 64, y , obj_Grid_Red)   
    }
    if nextPlatform != noone
    {
        alarm[0] = room_speed
    }
}
Alarm[0] for obj_enemy:
Code:
x = nextPlatform.x
y = nextPlatform.y
if (x == obj_player.x)
{
    nextPlatform = noone
}
else
{
    if (x < obj_player.x)
    {
        nextPlatform = instance_place(x + 64, y, obj_Grid_Red)
    }
    else
    {
        nextPlatform = instance_place(x - 64, y , obj_Grid_Red)
    }
    if nextPlatform != noone
    {
        alarm[0] = room_speed
    }
}
There are a bit of duplicate code. Don't worry about that for now.
 
Top