Adding 2 Players to a Game

Game Editor comments and discussion.

Adding 2 Players to a Game

Postby Zivouhr » Sat Nov 12, 2016 7:11 pm

Just wondering if there's a simple way to add 2 players to a game where both players are onscreen at the same time and control separately? The search for "2 player game" only brings up threads with the word "player" for the most part.
I'm guessing no easy way, but I did read something that had some kind of reference to the first player, then was able to use that reference to save time creating the 2nd player, but can't seem to find where it was 2 years ago when I saw it in the forum.

I have a 1 player game, but the 1 player has a ton of interconnections to the many enemies, objects and moves that trying to duplicate that code by code wouldn't be practical. I wish we could just create a clone of player 1 and then assign it different controls, so all of those links remain intact.
I'll have to think if that's possible using struct / state coding.

I would clone the actor, then for cloneindex.0 and .1, assign them different controls if that's possible. :idea:
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Adding 2 Players to a Game

Postby Epsilon » Mon Jun 26, 2017 5:17 am

Hello GE Users.
This topic is a bit old but, i was interested in this problem.

SO I am assuming that the two (or multiple) players are the same base actor (clones), not saying that you can't have different clones with different
behavior and animations, but what's the point of them being clones then?

now let's say as in my demo below that the player have those controls :
    Left Key - to move left
    Right Key - to move right
    space Key - to jump
    return Key - to attack

so instead of using fixed key down / up events with the same key, you need to have 4 int Actor variables keys representing the controls for that particular
clone and then using an abstract KeyDown with "any key" and checking the the keyboard state in a draw actor event with the function char * getKeyState()
and storing it in a global keyboard variable.

Code: Select all
// an example of Key Down "any key" event
if(keyboard[ attackKey ] == 2 && state != attack)     // Attack key is pressed
{
    Attack(clonename);
}

if(keyboard[ jumpKey ] == 2)                               // Jump key is pressed
{
    if(canJump == 1)
    Jump(clonename);
}


Note : Assigning the keys in the first place should not be done in the players->Create Actor event , because then ALL the clones will have the same keys
instead you should use another actor called ClonesManager to do so..

ClonesManager -> Create Actor
Code: Select all
// Assign keys for the first clone
// Note: you can find the all keys enumeration in GE Scripting Refference

getclone("player.0")->rightKey = KEY_d;
getclone("player.0")->leftKey = KEY_a;
getclone("player.0")->jumpKey = KEY_w;
getclone("player.0")->attackKey = KEY_SPACE;

// now say that we have another clone in the editor
// we just kive it different keys here, like so:

  // getclone("player.1")->rightKey = KEY_RIGHT;
  // getclone("player.1")->leftKey = KEY_LEFT;
  // getclone("player.1")->jumpKey = KEY_UP;
  // getclone("player.1")->attackKey = KEY_RETURN;
Attachments
Clone players with different controls.zip
a simple platformer, you can create clones and set their controls in-game
(1.07 MiB) Downloaded 184 times
User avatar
Epsilon
 
Posts: 11
Joined: Fri Jun 23, 2017 5:15 pm
Location: 418
Score: 0 Give a positive score

Re: Adding 2 Players to a Game

Postby schnellboot » Mon Jun 26, 2017 3:28 pm

Welcome to the forum... I guess?
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

Re: Adding 2 Players to a Game

Postby MrJolteon » Mon Jun 26, 2017 4:01 pm

schnellboot wrote:Welcome to the forum... I guess?

As long as he's helpful, I guess.
Join us on Discord!
Game Editor 2
These are the best ways to reach me these days


Your local Community Janitor, always lurking in the shadows...
User avatar
MrJolteon
 
Posts: 2326
Joined: Sat Aug 09, 2008 3:25 pm
Location: Stranded under endless sky
Score: 105 Give a positive score

Re: Adding 2 Players to a Game

Postby Epsilon » Tue Jun 27, 2017 10:34 am

MrJolteon wrote:
schnellboot wrote:Welcome to the forum... I guess?

As long as he's helpful, I guess.


Yeah sure.. I have used GE for the first time in 2015 upon entering Computer Science college.
So I have been programming a lot (Data Structures, Simulations, AI), and with C++ being my favorite language
I didn't have much trouble with GE's C. I GUESS :lol: you could say I am already past the basics.

Though I joined since I have a big game project that i would like to create and share here, some AI demo idea's and may be help other members as well :)

oK then i have a question : why are there so many downloads to the demo in just one day, when the forum itself is so inactive ? :?
Doesn't that mean a lot of people are using this program already?
User avatar
Epsilon
 
Posts: 11
Joined: Fri Jun 23, 2017 5:15 pm
Location: 418
Score: 0 Give a positive score

Re: Adding 2 Players to a Game

Postby schnellboot » Tue Jun 27, 2017 4:03 pm

someone could have spammed the download button
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

Re: Adding 2 Players to a Game

Postby lcl » Wed Jun 28, 2017 3:38 pm

schnellboot wrote:someone could have spammed the download button

Possible, but I don't think that's the case. :P

Welcome to the forum, Epsilon! Hope you have a good time here! :)

A big game project? That sounds interesting, can't wait to hear (and see) more about it!

Also, your answer to the two players question seems valid, I think it's visible that you have used GE for some time already. I'll check the demo a little later.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron