Legacy GM Local Coop Control help

S

Spaghetti Jr.

Guest
Hey there,
I am fairly new and grinding through prototyping different systems.
Right now, I am working on a 2 player local multiplayer game and want to set up so that Player 1 uses set keys from Player 2 on the keyboard to move about. I have the 2 players moving separately but using separate codes. With streamlining in mind; I wanted to get some help from the more experienced members of the community.

I would like to set up a separate Object that contains the Create and Step Events (for movement and collision) for both characters, but assign each player a reference (playerid = 1 or 2) using the Parent option to define what keys they will use. I am having trouble working through the logic and repurposing my code. Are there any resources out there (I've looked extensively)?

Thanks in advance and sorry for being long-winded!
 

Soso

Member
Obj_control

Step event
If obj_player1.playerid = 1 && keyboard_check (ord ("W"))
{Obj_player1.y-= (spd);}

//add down,left,right code same way
For player2 do the same. but change playerid to = 2 and change the key press if this isn't what you meant then post the code you have so far.
 
S

Spaghetti Jr.

Guest
Ok so what I have worked out is a Parent Object that has a step event containing the following code:
Code:
///Player Movement

//var collide = false

if(playerid = 1)
{
//Get the player's input

if (playerid = 1)
key_right = keyboard_check(ord("D"));
key_left = keyboard_check(ord("A"));
key_jump = keyboard_check_pressed(ord("W"));
}

if (playerid = 2)
{
key_right = keyboard_check(vk_numpad6);
key_left = keyboard_check(vk_numpad4);
key_jump = keyboard_check_pressed(vk_numpad8);
}


//Cakculate Movement
var move = key_right - key_left;

hsp = move * rollsp;

vsp = vsp + grav;

//Jumping

if(place_meeting (x,y+1,par_Solid)) && (key_jump)
{
    vsp = -15  
}


//Horizontal collision
if (place_meeting(x+hsp,y,par_Solid))
{
    while(!place_meeting(x+sign(hsp),y,par_Solid))
    {
        x = x + sign(hsp)
    }
    hsp = 0;
}

x = x + hsp;

//Vertical collision
if (place_meeting(x,y+vsp,par_Solid))
{
    while(!place_meeting(x,y+sign(vsp),par_Solid))
    {
        y = y + sign(vsp)
    }
    vsp = 0;
}

y = y + vsp;
and a Create Event that includes these variables:

Code:
///Initialize Player
playerid = 1
playerid = 2

hsp = 0.0;
vsp = 0.0;
rollsp = 8;
grav = 1;
velocity = 0.0;
accel = 0.0;

jumpsp = 10;
jumps = 0;
The characters are moving separately properly with their individual codes. Is this a reasonable way to go about this?

Also, I want to set up Collision between players within the Player Parent Object. Would I use something similar to Horizontal Collision but replace the solid object?
 
Top