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

Username:   Password: 
 RegisterRegister   
 Help me please
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
adrianr2z




PostPosted: Tue Mar 19, 2013 6:58 pm   Post subject: Help me please

What is it you are trying to achieve?
Trying to get an image to move across thescreen and when it hits the end of the screen, i want the loop to end and move on. Having the dragon move across the screen was pain cause I created a procedure and put it in my loop before have doing a CLS. Any way to make this more efficient?


What is the problem you are having?
Wont END! I set it so that the loop ends when the image has reached maxx (end of the screen) and move on with the code but it repeats and never ends.

Describe what you have tried to solve this problem
Everything I can. Many to remember.

Turing:


var Cloud23 : int

Cloud23 := Pic.FileNew ("Dragon.jpg")
Cloud23 := Pic.Scale (Cloud23, 50, 100)
%var x1 : Rand.Int
var y1 : int := maxy div 2 + 250

loop
    for i : 1 .. maxx
    var x1: int := 0 + i
        draw
        Pic.Draw (Cloud23,x1, y1, picMerge)

       View.Update
       
       Pic.Draw (Cloud23, x1 ,y1, picMerge)

if x1=maxx then
exit
end if

end for
end loop




Please specify what version of Turing you are using
4.1
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Mar 19, 2013 7:15 pm   Post subject: RE:Help me please

try this code:
code:

var Cloud23 : int

Cloud23 := Pic.FileNew ("Dragon.jpg")
Cloud23 := Pic.Scale (Cloud23, 50, 100)
%var x1 : Rand.Int
var y1 : int := maxy div 2 + 250

loop
   put "now starting for loop"
   delay(2000)

    for i : 1 .. maxx
    var x1: int := 0 + i
        draw
        Pic.Draw (Cloud23,x1, y1, picMerge)

       View.Update
       
       Pic.Draw (Cloud23, x1 ,y1, picMerge)

if x1=maxx then
put "now exiting"
delay(2000)
exit
end if

end for
put "for loop ended"
delay(2000)
end loop
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
adrianr2z




PostPosted: Tue Mar 19, 2013 7:27 pm   Post subject: Re: RE:Help me please

Tony @ Tue Mar 19, 2013 7:15 pm wrote:
try this code:
code:

var Cloud23 : int

Cloud23 := Pic.FileNew ("Dragon.jpg")
Cloud23 := Pic.Scale (Cloud23, 50, 100)
%var x1 : Rand.Int
var y1 : int := maxy div 2 + 250

loop
   put "now starting for loop"
   delay(2000)

    for i : 1 .. maxx
    var x1: int := 0 + i
        draw
        Pic.Draw (Cloud23,x1, y1, picMerge)

       View.Update
       
       Pic.Draw (Cloud23, x1 ,y1, picMerge)

if x1=maxx then
put "now exiting"
delay(2000)
exit
end if

end for
put "for loop ended"
delay(2000)
end loop


Thanks for the help but it isn't what I wanted. I edited it so that instead of putting text, It would move onto the rest of my text however it didn't work and just repeated non stop. Here is all the code after it

code:


var Cloud23 : int

Cloud23 := Pic.FileNew ("Dragon.jpg")
Cloud23 := Pic.Scale (Cloud23, 50, 100)
%var x1 : Rand.Int
var y1 : int := maxy div 2 + 250

loop
   
 

   for i : 1 .. maxx
    var x1: int := 0 + i
        draw
        Pic.Draw (Cloud23,x1, y1, picMerge)

       View.Update
       
       Pic.Draw (Cloud23, x1 ,y1, picMerge)

if x1=maxx then

exit
end if

end for

end loop
   

delay (1000)
cls


Font.Draw ("This is were our story comes to an end. Dikembe and the basketball lived happily ever after!", 0, maxy - 40, Font2, brightblue)
Font.Draw ("They became best friends and Dikembe played with the ball for a long time.  ", 0, maxy - 80, Font2, brown)

delay (5000)
cls


Font.Draw ("THE END! :)", maxx div 2, maxy div 2, Font3, brown)


By the way your code didn't work. When it hit the end of the screen, it didn't exit.
Tony




PostPosted: Tue Mar 19, 2013 9:46 pm   Post subject: RE:Help me please

That's your code. I've just added some put statements to help you track what your own code is doing.

It's all supposed to repeat -- as the animation is inside of a loop.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
adrianr2z




PostPosted: Tue Mar 19, 2013 10:04 pm   Post subject: Re: RE:Help me please

Tony @ Tue Mar 19, 2013 9:46 pm wrote:
That's your code. I've just added some put statements to help you track what your own code is doing.

It's all supposed to repeat -- as the animation is inside of a loop.


It's repeating forever though... I don't want it to repeat forever. I'm trying to make the loop stop once the image hit the side of the windows (once it his maxx) and move on to clearing the screen and displaying

code:

Font.Draw ("This is were our story comes to an end. Dikembe and the basketball lived happily ever after!", 0, maxy - 40, Font2, brightblue)
Font.Draw ("They became best friends and Dikembe played with the ball for a long time.  ", 0, maxy - 80, Font2, brown)
Tony




PostPosted: Tue Mar 19, 2013 10:16 pm   Post subject: Re: RE:Help me please

adrianr2z @ Tue Mar 19, 2013 10:04 pm wrote:
It's repeating forever though...


but that's exactly what loop does!
Quote:

A loop statement causes the statements (and declarations) in it to be repeatedly executed. This continues until terminated by one of its enclosed exit statements (or by an enclosed return or result statement).
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
adrianr2z




PostPosted: Tue Mar 19, 2013 10:22 pm   Post subject: Re: RE:Help me please

Tony @ Tue Mar 19, 2013 10:16 pm wrote:
adrianr2z @ Tue Mar 19, 2013 10:04 pm wrote:
It's repeating forever though...


but that's exactly what loop does!
Quote:

A loop statement causes the statements (and declarations) in it to be repeatedly executed. This continues until terminated by one of its enclosed exit statements (or by an enclosed return or result statement).


Oh I thought there was a way to end a loop by saying when this happens... Then how do I do what I want? I'm so frustrated that I can't get a simple picture to hit the end of screen and just move on. Here is a sample code of my friends and this is what I want to happen however I was wondering if you can break it down cause I don't understand it

code:

var PositionBallY : int := maxy div 2.7
var PositionBallX : int := maxx div 1.6
for i : 0 .. 129
    drawfilloval (PositionBallX, PositionBallY, 9, 9, 12)
    delay (19)
    drawfilloval (PositionBallX, PositionBallY, 9, 9, 101)
    PositionBallX := PositionBallX - 5
    drawfilloval (PositionBallX, PositionBallY, 9, 9, 12)
    View.UpdateArea (maxx div 1.5, maxy div 3.7, maxx div 4, maxy div 2.4)
end for

var PositionBallX2 : int := maxx div 3.6
for d : 0 .. 130
    drawfilloval (PositionBallX2, PositionBallY, 9, 9, 12)
    delay (19)
    drawfilloval (PositionBallX2, PositionBallY, 9, 9, 101)
    PositionBallX2 := PositionBallX2 + 5
    drawfilloval (PositionBallX2, PositionBallY, 9, 9, 12)
    View.UpdateArea (maxx div 1.5, maxy div 3.7, maxx div 4, maxy div 2.4)
end for


UPDATE! OH MY GOD! WOW! I DELETED THE LOOP AND AFTER IT WENT ON TO THE REST OF THE CODE! WOW! I THOUGHT THE LOOP WAS NEEDED TO HAVE THE PICTURE MOVE FORWARD! YESSSSSSSSS! OH MY GOD! I SPENT HOURS FIGURING WHY IT KEPT LOOPING! I DIDN'T NEED THE GOD DAMN LOOOOOOOOOOOOP! WOOOOHOOOOOOOOOOOOOOOOOOOOOOOOOOOO
adrianr2z




PostPosted: Tue Mar 19, 2013 10:27 pm   Post subject: Re: Help me please

One more question, I have dragon right however when it's going across the screen, the background covers my other image which is a cloud. I was wondering, How do i send the dragon image to the background so that cloud is on front and doesn't get covered by the dragon image?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Mar 19, 2013 10:49 pm   Post subject: RE:Help me please

re: loops -- frustration just clouds your judgement. Sometimes you need to step back and examine exactly what your code is doing in detail. A simple exercise to illustrate how nested loops work:
code:

loop
   put "Start outside loop"
   delay(500)
   loop
      put "Start inside loop"
      delay(500)
      exit  % exits the closest loop - the inside one
      put "this will not print"
   end loop
   put "Ending outside loop"
   delay(500)
end loop



For drawing stuff -- it sounds that you need to draw parts in the order that you want them to layer. So if you want the cloud in the very front, you would need to draw it last.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
adrianr2z




PostPosted: Tue Mar 19, 2013 11:05 pm   Post subject: Re: RE:Help me please

Just when I thought everything is ok, It actually isn't :/ So Previous code was procedure and I couldn't get the clouds to be written last because they were part of the procedure. Deleted the procedure and now I have another problem. Image leaves a trail even with offscreen and view.update + my clouds disappear :/ Decided to copy all my code just so you can see what the hell is going on and test it for yourself if possible. I really want to keep it as procedure but if that isn't possible, what do I do???

code:

View.Set ("graphics:max;max;nobuttonbar,offscreenonly")

%Creating procedure so that background stops getting deleted when I do the flying dragon
%Annoying dragon keeps deleting everything so someone online recommended I create a simple procedure and recall it in my loop so that it keeps redrawing
% And keeps updating and nobody notices that it is being redrawn.
% Background
Draw.FillBox (0, 0, maxx, maxy, 52)
%Grass on ground
Draw.FillBox (0, 0, maxx, maxy div 2 - 200, green)     %Grass
Draw.Arc (maxx div 5 - 150, maxy div 2 - 200, 50, 50, 0, 90, green)     %Grass Spikes
Draw.Arc (maxx div 5 - 50, maxy div 2 - 200, 50, 50, 90, 180, green)     %Grass Spikes
Draw.Line (maxx div 5 - 100, maxy div 2 - 200, maxx div 5 - 100, maxy div 2 - 150, green)     %Grass Spikes
Draw.Arc (2 * maxx div 5 - 150, maxy div 2 - 200, 50, 50, 0, 90, green)     %Grass Spikes
Draw.Arc (2 * maxx div 5 - 50, maxy div 2 - 200, 50, 50, 90, 180, green)     %Grass Spikes
Draw.Line (2 * maxx div 5 - 100, maxy div 2 - 200, 2 * maxx div 5 - 100, maxy div 2 - 150, green)     %Grass Spikes
Draw.Arc (3 * maxx div 5 - 150, maxy div 2 - 200, 50, 50, 0, 90, green)     %Grass Spikes
Draw.Arc (3 * maxx div 5 - 50, maxy div 2 - 200, 50, 50, 90, 180, green)     %Grass Spikes
Draw.Line (3 * maxx div 5 - 100, maxy div 2 - 200, 3 * maxx div 5 - 100, maxy div 2 - 150, green)     %Grass Spikes
Draw.Arc (4 * maxx div 5 - 150, maxy div 2 - 200, 50, 50, 0, 90, green)     %Grass Spikes
Draw.Arc (4 * maxx div 5 - 50, maxy div 2 - 200, 50, 50, 90, 180, green)     %Grass Spikes
Draw.Line (4 * maxx div 5 - 100, maxy div 2 - 200, 4 * maxx div 5 - 100, maxy div 2 - 150, green)     %Grass Spikes
Draw.Arc (5 * maxx div 5 - 150, maxy div 2 - 200, 50, 50, 0, 90, green)     %Grass Spikes
Draw.Arc (5 * maxx div 5 - 50, maxy div 2 - 200, 50, 50, 90, 180, green)     %Grass Spikes
Draw.Line (5 * maxx div 5 - 100, maxy div 2 - 200, 5 * maxx div 5 - 100, maxy div 2 - 150, green)     %Grass Spikes
%The Bird
Draw.Arc (maxx div 2 - maxx div 2, maxy div 2 + 150, 30, 30, 0, 90, black)

Draw.Arc (maxx div 2 - maxx div 2 + 60, maxy div 2 + 150, 30, 30, 90, 180, black)




%The Sun
Draw.FillArc (maxx, maxy, maxx div 2 - 450, maxy div 2 - 200, 360, 720, yellow)
% The Sun Rays
Draw.Line (maxx, maxy, maxx - 30, maxy div 2 + 120, yellow)
Draw.Line (maxx, maxy, maxx - 230, maxy div 2 + 180, yellow)
Draw.Line (maxx, maxy, maxx - 300, maxy - 30, yellow)
% The Basketball :)
Draw.FillOval (maxx div 2 - 80, maxy div 2 - 150, 50, 50, 41)     % The Orange Circle
Draw.FillOval (maxx div 2 - 65, maxy div 2 - 135, 10, 10, 7)     % The Eyes
Draw.FillOval (maxx div 2 - 98, maxy div 2 - 135, 10, 10, 7)     % Eye #2
Draw.Arc (maxx div 2 - 80, maxy div 2 - 160, 20, 20, 180, 360, 7)     % The Smile
%Thought Bubble of the basketball
Draw.Line (maxx div 2 - 60, maxy div 2 - 90, maxx div 2 - 30, maxy div 2 - 40, yellow)
Draw.Box (maxx div 2 - 30, maxy div 2 - 40, maxx div 2 + 400, maxy div 2 + 70, white)
Font.Draw ("OH MA GAWD! IT'S DIKEMEBE MUTOMBO! ", maxx div 2 - 30, maxy div 2 + 45, Font2, brightgreen)
Font.Draw (" Is he really going to come and play with me?", maxx div 2 - 35, maxy div 2 + 25, Font2, brightgreen)
%Dikeme Mutombo
Draw.FillOval (maxx div 2 - 350, maxy div 2, 50, 50, white)     %Head
Draw.FillOval (maxx div 2 - 330, maxy div 2, 10, 10, black)     % The Eyes
Draw.FillOval (maxx div 2 - 375, maxy div 2, 10, 10, black)     % Eye #2
Draw.Arc (maxx div 2 - 353, maxy div 2 - 20, 20, 20, 180, 360, black)     %Smile
Draw.FillBox (maxx div 2 - 360, maxy div 2 - 50, maxx div 2 - 340, maxy div 2 - 150, black)     %Body
Draw.Line (maxx div 2 - 350, maxy div 2 - 80, maxx div 2 - 400, maxy div 2 - 50, black)     %Arms
Draw.Line (maxx div 2 - 350, maxy div 2 - 80, maxx div 2 - 300, maxy div 2 - 50, black)     %Arms
Draw.Line (maxx div 2 - 360, maxy div 2 - 50, maxx div 2 - 360, maxy div 2 - 200, black)     %legs
Draw.Line (maxx div 2 - 340, maxy div 2 - 50, maxx div 2 - 340, maxy div 2 - 200, black)     %legs
%Thought Bubble of Dikembe Mutombo
Draw.Line (maxx div 2 - 350, maxy div 2 + 50, maxx div 2 - 300, maxy div 2 + 80, brightred)
Draw.Box (maxx div 2 - 300, maxy div 2 + 80, maxx div 2 + 200, maxy div 2 + 200, brightblue)
Font.Draw ("Hello almighty basketball, You seem like a very good basketball to play with!", maxx div 2 - 290, maxy div 2 + 180, Font4, brightred)
Font.Draw ("I am going to play with you!", maxx div 2 - 290, maxy div 2 + 140, Font4, brightred)



var Dragon : int
Dragon := Pic.FileNew ("Dragon.jpg")
Dragon := Pic.Scale (Dragon, 50, 50)
var y1 : int := maxy div 2 + 200
for i : 1 .. maxx
    var x1 : int := 0 + i

    Pic.Draw (Dragon, x1, y1, picCopy)
    View.Update
    delay (19)
    Pic.Draw (Dragon, x1, y1, picCopy)

    if x1 = maxx then
        exit
    end if
end for


%Clouds in the sky
var Cloud : int
Cloud := Pic.FileNew ("cloud1.jpg")
Pic.Draw (Cloud, maxx div 2 - 500, maxy div 2 + 200, picCopy)
Pic.Draw (Cloud, maxx div 2 - 300, maxy div 2 + 200, picCopy)
Pic.Draw (Cloud, maxx div 2 - 100, maxy div 2 + 200, picCopy)
Pic.Draw (Cloud, maxx div 2 + 100, maxy div 2 + 200, picCopy)
Pic.Free (Cloud)


What am I doing wrong???? Why can't I do a simple animation without screwing everything else up. Gets so frustrating...
Tony




PostPosted: Tue Mar 19, 2013 11:18 pm   Post subject: Re: RE:Help me please

adrianr2z @ Tue Mar 19, 2013 11:05 pm wrote:
Image leaves a trail

Where do you clear the screen from the previous drawing? That is
code:

for x : 1 .. 100
   Draw.Oval(x*10, 100, 10,10, red)
end for

Is this an animation leaving a trail, do did I mean to draw 100 circles on the screen as a pattern?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
adrianr2z




PostPosted: Tue Mar 19, 2013 11:38 pm   Post subject: Re: RE:Help me please

Tony @ Tue Mar 19, 2013 11:18 pm wrote:
adrianr2z @ Tue Mar 19, 2013 11:05 pm wrote:
Image leaves a trail

Where do you clear the screen from the previous drawing? That is
code:

for x : 1 .. 100
   Draw.Oval(x*10, 100, 10,10, red)
end for

Is this an animation leaving a trail, do did I mean to draw 100 circles on the screen as a pattern?


I DID CLS AND NOW IT DELETES EVERYTHING! HOW DO I FIX THIS! I'VE SPENT A WHOLE DAY TRYING TO DO THIS! WHAT DO I DO! the dragon trail is fine just the stupid thing deletes everything
adrianr2z




PostPosted: Wed Mar 20, 2013 12:39 am   Post subject: Re: Help me please

I tried repositioning everything to make it work but no luck. The cls fixes the trail problem but causs further problems by clearing everything else.
Tony




PostPosted: Wed Mar 20, 2013 1:00 am   Post subject: RE:Help me please

That's what cls does, it clears the screen, so you can draw new stuff
Quote:

The cls (clear screen) procedure is used to blank the output window.


It's as good as Draw.FillBox(0,0,maxx,maxy,background_color)

If you want to draw a smaller box, you can specify the dimensions directly.

Ultimately you always draw new stuff on top of the old stuff. If something is missing because of movement, just draw it again, in the correct position.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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  [ 14 Posts ]
Jump to:   


Style:  
Search: