
-----------------------------------
Thuged_Out_G
Sat Jan 17, 2004 12:51 pm

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 


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


-----------------------------------
Cervantes
Sat Jan 17, 2004 1:03 pm


-----------------------------------
as kickass as whatdotcolour is i wouldn't recommend it here.

instead of 
            elsif whatdotcolor (ballx, bally) = 12 then 
                ballxdir := -ballxdir 

try something like

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
Sat Jan 17, 2004 1:05 pm


-----------------------------------
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
Sat Jan 17, 2004 1:11 pm


-----------------------------------
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
Sat Jan 17, 2004 1:15 pm


-----------------------------------
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
Sat Jan 17, 2004 1:16 pm


-----------------------------------
i used window.update because i am opening my own window, when i used view.update though i had the same problem  :?

-----------------------------------
shorthair
Sat Jan 17, 2004 1:22 pm


-----------------------------------
use hte brand spanking new view.updatearea ,

-----------------------------------
Andy
Sat Jan 17, 2004 2:23 pm


-----------------------------------
yepp, thats the way, makes your program so much faster

-----------------------------------
Cervantes
Sat Jan 17, 2004 4:41 pm


-----------------------------------
is that in Turing 4.5 ? or is it 4.05... whatever, the new version?

-----------------------------------
Andy
Sat Jan 17, 2004 7:26 pm


-----------------------------------
4.05 its in there... however they did lie about Window.UpdateArea

-----------------------------------
Cervantes
Sat Jan 17, 2004 7:32 pm


-----------------------------------
its non-existant?

-----------------------------------
AsianSensation
Sat Jan 17, 2004 7:54 pm


-----------------------------------
i used window.update because i am opening my own window, when i used view.update though i had the same problem  :?

you could always go Window.Select, and then View.Update. I know it worked for my game.

-----------------------------------
Andy
Sun Jan 18, 2004 6:13 pm


-----------------------------------
no there is Window.UpdateArea... its just not documented in the help
