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

Username:   Password: 
 RegisterRegister   
 pong:paddles
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
gilbamy




PostPosted: Thu May 18, 2006 1:22 pm   Post subject: pong:paddles

alright what i need to do is have a program called paddle and i have to have to paddle s move but my first paddle won't move
code:
%Amy Gilbank
%May 15 2006
%paddle.t
%A paddle program
var winMain : int := Window.Open ("graphics :800;600")
var key : string (1)
var y : int
y := 100

loop
        drawfillbox (0, 0, 20, 100, 7)
        getch (key)
        cls
        if key = "S" or key = "s" then
        y := y - 90
    elsif key = "W" or key = "w" then
        y := y + 90
    end if
end loop

Sponsor
Sponsor
Sponsor
sponsor
MysticVegeta




PostPosted: Thu May 18, 2006 1:31 pm   Post subject: (No subject)

Take a look at your drawfilbox, shouldnt it have a coordinate y in there? Also, do not use getch use something else such as Input.KeyDown, look it up in the turing refercne
gilbamy




PostPosted: Thu May 18, 2006 1:34 pm   Post subject: (No subject)

but i have to use getch though oh and here is my new code and i got it to move but it changes sizes and things so i need help
code:

%Amy Gilbank
%May 15 2006
%paddle.t
%A paddle program
var winMain : int := Window.Open ("graphics :800;600")
var key : string (1)
var y ,x,x2,y2: int
y := 0
x:=20

loop
        drawfillbox (x, y, 0, 100, 7)
        getch (key)
        cls
        if key = "S" or key = "s" then
        y := y - 90
    elsif key = "W" or key = "w" then
        y := y + 90
    end if
end loop
TheOneTrueGod




PostPosted: Thu May 18, 2006 2:08 pm   Post subject: (No subject)

First of all, you need to understand what drawfillbox does.

code:
drawfillbox(x1,y1,x2,y2,colour)


drawfillbox will draw a filled in box from the co-ordinate (x1,y1) to the co-ordinate (x2,y2).

If you tell it to draw the box from x,y to 0,100 then obviously its going to do just that. Think about it for a second. Before, you wanted to draw the box from 0,0 to 20,100. If you split that up into X and Y components, then you'll figure out that you want the box to be 20 wide, and 100 tall.

So, if you have the position (x,y), and you want the second co-ordinate to be 20 greater along the x, and 100 greater along the y, what should you do?

(I'll let you try and figure that out. To anyone else who thinks they know the answer, don't post it. He won't learn anything that way.)
Clayton




PostPosted: Thu May 18, 2006 3:18 pm   Post subject: (No subject)

if you are going to use getch use it with hasch as well ex.:

code:

if hasch then
    getch (a)
end if
[/code]
gilbamy




PostPosted: Thu May 18, 2006 7:24 pm   Post subject: (No subject)

i have decided to screw getch and use that input thing
gilbamy




PostPosted: Thu May 18, 2006 7:34 pm   Post subject: (No subject)

never mind my last comment okay well i got the input thing to work but now its just a line when i hit W for up so yeah here is new code aain sorr
code:
%Amy Gilbank
%May 15 2006
%paddle.t
%A paddle program
var winMain : int := Window.Open ("graphics :800;600")
var key : array char of boolean
var y, x, x2, y2 : int
y2 := 1
x := 20

loop
    drawfillbox (x, y2, 0, 100, 7)
    Input.KeyDown (key)
    if key ('S') or key ('s') then
        y2 := y2 - 10
    elsif key ('W') or key ('w') then
        y2 := y2 + 10
    end if
end loop
TheOneTrueGod




PostPosted: Thu May 18, 2006 7:43 pm   Post subject: (No subject)

Turing doesn't erase the screen every iteration of the loop, you have to tell it when to do that. Also, keep in mind that the code you have there iterates every roughly 12 milliseconds, so y2 is decreasing by 10 every 12 milliseconds that you hold the key down. There are three commands you want to use.

Number one, cls
Number two, delay
Number three, View.Update

Visit the Turing Walkthrough to find info on these.
Sponsor
Sponsor
Sponsor
sponsor
gilbamy




PostPosted: Thu May 18, 2006 7:52 pm   Post subject: (No subject)

alright now it won't move at all
code:
%Amy Gilbank
%May 15 2006
%paddle.t
%A paddle program
var winMain : int := Window.Open ("graphics :800;600")
var key : array char of boolean
var y, x, x2, y2 : int
y2 := 1
x := 20

loop
View.Update
    drawfillbox (x, y2, 0, 100, 7)
    delay(100)
    Input.KeyDown (key)
    if key ('S') or key ('s') then
        y2 := y2 - 10
    elsif key ('W') or key ('w') then
        y2 := y2 + 10
    end if
end loop
MysticVegeta




PostPosted: Thu May 18, 2006 8:43 pm   Post subject: (No subject)

Did you pay attention to true gods post? He explaned drawfillbox, as you can clearly see your y starts at 1 and you increment it every 10, and the other y coordinate is 100! so it will draw a box with y1 = 1 and y2 = 100, so you have to press w 10 times for the y1 to go to 100 right? Now, Why is the second y coordinate a constant too? Do you not want the other end of the paddle to move too?! Its not memorizing, its logic, you have to think about it, start with knowing how drawfillbox operates.
gilbamy




PostPosted: Fri May 19, 2006 12:11 pm   Post subject: (No subject)

why must everyone explan eveything so difficultly arg!! i hate pong now oh and why won't oit still move and why won't my second one appear blast this computer stupid school comp can't even install everything okay here is my new code but yeah here
code:

%Amy Gilbank
%May 15 2006
%paddle.t
%A paddle program
var winMain : int := Window.Open ("graphics :800;600")
var key : array char of boolean
var y, x, x2, y2 : int
y2 := 1
x := 20

loop
    drawfillbox (x, y2, 0, 100, 7)
       Input.KeyDown (key)
       if key ('S') or key ('s') then
        y2 := y2 - 2
    elsif key ('W') or key ('w') then
        y2 := y2 + 1
    end if
        end loop
loop
drawfillbox(800,0,780,100,9)
    delay(250)
    cls
    Input.KeyDown(key)
    if  key  ('O') or key ('o') then
    y2:=y2+1
    elsif key ('L') or key ('l') then
    y2:=y2-2
    end if
end loop
gilbamy




PostPosted: Thu May 25, 2006 6:25 pm   Post subject: (No subject)

i need help
MysticVegeta




PostPosted: Thu May 25, 2006 6:36 pm   Post subject: (No subject)

code:
loop
    Input.KeyDown (key)
    if key ('S') or key ('s') then
        y2 := y2 - 1
    elsif key ('W') or key ('w') then
        y2 := y2 + 1
    end if
    cls
    drawfillbox (x, y2, 0, y2 - 80, 7)
    delay (3)
end loop


try to understand this code, and before you say " I need help " why not look at how drawfillbox works in the first place??? Also, to move your second paddle you need to put it in the same loop, not a different one because as you clearly see it wont enter the second loop until it finishes exiting the first one, and it is clear you dont have an exit condition on the first loop.
gilbamy




PostPosted: Fri May 26, 2006 11:08 am   Post subject: (No subject)

well guess what i got my 1st paddle to move but my second one on't appear in the same loop or in a different loop oh why why ! here is my code
code:
%Amy Gilbank
%May 15 2006
%paddle.t
%A paddle program
var winMain : int := Window.Open ("graphics :800;600")
var key, key2 : array char of boolean
var y, y2, y3, y4 : int
y2 := 100
y := 20
y3 := 20
y4 := 100
process pad
    loop
        drawfillbox (20, y, 0, y2, 7)
        delay (3)
        Input.KeyDown (key)
        drawfillbox (20, y, 0, y2, 0)
        if key ('S') or key ('s') then
            y := y - 1
            y2 := y2 - 1
        end if
        if key ('W') or key ('w') then
            y := y + 1
            y2 := y2 + 1
        end if
    end loop
end pad
%2nd pad
process pad2
    loop
        drawfillbox (780, y3, 780, y4, 7)
        delay (3)
        Input.KeyDown (key2)
        drawfillbox (780, y3, 800, y4, 0)
        if key2 (KEY_UP_ARROW)  then
            y3 := y3 + 1
            y4 := y4 + 1
        end if
        if key2 (KEY_DOWN_ARROW)  then
            y3 := y3 - 1
            y4 := y4 - 1
        end if
    end loop
end pad2

fork pad
fork pad2
NikG




PostPosted: Fri May 26, 2006 11:44 am   Post subject: (No subject)

First off, don't use processes. They don't work reliably.

Second, you don't need 2 loops for the movement. You need one main loop, and in that loop you can ask for input for both paddles. Here's some sample code:
code:
Input.KeyDown (key)
if key ('S') or key ('s') then
    Paddle1y := Paddle1y - 1 %can also be written as Paddle1y-=1
elsif key ('W') or key ('w') then
    Paddle1y := Paddle1y + 1 %can also be written as Paddle1y+=1
end if
if key (KEY_UP_ARROW)  then
    Paddle2y += 1
elsif key (KEY_DOWN_ARROW)  then
    Paddle2y -= 1
end if

Hope that helped.
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  [ 26 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: