Author Topic: Multiplayer key input question  (Read 1705 times)

Offline mrdremel

  • Mc. Print
  • *
  • Posts: 18
    • View Profile
Multiplayer key input question
« on: 2010-Sep-14 »
I am a bit of a n00b when it comes to game coding and using keyboard input. I have some skills, but they were always used for company purposes (writing stuff to search through a lot of files and those kind of things).

I have a game which is a game about shooting a gun by holding a button. The longer you hold the button, the further the gun shoots.

Two players can play this game.

However, right now, when one player pushes the button, the other can't because the program is running some code for that button input.

How can I make it so that both players can use the controls at the same time?

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1600
    • View Profile
    • AMpostata Website
Re: Multiplayer key input question
« Reply #1 on: 2010-Sep-14 »
Code: (glbasic) [Select]
repeat

if key(one)=1 then inc player1pressed
if key(two)=1 then inc player2pressed

if key(one)=0 and player1pressed>0 then gosub fire1
if key(two)=0 and player2pressed>0 then gosub fire2

until oneisdead=true

More or less.
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10752
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Multiplayer key input question
« Reply #2 on: 2010-Sep-14 »
Warning - some keyboards (read: about 99%) cannot give you all keys simultanously - I think you can't detect more than 5 keys pressed at once. Test it with the Tools/Keycodes program in the editor.

Offline mrdremel

  • Mc. Print
  • *
  • Posts: 18
    • View Profile
Re: Multiplayer key input question
« Reply #3 on: 2010-Sep-14 »
Warning - some keyboards (read: about 99%) cannot give you all keys simultanously - I think you can't detect more than 5 keys pressed at once. Test it with the Tools/Keycodes program in the editor.

Shouldn't be a problem, as i am only assigning each player 1 or 2 buttons.

Thanks for the tips. Will give it a try.

Offline mrdremel

  • Mc. Print
  • *
  • Posts: 18
    • View Profile
Re: Multiplayer key input question
« Reply #4 on: 2010-Sep-14 »
Warning - some keyboards (read: about 99%) cannot give you all keys simultanously - I think you can't detect more than 5 keys pressed at once. Test it with the Tools/Keycodes program in the editor.

Shouldn't be a problem, as i am only assigning each player 1 or 2 buttons.

Thanks for the tips. Will give it a try.

OK, that works.....both keys can be pressed at the same time. Now I created 2 subs (fire1 and fire2, for both players).

The subs look like this:

FOR arc=90 TO 270 STEP 2
   gun2y = (30*speed2)*COS (arc) + 380
   DRAWSPRITE 0,gun2x,gun2y
   gun2x = gun2x + speed2
   SHOWSCREEN
NEXT

These are so that the guns fire a bomb which describe an arc over the screen. But when one is in the air, the other isn't. Now I need to somehow let both be fired at the same time as well.

Any thoughts for this n00b?
« Last Edit: 2010-Sep-14 by mrdremel »

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1600
    • View Profile
    • AMpostata Website
Re: Multiplayer key input question
« Reply #5 on: 2010-Sep-14 »
In the mainloop insert something like

Code: (glbasic) [Select]
if gunfired=1
   arc=90
   firestate=1
   gunfired=0
endif

if firestate=1
   gosub paintgun
   inc arc,2
endif

if arc=272
   firestate=0
endif

I want royalyties  :whistle:
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline mrdremel

  • Mc. Print
  • *
  • Posts: 18
    • View Profile
Re: Multiplayer key input question
« Reply #6 on: 2010-Sep-14 »
In the mainloop insert something like

Code: (glbasic) [Select]
if gunfired=1
   arc=90
   firestate=1
   gunfired=0
endif

if firestate=1
   gosub paintgun
   inc arc,2
endif

if arc=272
   firestate=0
endif

I want royalyties  :whistle:

hmmm.....50% royalties over a $ 0,00 game equals.....whoops....still nothing  :rtfm:  :whistle:


i'll give it a go....thanks!