
-----------------------------------
SAValkyrie
Fri Dec 07, 2012 10:29 am

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)


setscreen ("screen:max;max")

%-----------------------------------Movements---------------------------------
var x, y : int
x := 100
y := 100
var char1 : array char of boolean

loop
    Input.KeyDown (char1)

    if char1 (KEY_UP_ARROW) then
        y := y + 5
    end if
    if char1 (KEY_RIGHT_ARROW) then
        x := x + 5
    end if
    if char1 (KEY_LEFT_ARROW) then
        x := x - 5
    end if
    if char1 (KEY_DOWN_ARROW) then
        y := y - 5
    end if
    if char1 (KEY_ENTER) then
        for i : 1 .. 10
            drawoval (x, y, 4 + i, 4 + i, blue)
            delay (10)
        end for
    end if

    drawoval (x, y, 4, 4, red)
    delay (10)
    cls

end loop



Please specify what version of Turing you are using
4.1.1

-----------------------------------
AntoxicatedDevil78
Fri Dec 07, 2012 10:44 am

RE:Making coding that allows 2 player gaming
-----------------------------------
You should make have teh second player use the A S D W keys :)


just try duplicating your coding with player 2 setting

-----------------------------------
Tony
Fri Dec 07, 2012 12:54 pm

RE:Making coding that allows 2 player gaming
-----------------------------------
where's your code for the other player?

Hint: would your code be any different if it was a single person controlling both players (playing against themselves)?

-----------------------------------
SAValkyrie
Sat Dec 08, 2012 1:33 pm

Re: Making coding that allows 2 player gaming
-----------------------------------
So, I followed you guys advice and i added the second player by just copying the code and changing the variables..


setscreen ("screen:max;max")

%-----------------------------------Movements---------------------------------
var x, y, a, b : int
x := 100
y := 100
a := 200
b := 200
var char1 : array char of boolean
var char2 : array char of boolean
loop
    Input.KeyDown (char1)

    if char1 (KEY_UP_ARROW) then
        y := y + 5
    end if
    if char1 (KEY_RIGHT_ARROW) then
        x := x + 5
    end if
    if char1 (KEY_LEFT_ARROW) then
        x := x - 5
    end if
    if char1 (KEY_DOWN_ARROW) then
        y := y - 5
    end if
    if char1 (KEY_ENTER) then
        for i : 1 .. 10
            drawoval (x, y, 4 + i, 4 + i, blue)
            delay (10)

        end for
    end if
    drawoval (x, y, 4, 4, red)
    delay (10)
    cls
end loop
loop
    Input.KeyDown (char2)

    if char2 ("w") then
        b := b + 5
    end if
    if char2 ("d") then
        a := a + 5
    end if
    if char2 ("s") then
        a := a - 5
    end if
    if char2 ("a") then
        b := b - 5
    end if
    if char1 ("q") then
        for i : 1 .. 10
            drawoval (a, b, 4 + i, 4 + i, green)
            delay (10)
        end for
    end if
    drawoval (a, b, 4, 4, black)
    delay (10)

    cls
end loop







but it doesnt work D:

-----------------------------------
Insectoid
Sat Dec 08, 2012 1:54 pm

RE:Making coding that allows 2 player gaming
-----------------------------------
Will your 2nd loop ever execute?

-----------------------------------
SAValkyrie
Sat Dec 08, 2012 1:57 pm

Re: Making coding that allows 2 player gaming
-----------------------------------
Ummm actually no. Do I have to put them in a same loop?

-----------------------------------
Panphobia
Sat Dec 08, 2012 2:00 pm

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
Sat Dec 08, 2012 2:00 pm

RE:Making coding that allows 2 player gaming
-----------------------------------
Why don't you try it?

-----------------------------------
SAValkyrie
Sat Dec 08, 2012 2:04 pm

Re: Making coding that allows 2 player gaming
-----------------------------------

setscreen ("screen:max;max")

%-----------------------------------Movements---------------------------------
var x, y, a, b : int
x := 100
y := 100
a := 200
b := 200
var char1,char2 : array char of boolean
loop
    Input.KeyDown (char1)
    Input.KeyDown (char2)

    if char1 (KEY_UP_ARROW) and char2 ("w") then
        y := y + 5
        b := b + 5
    end if
    if char1 (KEY_RIGHT_ARROW) and char2 ("d") then
        x := x + 5
        a := a - 5
    end if
    if char1 (KEY_LEFT_ARROW) and char2 ("s") then
        x := x - 5
        b := b - 5
    end if
    if char1 (KEY_DOWN_ARROW)and char2 ("a") then
        y := y - 5
        b := b - 5
    end if

    drawoval (x, y, 4, 4, red)
    drawoval (a, b, 4, 4, black)
    delay (10)
    cls
end loop


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
Sat Dec 08, 2012 2:06 pm

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
Sat Dec 08, 2012 2:13 pm

Re: Making coding that allows 2 player gaming
-----------------------------------

setscreen ("screen:max;max")

%-----------------------------------Movements---------------------------------
var x, y, a, b : int
x := 100
y := 100
a := 200
b := 200
var char1 : array char of boolean
var char2 : array char of boolean
loop
    Input.KeyDown (char1)
    Input.KeyDown (char2)

    if char1 (KEY_UP_ARROW) then
        y := y + 5
    end if
    if char2 ("w") then
        b := b + 5
    end if
    if char1 (KEY_RIGHT_ARROW) then
        x := x + 5
    end if
    if char2 ("d") then
        a := a + 5
    end if
    if char1 (KEY_LEFT_ARROW) then
        x := x - 5
    end if
    if char2 ("a") then
        b := b - 5
    end if
    if char1 (KEY_DOWN_ARROW) then
        y := y - 5
    end if
    if char2 ("s") then
        a := a - 5
    end if
    if char1 (KEY_ENTER) then
        for i : 1 .. 10
            drawoval (x, y, 4 + i, 4 + i, blue)
            delay (10)
        end for
    if char2 ("q") then
        for i : 1 .. 10
            drawoval (a, b, 4 + i, 4 + i, green)
            delay (10)
        end for
    end if
    end if
    drawoval (x, y, 4, 4, red)
    drawoval (a, b, 4, 4, black)
    delay (10)
    cls
end loop


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
Sat Dec 08, 2012 2:17 pm

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 :P

-----------------------------------
Panphobia
Sat Dec 08, 2012 2:25 pm

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
Sat Dec 08, 2012 3:31 pm

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
Sat Dec 08, 2012 4:03 pm

Re: Making coding that allows 2 player gaming
-----------------------------------

setscreen ("screen:max;max,offscreenonly") 

%-----------------------------------Movements--------------------------------- 
var x, y, a, b : int 
x := 100 
y := 100 
a := 200 
b := 200 
var char1 : array char of boolean 
loop 
    Input.KeyDown (char1) 

    if char1 (KEY_UP_ARROW) then 
        y := y + 5 
    end if 
    if char1 ('w') then 
        b := b + 5 
    end if 
    if char1 (KEY_RIGHT_ARROW) then 
        x := x + 5 
    end if 
    if char1 ('d') then 
        a := a + 5 
    end if 
    if char1 (KEY_LEFT_ARROW) then 
        x := x - 5 
    end if 
    if char1 ('a') then 
        b := b - 5 
    end if 
    if char1 (KEY_DOWN_ARROW) then 
        y := y - 5 
    end if 
    if char1 ('s') then 
        a := a - 5 
    end if 
    if char1 (KEY_ENTER) then 
        for i : 1 .. 10 
            drawoval (x, y, 4 + i, 4 + i, blue) 
            delay (10) 
        end for 
    if char1 ('q') then 
        for i : 1 .. 10 
            drawoval (a, b, 4 + i, 4 + i, green) 
            delay (10) 
        end for 
    end if 
    end if 

    drawoval (x, y, 4, 4, red) 
    drawoval (a, b, 4, 4, black) 
    delay (10) 
    View.Update
    cls
end loop 



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

-----------------------------------
Panphobia
Sat Dec 08, 2012 4:07 pm

RE:Making coding that allows 2 player gaming
-----------------------------------
put it at the beginning

-----------------------------------
Tony
Sat Dec 08, 2012 5:12 pm

RE:Making coding that allows 2 player gaming
-----------------------------------
consider the order that drawing of things happen

drawoval (x, y, 4, 4, red) 
    drawoval (a, b, 4, 4, black) 
    delay (10) 
    View.Update 
    cls 


- draw items to buffer, not displaying anything yet
- wait for a bit (this is essentially lag, as you'll be displaying the frame even later than it was ready)
- update the screen
- erase everything right away
