
-----------------------------------
DAV1209
Tue Oct 28, 2003 4:07 pm

help with modify programming code
-----------------------------------
here is the original programming code:


setscreen ("graphics")
setscreen ("nocursor")

var tablex1, tabley1, tablex2, tabley2, tableLength, tableWidth, tableColour
    : int
const buffer := 10
var keypress : string (1)

tableColour := green
tableLength := maxx - buffer * 2
tableWidth := tableLength div 2
tablex1 := buffer
tabley1 := buffer
tablex2 := tablex1 + tableLength
tabley2 := tabley1 + tableWidth
drawfillbox (tablex1, tabley1, tablex2, tabley2, tableColour)

var x, y, r, c, dy, dx : int
r := 6
c := white

x := maxx div 2
y := maxy div 2

dy := 2
dx := 2

drawfilloval (x, y, r, r, c)

getch (keypress)

for p : 1 .. 50
    drawfilloval (x, y, r, r, tableColour)

    y := y + dy
    x := x + dx

    drawfilloval (x, y, r, r, c)

    delay (15)
end for



how can i modify the program so the ball will continue to travel indefinitely and also the ball will bounce when it reaches any edge of the table.( The angle of incidence is equal to the angle of reflection).

-----------------------------------
thoughtful
Tue Oct 28, 2003 5:18 pm


-----------------------------------
To keep it moving you have to change the for statement to a loop statement.
For the bouncing part look at my if statement in the loop.


setscreen ("graphics")
setscreen ("nocursor")
setscreen ("offscreenonly")

var tablex1, tabley1, tablex2, tabley2, tableLength, tableWidth, tableColour
    : int
const buffer := 10
var keypress : string (1)

tableColour := green
tableLength := maxx - buffer * 2
tableWidth := tableLength div 2
tablex1 := buffer
tabley1 := buffer
tablex2 := tablex1 + tableLength
tabley2 := tabley1 + tableWidth
drawfillbox (tablex1, tabley1, tablex2, tabley2, tableColour)

var x, y, r, c, dy, dx : int
r := 6
c := white

x := maxx div 2
y := maxy div 2

dy := 2
dx := 2

drawfilloval (x, y, r, r, c)

getch (keypress)

loop
    drawfillbox (tablex1, tabley1, tablex2, tabley2, tableColour)


    y := y + dy
    x := x + dx

    if y < tabley1 or y > tabley2 then
        dy *= -1
    end if
    if x < tablex1 or x > tablex2 then
        dx *= -1
    end if

    drawfilloval (x, y, r, r, c)

    delay (15)
    View.Update
    cls
end loop

Basically if the bally is greater than tabley2 or less the tabley1, it reflects the y speed. Same for the x.
PS: Use offscreen only and view update for smooth animations, dont draw a ball over the last one to hide it  :idea:  :wink:

-----------------------------------
Tony
Tue Oct 28, 2003 5:36 pm


-----------------------------------
if you're interested, you can also take a look at some fine examples of pool games programmed in turing. Just borwse the forum or use the Search.

-----------------------------------
thoughtful
Tue Oct 28, 2003 5:38 pm


-----------------------------------
or wait till  i rite my pool & collision detection tutorial :P  :P

-----------------------------------
DAV1209
Wed Oct 29, 2003 5:34 pm


-----------------------------------

PS: Use offscreen only and view update for smooth animations

where can i find the update for it

-----------------------------------
Tony
Wed Oct 29, 2003 6:22 pm


-----------------------------------
You'd need the latest version of Turing - 4.something. If you already have v4 installed, go to [url=www.holtsoft.com]HoltSoft and download the patch. If you don't have it... well you'd have to find it somewhere :wink:

-----------------------------------
DAV1209
Thu Oct 30, 2003 5:39 pm


-----------------------------------

If you already have v4 installed, go to HoltSoft and download the patch. If you don't have it... 

i look for the patch but couldn't find it 
can you give me the link to the patch
thanks

-----------------------------------
Dan
Fri Oct 31, 2003 8:45 pm


-----------------------------------
http://www.holtsoft.com/turing/support/#turing4patches

they realy should wrok on there layout, hard to find anything.
