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

Username:   Password: 
 RegisterRegister   
 Keeping a drawn object inside the max of screen
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Robotkubo




PostPosted: Thu Feb 25, 2016 10:15 am   Post subject: Keeping a drawn object inside the max of screen

Been working on a project that makes a ball grow and get smaller with the press of a '1' and '2' and can move with the arrow keys, I got all that working but I cant get it to stay inside the max of the screen, I tried some code but if someone could point me in the right direction that would be great!
Turing:


<%Assignment 5
View.Set ("graphics:max,max,offscreenonly,nobuttonbar")
var x, y : int
var r : int := 10
x := 100
y := 100
var chars : array char of boolean
if y + 20 > maxy then
    y := y - 5
end if
loop
    drawfilloval (x, y, r, r, red)
    Input.KeyDown (chars)

    if chars (KEY_UP_ARROW) then
        y := y + 8
    end if
    if chars (KEY_RIGHT_ARROW) then
        x := x + 8
    end if
    if chars (KEY_LEFT_ARROW) then
        x := x - 8
    end if
    if chars (KEY_DOWN_ARROW) then
        y := y - 8
    end if

    if chars ('1') then
        r := r + 5
    end if

    if chars ('2') then
        r := r - 4
    end if
    View.Update
    delay (20)
    cls
    if r = maxx then
        r := r - 10
    end if

    if r = maxy then
        r := r - 10
    end if
end loop
>



Please specify what version of Turing you are using
<Answer Here>
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Thu Feb 25, 2016 1:24 pm   Post subject: RE:Keeping a drawn object inside the max of screen

You need to compare the coordinates of the ball to the coordinates of the bounds of the screen. Try drawing it out on paper. Draw the ball in a few different spots (inside the walls, outside the walls, adjacent to the walls, etc) and label the coordinates of each one. Try to figure out how they relate to those of the walls and then create rules to decide where the ball is based on what you learned.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: