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?
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.
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.
Quote from: Kitty Hello 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.
Quote from: mrdremel on 2010-Sep-14
Quote from: Kitty Hello 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?
In the mainloop insert something like
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:
Quote from: ampos on 2010-Sep-14
In the mainloop insert something like
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!