help with modify programming code
Author |
Message |
DAV1209
|
Posted: Tue Oct 28, 2003 4:07 pm Post subject: help with modify programming code |
|
|
here is the original programming code:
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). |
|
|
|
|
|
Sponsor Sponsor
|
|
|
thoughtful
|
Posted: Tue Oct 28, 2003 5:18 pm Post subject: (No subject) |
|
|
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.
code: |
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 |
|
|
|
|
|
Tony
|
Posted: Tue Oct 28, 2003 5:36 pm Post subject: (No subject) |
|
|
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. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
thoughtful
|
Posted: Tue Oct 28, 2003 5:38 pm Post subject: (No subject) |
|
|
or wait till i rite my pool & collision detection tutorial |
|
|
|
|
|
DAV1209
|
Posted: Wed Oct 29, 2003 5:34 pm Post subject: (No subject) |
|
|
Quote:
PS: Use offscreen only and view update for smooth animations
where can i find the update for it |
|
|
|
|
|
Tony
|
Posted: Wed Oct 29, 2003 6:22 pm Post subject: (No subject) |
|
|
You'd need the latest version of Turing - 4.something. If you already have v4 installed, go to HoltSoft and download the patch. If you don't have it... well you'd have to find it somewhere |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
DAV1209
|
Posted: Thu Oct 30, 2003 5:39 pm Post subject: (No subject) |
|
|
Quote:
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
|
Posted: Fri Oct 31, 2003 8:45 pm Post subject: (No subject) |
|
|
http://www.holtsoft.com/turing/support/#turing4patches
they realy should wrok on there layout, hard to find anything. |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
Sponsor Sponsor
|
|
|
|
|