Posted: Fri Dec 07, 2012 10:29 am Post subject: Making coding that allows 2 player gaming
What is it you are trying to achieve?
I am creating a game that is playable by 2 players. So, first player uses w,a,s,d to control and second player uses Key.Up,Down,Left,Right.
What is the problem you are having?
I can allow the player to control 1 player but I cannot seem to make the second player appear and let the player control it.
Describe what you have tried to solve this problem
I have searched how to do 2 player stuff but there was no information about it at all...
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
%-----------------------------------Movements--------------------------------- var x, y, a, b :int
x :=100
y :=100
a :=200
b :=200 var char1 :arraycharofboolean var char2 :arraycharofboolean loop Input.KeyDown(char1)
if char2 ("w")then
b := b + 5 endif if char2 ("d")then
a := a + 5 endif if char2 ("s")then
a := a - 5 endif if char2 ("a")then
b := b - 5 endif if char1 ("q")then for i :1.. 10 drawoval(a, b, 4 + i, 4 + i, green) delay(10) endfor endif drawoval(a, b, 4, 4, black) delay(10)
Posted: Sat Dec 08, 2012 1:54 pm Post subject: RE:Making coding that allows 2 player gaming
Will your 2nd loop ever execute?
SAValkyrie
Posted: Sat Dec 08, 2012 1:57 pm Post subject: Re: Making coding that allows 2 player gaming
Ummm actually no. Do I have to put them in a same loop?
Panphobia
Posted: Sat Dec 08, 2012 2:00 pm Post subject: RE:Making coding that allows 2 player gaming
if you want them to execute at the same time, yes you need them in the same loop, because for one to be running the other cant be running, dont put the other loop in the first loop, just put the contents
Insectoid
Posted: Sat Dec 08, 2012 2:00 pm Post subject: RE:Making coding that allows 2 player gaming
Why don't you try it?
Sponsor Sponsor
SAValkyrie
Posted: Sat Dec 08, 2012 2:04 pm Post subject: Re: Making coding that allows 2 player gaming
%-----------------------------------Movements--------------------------------- var x, y, a, b :int
x :=100
y :=100
a :=200
b :=200 var char1,char2 :arraycharofboolean loop Input.KeyDown(char1) Input.KeyDown(char2)
if char1 (KEY_UP_ARROW)and char2 ("w")then
y := y + 5
b := b + 5 endif if char1 (KEY_RIGHT_ARROW)and char2 ("d")then
x := x + 5
a := a - 5 endif if char1 (KEY_LEFT_ARROW)and char2 ("s")then
x := x - 5
b := b - 5 endif if char1 (KEY_DOWN_ARROW)and char2 ("a")then
y := y - 5
b := b - 5 endif
So, This is why I did and there's an error occuring, I am not quite sure what's the problem. It says Array Subscript is out of range?? What does that mean?
Panphobia
Posted: Sat Dec 08, 2012 2:06 pm Post subject: RE:Making coding that allows 2 player gaming
ok dont do that, because that means that it wont be 2 player, make seperate ifs for the as and bs and seperate for x and y because right now, one player can control both
SAValkyrie
Posted: Sat Dec 08, 2012 2:13 pm Post subject: Re: Making coding that allows 2 player gaming
%-----------------------------------Movements--------------------------------- var x, y, a, b :int
x :=100
y :=100
a :=200
b :=200 var char1 :arraycharofboolean var char2 :arraycharofboolean loop Input.KeyDown(char1) Input.KeyDown(char2)
if char1 (KEY_UP_ARROW)then
y := y + 5 endif if char2 ("w")then
b := b + 5 endif if char1 (KEY_RIGHT_ARROW)then
x := x + 5 endif if char2 ("d")then
a := a + 5 endif if char1 (KEY_LEFT_ARROW)then
x := x - 5 endif if char2 ("a")then
b := b - 5 endif if char1 (KEY_DOWN_ARROW)then
y := y - 5 endif if char2 ("s")then
a := a - 5 endif if char1 (KEY_ENTER)then for i :1.. 10 drawoval(x, y, 4 + i, 4 + i, blue) delay(10) endfor if char2 ("q")then for i :1.. 10 drawoval(a, b, 4 + i, 4 + i, green) delay(10) endfor endif endif drawoval(x, y, 4, 4, red) drawoval(a, b, 4, 4, black) delay(10) cls endloop
This is what I did and I inputted both character movements in a same loop. But it keeps saying Array Subscript is out of range..
Panphobia
Posted: Sat Dec 08, 2012 2:17 pm Post subject: RE:Making coding that allows 2 player gaming
when you're setting your screen, this is unrelated but if you have moving objects, put it as offscreenonly, as for me, it flickers if i dont, and also, do you have a view.update? and as for the actual moving of the keys ill look into it on my desktop where i have windows
Panphobia
Posted: Sat Dec 08, 2012 2:25 pm Post subject: RE:Making coding that allows 2 player gaming
ok um, when you are saying chars2("w") do chars2('w'), because it is a char and chars are recognized by single apostrophes and not quotes enjoy
Insectoid
Posted: Sat Dec 08, 2012 3:31 pm Post subject: RE:Making coding that allows 2 player gaming
You don't need char2. You can do it just fine with only char1 and only one Input.KeyDown().
SAValkyrie
Posted: Sat Dec 08, 2012 4:03 pm Post subject: Re: Making coding that allows 2 player gaming
%-----------------------------------Movements--------------------------------- var x, y, a, b :int
x :=100
y :=100
a :=200
b :=200 var char1 :arraycharofboolean loop Input.KeyDown(char1)
if char1 (KEY_UP_ARROW)then
y := y + 5 endif if char1 ('w')then
b := b + 5 endif if char1 (KEY_RIGHT_ARROW)then
x := x + 5 endif if char1 ('d')then
a := a + 5 endif if char1 (KEY_LEFT_ARROW)then
x := x - 5 endif if char1 ('a')then
b := b - 5 endif if char1 (KEY_DOWN_ARROW)then
y := y - 5 endif if char1 ('s')then
a := a - 5 endif if char1 (KEY_ENTER)then for i :1.. 10 drawoval(x, y, 4 + i, 4 + i, blue) delay(10) endfor if char1 ('q')then for i :1.. 10 drawoval(a, b, 4 + i, 4 + i, green) delay(10) endfor endif endif
OH! I did it thank you so much !
So, I only used one input keydown and made it work. However, that cls at the end is a problem. When I put cls, it doesnt show anything