Computer Science Canada

How do you put an output "border" for animations so it doesn't pass outside the output screen?

Author:  Macuser111 [ Sat Dec 11, 2010 8:16 pm ]
Post subject:  How do you put an output "border" for animations so it doesn't pass outside the output screen?

What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>


What is the problem you are having?
outputting a "border" for animations so it doesn't pass outside the output screen?

Describe what you have tried to solve this problem
made an if structure for the border but ends up killing the animation.

Please specify what version of Turing you are using
4.1.1

%Declaration Section
var startpointx, startpointy : int := 0
var endpointx, endpointy : int := 50
var key : string (1)
%set screen mode and size
setscreen ("graphics:400;300")
setscreen ("noecho")
setscreen ("offscreenonly")
setscreen ("nocursor")
procedure display
drawfillbox (startpointx, startpointy, endpointx, endpointy, white)
drawfillbox (startpointx + 1, startpointy + 1, endpointx - 1, endpointy - 1, blue)
getch (key)

if key = chr (200) then
startpointy := startpointy + 1 %up
endpointy := endpointy + 1
elsif key = chr (208) then %down
startpointy := startpointy - 1
endpointy := endpointy - 1
elsif key = chr (205) then
startpointx := startpointx + 1 %right
endpointx := endpointx + 1
else
if key = chr (203) then
startpointx := startpointx - 1 %left
endpointx := endpointx - 1
end if
end if

View.Update
end display
%Main Program
loop
display
exit when key = chr (27)
end loop

Author:  Searing [ Tue Dec 14, 2010 10:40 am ]
Post subject:  RE:How do you put an output "border" for animations so it doesn\'t pass outside the output screen?

First of all, instead of having an else, then another if, consider just simply having two if structures, it will simplify your coding and allow you to debug easier.

Also, what you are trying to accieve is to not allow the user to go offscreen, so you should look at what allows him to go offscreen, then fix that.

Hint, it's in the if structures, and includes restrictions.


: