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

Username:   Password: 
 RegisterRegister   
 Turing Pong Project
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Salman




PostPosted: Thu Jan 17, 2013 1:41 pm   Post subject: Turing Pong Project

What is it you are trying to achieve?
I'm trying to make the ball hit the paddles

Describe what you have tried to solve this problem
I'm confused with how to make it hit the paddles

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


import GUI
var x2 := maxx div 2
var y2 := maxy div 2
const radius := 10
var speedx : int := -1
var speedy : int := 1
var font : int
var font2 : int
var movement1 : int := 0
var movement2 : int := 0
var keys : array char of boolean
var x := 175
var y := 0
colorback (black)
for i : 1 .. 25 %Counted loop makes the background stay black
    for j : 1 .. 80
        put " " ..
    end for
end for
setscreen ("nocursor,offscreenonly")
font := Font.New ("Arial Black:18")
font2 := Font.New ("Arial Black:12")
Font.Draw ("Pong", 280, 320, font, red)

procedure startGame
    cls
 
    Draw.FillBox (0, 600, maxx, 360, brightred)
    Draw.FillBox (0, 00, maxx, 45, brightred)
    Draw.FillBox (0, 175 + movement1, 10, 225 + movement1, brightred)
    Draw.FillBox (630, x + movement2, maxx, 225 + movement2, brightred)
    Font.Draw ("Player 1 Score", 5, 385, font2, blue)
    Font.Draw ("Player 2 Score", 500, 385, font2, blue)
    Input.KeyDown (keys)
    if keys ('w') then
        Draw.FillBox (0, 175 + movement1, 10, 225 + movement1, brightred)
        if movement1 <= 360 - 175 - 50 then
            movement1 := movement1 + 2
        end if
    end if

    if keys ('s') then
        Draw.FillBox (0, 175 + movement1, 10, 225 + movement1, brightred)
        if movement1 >= 45 - 175 then
            movement1 := movement1 - 2
        end if
    end if

    if keys (KEY_UP_ARROW) then
        Draw.FillBox (630, 175 + movement2, maxx, 225 + movement2, brightred)
        if movement2 <= 360 - 175 - 50 then
            movement2 := movement2 + 2
        end if
    end if

    if keys (KEY_DOWN_ARROW) then
        Draw.FillBox (630, 175 + movement2, maxx, 225 + movement2, brightred)
        if movement2 >= 45 - 175 then
            movement2 := movement2 - 2
        end if
    end if

    Draw.FillOval (x2, y2, radius, radius, brightblue)
    x2 := x2 + speedx
    y2:=y2+speedy
    if y2 + speedy + radius > 360 or y2 + speedy - radius < 45 then
        speedy := speedy * -1
    end if
    if x2 + speedx + radius<20 and y2+speedy+radius<maxy-225  or  x2 + speedx - radius > 620 then
        speedx := speedx * -1
end if

end startGame
var startButton : int := GUI.CreateButton (maxx div 2 - 30, 60, 60, "Start Game", startGame)



procedure helpGame
    cls
    Font.Draw ("Refer to the instruction manual", 100, 320, font, red)
end helpGame
var helpButtom : int := GUI.CreateButton (maxx div 2 - 200, 60, 60, "Help", helpGame)

loop
    startGame
    View.Update
    exit when GUI.ProcessEvent
end loop



Please specify what version of Turing you are using
<Answer Here>
Sponsor
Sponsor
Sponsor
sponsor
Pyralblitzzz




PostPosted: Thu Jan 17, 2013 2:02 pm   Post subject: RE:Turing Pong Project

Try The Turing Walkthrough's tutorial on collision detection. If you don't get that, here's a hint; The x position of the paddles never changes.
Panphobia




PostPosted: Thu Jan 17, 2013 5:27 pm   Post subject: RE:Turing Pong Project

Since X is static, that means the Y is the only thing that changes, and if it changes it uses a "variable", its a simple if statement if you know what the X and Y vars are Smile
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 1  [ 3 Posts ]
Jump to:   


Style:  
Search: