Legacy GM Longshot, but could help

S

Sabotage

Guest
Hello!

First thing, I am an artist! That means I have very rudimentary knowledge of coding and almost no patience for it. I have been cobbling together a game idea I have and even though it took me far longer than it should have, I finally have a working prototype of all the main mechanics in GameMaker.

Kind of an opposite position to most here, right? I'll have beautiful art but my code will leave something to be desired :p

My problem is that I want to scale this in an intelligent way, and I'm not familiar enough with code or gamemaker to easily do what I want to do.

Basically all I need is Local Multiplayer capability that supports KB/M and gamepad. If I'm dreaming, then one day that could be online multiplayer. The players would be using the same object (like, same player character, same abilities and whatnot.) I'm still trying to figure how instance.id really works so that his own projectile doesn't collide with him but does collide with another player as well.

My issue is that I started coding with a collision and movement template that I really like, and both of those are totally beyond me coding-wise, but I don't fully understand how to mesh it with something like Inputdog. I actually did get it working after a fashion but inputdog's movement is terrible and collision non-existent. I don't know how to replace it with what I have.

I don't suppose anyone has a basic template with multiple players and full input, top down movement and collision, already set up which I could just add my own developed mechanics to?
At this point my game is so simple that all I need to do is populate the player with a few scripts, add in my own objects and mechanics, and be done. The main thing is good collision and movement because without it, this particular game would suck.

Otherwise, maybe someone can try to help me understand (or point me in the right direction, though I've viewed and read a dozen or more tutorials) in a very rudimentary way how to add controller and multiple players using the same object to my already implemented movement and collision code in a way that can be scaled to several players and ideally online.

I've been reading that it should be in a script, and that I should call the script in the player but I don't understand which parts are in the create, which step, which belong in the script etc. I can read the individual code but don't know how all the pieces fit together.

Sorry, I am an artist and while I can tell you what color the shadow of a green object should be under a red light and give you a physician's level run-down of the human body and how the muscles move, I couldn't tell you any of the above.
 
By multiplayer, do you mean at the same computer or online? Because online is difficult tedious work and I doubt that you'd be able to get yourself to that point, given your description of yourself (no offense intended) and there's no 'templates' for online multiplayer. In addition, online play HAS to be built in from the very beginning, it's pointless and an incredible amount of work (literally rewriting the whole thing from scratch) to try to 'convert' a game from no online to online. If you mean local multiplayer, using perhaps a combination of KB+M and gamepads, then that will probably be within your reach, but will still be difficult. Can you show us some of the code you have (btw, things being in scripts or not in scripts is not something you need to worry about, scripts function in basically the same way as code that is not within a script, so don't get hung up on that part).

Oh, I just noticed you mentioned online. That's above the level of code you talk about with yourself. It's not really something that people get going until they get into the very advanced (for the average GM user) area of expertise.
 
H

Homunculus

Guest
Looks to me you are merging two different problems into one. While the controller has obviously SOMETHING to do with movement and by extension collisions, how you handle two different input devices and how your objects interact with the game world are essentially different things.
If you try to solve two problems at once you'll probably get burned.

Forget about multiple inputs for a moment, and try to program your collision system with one of the two input methods. That's something we can't simply program for you, every game is unique in how it handles collisions, there's no silver bullet.

Once you got this working, start thinking about using two different input methods, and having multiple instances of the same object. Split your problems into smaller chunks, and eventually ask here when you are facing specific problems down the road.
 
S

Sabotage

Guest
Thanks, yeah online will definitely be too much for me if it's not as simple as 'add gme to project'.
I'd be plenty happy making this work for couch-coop. The game itself is not a complicated one and has very little code at the moment.

I have collision and movement with WASD and Arrow keys setup already. That part works great. However the movement is in the player object. My collision is set up in scripts and a parent object, from what I know that won't be a problem.

I used the Top - Down shooter engine code from the marketplace, since this kind of thing is beyond me. So this code is freely available. That's a lot of the reason why I can't figure out how to manipulate it into making it work for multiple different players using the same player object.

script: approach
Code:
/// approach(start, end, shift);

if (argument0 < argument1)
    return min(argument0 + argument2, argument1);
else
    return max(argument0 - argument2, argument1);
scipt: collision
Code:
/// collision()

// Horizontal Collisions
repeat(abs(vx)) {
if(!place_meeting(x+sign(vx),y,p_solid)) {
    x += sign(vx);
}
else {
    vx = 0;
    }
   }
// Vertical Collisions
repeat(abs(vy)) {
if(!place_meeting(x,y+sign(vy),p_solid)) {
    y += sign(vy);
}
else {
    vy = 0;
    }
    }
in o_player CREATE
Code:
/// Player Variables
//Inherit Variables
event_inherited();


// Movement
vxMax = 3;
vyMax = 3;
accel = 0.75;
fric = 2;

// States (Sprites? not sure yet)
IDLE = 10;
RUN = 11;
ATTACK = 12;
DEFEND = 13;
KNOCKBACK = 4;

// Initialize Properties (not sure how used yet)
state = IDLE
attackRate = 10;
dir = 0;
facing = image_xscale;
(In o_player STEP)
Code:
(In o_player STEP)
///Movement


//get keypress
var pressed_up = keyboard_check(key_up) || keyboard_check(key_up_alt)
var pressed_down = keyboard_check(key_down) || keyboard_check(key_down_alt)
var pressed_left = keyboard_check(key_left) || keyboard_check(key_left_alt)
var pressed_right = keyboard_check(key_right) || keyboard_check(key_right_alt)

// Movement
//Left
if(pressed_left && !pressed_right)
{
    facing = -1;
    state = RUN;
    if (vx > 0) {
        vx = approach(vx,0,fric);
    }
    vx = approach(vx,-vxMax,accel);
    if(!pressed_up && !pressed_down) {
        if (vy != 0) {
            vy = approach(vy,0,fric);
        }
    }
    
    dir = 2;
}

//Right
if(pressed_right && !pressed_left)
{
    facing = 1;
    state = RUN;
    if (vx < 0) {
        vx = approach(vx,0,fric);
    }
    vx = approach(vx,vxMax,accel);
    if(!pressed_up && !pressed_down) {
        if (vy != 0) {
            vy = approach(vy,0,fric);
        }
    }
    
    dir = 2;
}

//Up
if(pressed_up && !pressed_down)
{
    state = RUN;
    if (vy > 0) {
        vy = approach(vy,0,fric);
    }
    vy = approach(vy,-vyMax,accel);
    
    if(!pressed_left && !pressed_right) {
        if (vx != 0) {
            vx = approach(vx,0,fric);
        }
    }
    if((vy*vx) == 0) {
        dir = 1;
        } else {
        dir = 2;
        }
}

//Down
if(pressed_down && !pressed_up)
{
    state = RUN;
    if (vy < 0) {
        vy = approach(vy,0,fric);
    }
    vy = approach(vy,vyMax,accel);
    
    if(!pressed_left && !pressed_right) {
        if (vx != 0) {
            vx = approach(vx,0,fric);
        }
    }
    if((vy*vx) == 0) {
        dir = 0;
        } else {
        dir = 2;
        }
}

//Friction
if(!pressed_left && !pressed_right && !pressed_up && !pressed_down)
{
    state = IDLE;
    vx = approach(vx,0,fric);
    vy = approach(vy,0,fric);
}

This is I think all code related to movement and where it can be found.
scripts: approach
o_player (key bindings, movement code)

collisions seem to be all handled through script and the parent object, so I don't anticipate any trouble there?

I'm probably making this more complicated than it needs to be by not understanding how to phrase this stuff. Basically I have the movement code, I have the collision code, and I just need to understand or figure out how to get multiple players locally working in the game, with gamepads as well. I've seen and read gamepad setup but I wanted to know where to put everything before I added that in. My plan is for twin-stick shooting.

I thank anyone who takes the time!
 
T

Taddio

Guest
My current project is a 2 players local game that plays with controllers. My heads up to you, is plan carefully in advance your controller scheme (and your game dev in general).
Now that I know what I want, it's easier, but in my prototype, I had SO MUCH useless stuff (twice the objects, for the most part) because 1) it's easy to get carried away, and 2) lack of initial planning.
Just sketching on paper your states, macros, main function uses, option tree, GUI layout, etc. will save you days of work, make it look better and give you time to focus on the cool and important things.
But even if carefully planned, a 2 player game is no light undertaking, if it's to be fun, balanced and replayable.
For your question as to differiencate players, I have a macro PLAYER_1 and a macro PLAYER_2, and use if and state switch to change behaviors.

if(parent_player == PLAYER_1) {//Do stuff;}
 
Last edited by a moderator:
Top