Author Topic: I Have a Question About Two Players  (Read 5930 times)

GameDeveloper

  • Guest
I Have a Question About Two Players
« on: 2005-11-25, 11:39:11 AM »
I have a question about the two player script [the one that enables 2 players].  I just recently got a couple of Xbox 360 controllers, and I've decided to use them for computer games.  I was wondering, can you use them [two joysticks] with the two player script?  I know the 360 controllers work with the one player games, but for the two player games?  I hope I can use two controllers for my two player games, because after two keys are pressed, the computer makes a beep and locks the controls.  Besides, it's pretty tiresome with two at a keyboard.  So, can it work?  If not, then can it be done by adding to the script? :?:

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
I Have a Question About Two Players
« Reply #1 on: 2005-11-25, 12:17:23 PM »
ok, wait, back up a sec. you have an xbox 360, and you want to take the controller and use it for a custon made 2 player 2d game, (no offense bluemonk), on the computer? second, does the controller even have the ability to connect to the computer?
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

GameDeveloper

  • Guest
I Have a Question About Two Players
« Reply #2 on: 2005-11-25, 01:01:21 PM »
Yeah, I know it sounds crazy but I'd like to let the Xbox 360 rest a bit so it doesn't over heat ;) .  Besides, I just had a good idea about a 2 player game. Also, yes it can connect to the computer, if it is wired [the controller has to be a wired one].  It can fit into a USB port on the PC [which is cool].  I just wanted to know, I'm trying to keep up with my game creating and my game playing.  Still, I've played the 360 non-stop and I need a break.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
I Have a Question About Two Players
« Reply #3 on: 2005-11-25, 07:24:57 PM »
Well, as joysticks in general go, you can really only use one for SGDK.  It's a standard input device.  However, you could have player 1 using the joystick and player 2 using the keyboard (many older 2d games do this).  In fact, I don't know of any computer games that use 2 joysticks... but maybe that's just because I only have one joystick :P

In any case, if you wanted to use two joysticks with SGDK, you would probably have to do it using Visual Basic and connecting through COM to GDPlay.exe to play your game.  And the script would certainly have to be modified since it checks directly for key presses on the keyboard, not "controller presses".
Edward Dassmesser

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
I Have a Question About Two Players
« Reply #4 on: 2005-11-26, 07:25:36 AM »
Actually it should be quite simple to use the second joystick for player 2 in GameDev if you are using scripting.  Just call
Code: [Select]
ProjectObj.GamePlayer.PollJoystick(1)
during OnBeforeMoveSprites or OnAfterMoveSprites, and then you can use ProjectObj.GamePlayer.JoyX and ProjectObj.GamePlayer.JoyY to get the position of the joystick.  You can use the JoyButton1-JoyButton4 properties to get the state of the buttons.  If you are using the default player object (rather than creating an extra copy) you will no longer be able to access the controller state for player 1, though.  If you need help creating an extra player object to track separate states of the two players so you can freely check each player's controller at any time, I could probably help with that.

If you want the joystick to also set the state of the JoyActions property and raise events, you can call ProjectObj.GamePlayer.JoyMove after calling PollJoystick.  Again, if you are using the default player object, though, you might have trouble separating player 1 events from player 2 events.  If you had separate player objects, you could have separate events for each player, though.  (One of these days I'll have to show people how to implement multiple players properly.)

GameDeveloper

  • Guest
Re: I Have a Question About Two Players
« Reply #5 on: 2005-11-26, 11:38:03 AM »
I was wondering, seeing as how I never script for my games and I only recently downloaded the 2 player script, could you possibly help me with this?  I'm quite ignorant when it comes to using the scripted side of this development kit.  If it's not asking to much, do you think you could just 'modify' the existing script?  I'm serious when I say I have no idea where to begin. :(

If not, then I will just use the joystick and keyboard combination Durnurd suggested.

Thank you either way.

Ed

  • Guest
Re: I Have a Question About Two Players
« Reply #6 on: 2005-11-27, 10:28:00 PM »
Well, yes, that's one way to do it........if you want to do it the easy way :-[

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: I Have a Question About Two Players
« Reply #7 on: 2005-11-28, 10:30:11 AM »
If I can find time (and remember) I will try to help out with some more specific sample script... unless Ed/Durnurd wants to jump in.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: I Have a Question About Two Players
« Reply #8 on: 2005-11-29, 09:36:59 PM »
OK, I have made some significant improvements to the 2-Player demo.  You can get it from http://gamedevprj.sf.net/files/.  The filename is GD2Player.zip.  New features include:
  • More effecient code for handling second player (no need to manually handle keypresses using the display)
  • Ability to use both joysticks and two sets of keyboard controls to control the players.  (Each player can use keyboard or joystick)
  • Ability for each player to have their own inventory drawn on their own side of the map
  • Ability for each player to interact with the map by activating special functions and affecting tiles

The one thing I was going to do that I didn't have time to finish working on was support switching maps.  Right now you will get an error when you try to go through the door that leads to the other map.  Unfortunately I don't have time to finish that work right now, but hopefully what is here is helpful.

One cool thing about this exercise.  I realized that My Logitech driving force wheel that I got for my PS2 is supported as a joystick (game controller) under Windows.  I could make a GameDev game that uses a steering wheel!  The reason I bothered to figure that out was because I don't have two joysticks that I can plug into my computer, so I had to use this other device to pretend I had another joystick, and it worked!

GameDeveloper

  • Guest
Re: I Have a Question About Two Players
« Reply #9 on: 2005-11-29, 09:51:07 PM »
Excellent!  Thank you so much, this will help tremendously! :D  I like the additions!  My favorite has to be that the 2nd player can now activate functions!  That takes away the limitations.  Strange that the wheel works as a joystick [it's nice though].  Well, thank you for helping me [and others].  I'm off to try out the script right now!

P.S. Thank you! :)

GameDeveloper

  • Guest
Re: I Have a Question About Two Players
« Reply #10 on: 2005-11-29, 10:02:12 PM »
-Also, I can finally create a 2-player side-scrolling game!  With the new properties set to the second player, it finally jumps like the first player.  Wow, that's going to add alot.  I already have a lot of great ideas!  Thanks agian! ;D