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

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




PostPosted: Sat Jan 17, 2004 12:51 pm   Post subject: Pong help

sometimes the ball gets stuck to the paddles, and the points just keep going up here...here is my code, if someone could give me a solution, id appreciate it

code:

var win := Window.Open ("title:Alans Pong Game")
var ballx, bally, ballxdir, ballydir : int
var count, count1 := 0
var x, y, x1, y1 : int
var chars : array char of boolean
var name : string
View.Set ("graphics")
View.Set ("offscreenonly")
ballx := Rand.Int (0, maxx)
bally := Rand.Int (0, maxy)
ballxdir := 1
ballydir := 1
x := 0
x1 := 10
y := 100
y1 := maxy div 2

process user_AI
    %%%%%%%%%%%%%%%%%%%%COMP AI%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    Draw.FillBox (maxx - 10, bally + 40, maxx, bally, 12)
    if whatdotcolor (ballx, bally) = 12 then
        ballxdir := -ballxdir
    end if
    %%%%%%%%%%%%%%%%%END COMP AI%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%START USER CONTROLS%%%%%%%%%%%%%%%%%%%%%%

    Draw.FillBox (x, y, x1, y1, 12)
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        Draw.FillBox (x, y + 1, x1, y1 + 1, 12)
        y := y + 1
        y1 := y1 + 1
        if y1 = maxy - 16 then
            y := y - 1
            y1 := y1 - 1
            Draw.FillBox (x, y - 1, x1, y1 - 1, 12)
        end if
    elsif chars (KEY_DOWN_ARROW) then
        Draw.FillBox (x, y - 1, x1, y1 - 1, 12)
        y := y - 1
        y1 := y1 - 1
        if y = maxy - maxy then
            y := y + 1
            y1 := y1 + 1
        end if
    end if
    %%%%%%%%%%%%%%END USER CONTROLS%%%%%%%%%%%%%%%%%%%%%%%%%%
end user_AI

proc start
    Text.Color (black)
    put "Enter your name: " ..
    get name
    setscreen ("nocursor")
end start

proc pong
    start
    loop
        cls
        Draw.Box (0, 0, maxx, maxy - 16, 15)
        put "Comp Score: ", count ..
        put " ", name, "'s Score: ", count1
        fork user_AI
        drawfilloval (ballx, bally, 5, 5, 1)
        loop
            if ballx > maxx and ballxdir > 0 then
                ballxdir := -ballxdir
            elsif ballx < 0 and ballxdir < 0 then
                ballxdir := -ballxdir
            elsif bally > maxy - 16 and ballydir > 0 then
                ballydir := -ballydir
            elsif bally < 0 and ballydir < 0 then
                ballydir := -ballydir
            elsif whatdotcolor (ballx, bally) = 12 then
                ballxdir := -ballxdir
            elsif ballx < 1 then
                count += 1
            elsif ballx = maxx - 2 then
                count1 += 1
            end if
            ballx += ballxdir
            bally += ballydir
            exit
        end loop
        Window.Update (win)
    end loop
end pong

pong
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Jan 17, 2004 1:03 pm   Post subject: (No subject)

as kickass as whatdotcolour is i wouldn't recommend it here.

instead of
code:
            elsif whatdotcolor (ballx, bally) = 12 then
                ballxdir := -ballxdir


try something like

code:
elsif ballx> maxx - (whatever you want) and bally > (paddley and bally < paddley + height then
ballxdir := -ballxdir


I haven't tested that at all and you'd have to input your own values...
Andy




PostPosted: Sat Jan 17, 2004 1:05 pm   Post subject: (No subject)

if you dont totally understand how to use whatdotcolor plz dont use it... u'll simply inviting ppl like tony and dan to insult it... if u were to use whatdotcolor for ur problem, you have to check the step ahead of time. instead of checking the x and y location, check the x+xdir and y+ydir so that your ball wont go beyond the paddle
Thuged_Out_G




PostPosted: Sat Jan 17, 2004 1:11 pm   Post subject: (No subject)

i used whatdotcolor because it made the code alot sorter....and it works fine, the only problem is when the ball hits on the very edge of the paddle, it sometimes kinda sticks to it....and i also cant seem to get the players paddle to stop flickering without slowing down the hole program
Cervantes




PostPosted: Sat Jan 17, 2004 1:15 pm   Post subject: (No subject)

I noticed you used Window.Update instead of View.Update...

never heard of Window.Update before, iuno why but maybe thats why its flickering... never flickers for me when I use View.Update..

dodge, that's cool, never thought of that before.. does that work flawlessly??
Thuged_Out_G




PostPosted: Sat Jan 17, 2004 1:16 pm   Post subject: (No subject)

i used window.update because i am opening my own window, when i used view.update though i had the same problem Confused
shorthair




PostPosted: Sat Jan 17, 2004 1:22 pm   Post subject: (No subject)

use hte brand spanking new view.updatearea ,
Andy




PostPosted: Sat Jan 17, 2004 2:23 pm   Post subject: (No subject)

yepp, thats the way, makes your program so much faster
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Jan 17, 2004 4:41 pm   Post subject: (No subject)

is that in Turing 4.5 ? or is it 4.05... whatever, the new version?
Andy




PostPosted: Sat Jan 17, 2004 7:26 pm   Post subject: (No subject)

4.05 its in there... however they did lie about Window.UpdateArea
Cervantes




PostPosted: Sat Jan 17, 2004 7:32 pm   Post subject: (No subject)

its non-existant?
AsianSensation




PostPosted: Sat Jan 17, 2004 7:54 pm   Post subject: (No subject)

Thuged_Out_G wrote:
i used window.update because i am opening my own window, when i used view.update though i had the same problem Confused


you could always go Window.Select, and then View.Update. I know it worked for my game.
Andy




PostPosted: Sun Jan 18, 2004 6:13 pm   Post subject: (No subject)

no there is Window.UpdateArea... its just not documented in the help
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  [ 13 Posts ]
Jump to:   


Style:  
Search: