Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Making coding that allows 2 player gaming
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
SAValkyrie




PostPosted: 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)

Turing:

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
Sponsor
Sponsor
Sponsor
sponsor
AntoxicatedDevil78




PostPosted: Fri Dec 07, 2012 10:44 am   Post subject: RE:Making coding that allows 2 player gaming

You should make have teh second player use the A S D W keys Smile


just try duplicating your coding with player 2 setting
Tony




PostPosted: Fri Dec 07, 2012 12:54 pm   Post subject: 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)?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
SAValkyrie




PostPosted: Sat Dec 08, 2012 1:33 pm   Post subject: 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..

Turing:

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




PostPosted: Sat Dec 08, 2012 1:54 pm   Post subject: RE:Making coding that allows 2 player gaming

Will your 2nd loop ever execute?
SAValkyrie




PostPosted: 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




PostPosted: 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




PostPosted: 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
Sponsor
sponsor
SAValkyrie




PostPosted: Sat Dec 08, 2012 2:04 pm   Post subject: Re: Making coding that allows 2 player gaming

Turing:

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




PostPosted: 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




PostPosted: Sat Dec 08, 2012 2:13 pm   Post subject: Re: Making coding that allows 2 player gaming

Turing:

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




PostPosted: 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 Razz
Panphobia




PostPosted: 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 Smile enjoy
Insectoid




PostPosted: 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




PostPosted: Sat Dec 08, 2012 4:03 pm   Post subject: Re: Making coding that allows 2 player gaming

Turing:

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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 17 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: