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

Username:   Password: 
 RegisterRegister   
 Help with moving objects
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
skyler




PostPosted: Tue May 16, 2006 11:13 pm   Post subject: Help with moving objects

hi, this is a truck i designed but i couldn't move the body of the truck which is a polygon with the tires and the lights at the same time... please i need your help in this , here is the program with documentation:

code:

%MOVING THE TRUCK:
loop
    %Moving the body:
    for move : 1 .. 8
        x (move) := x (move) - 1
    end for
    drawfillpolygon (x, y, 8, brightblue)

    %Moving the metal bar:
    for move2 : 1 .. 4
        x2 (move2) := x2 (move2) - 1
    end for
    drawfillpolygon (x2, y2, 4, 125)

    %Moving the window:
    for move3 : 1 .. 4
        x3 (move3) := x3 (move3) - 1
    end for
    drawfillpolygon (x3, y3, 4, yellow)
    delay (8)


end loop


%Moving the tires:

for move4 : 0 .. 640

    drawfilloval (450 - move4, 60, 40, 40, 26)
    drawoval (450 - move4, 60, 40, 40, 254)
    drawfilloval (450 - move4, 60, 20, 20, gray)
    drawoval (450 - move4, 60, 20, 20, 254)

    drawfilloval (550 - move4, 60, 40, 40, 26)
    drawoval (550 - move4, 60, 40, 40, 254)
    drawfilloval (550 - move4, 60, 20, 20, gray)
    drawoval (550 - move4, 60, 20, 20, 254)

    delay (5)

end for

%Moving the front lights:

for move5:0..640

drawfillbox (420-move5, 105, 430-move5, 115, yellow)
drawbox (420-move5, 105, 430-move5, 115, 254)

end for

%Moving the back lights:
for move6:0..640

drawfillbox (583-move6, 100, 590-move6, 114, brightred)

end for


THANK YOU.
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Wed May 17, 2006 9:46 am   Post subject: (No subject)

Well im about to state the obvious, because you're moving them at seperate times.

Your last 3 for loops are 0 .. 640 so they can all go into the same for loop. But im shure you dont even get that far because you have no exit in your loop.

It works like this. If you want 5 objects to move at the same time, are you going to move object 1, then 2, then 3 . . then 5? NO!

You're going to move object 1-5 at the same time. Put them all im the same for loop/loop in order to get them to move together.

Also, im the future post all of the code (so we can se exactly what you mean).
skyler




PostPosted: Wed May 17, 2006 11:12 am   Post subject: (No subject)

Thank you for ur reply and here is the full code:
code:

setscreen ("graphics:v256")
setscreen ("graphics:640,480")

%TRUCK

%Body:
View.Set ("graphics")
var x : array 1 .. 8 of int := init (440, 440, 490, 510, 560, 560, 610, 610)
var y : array 1 .. 8 of int := init (90, 120, 120, 140, 140, 115, 115, 90)
Draw.FillPolygon (x, y, 8, brightblue)
Draw.Polygon (x, y, 8, 254)


%Tires:
drawfilloval (470, 60, 40, 40, 26)
drawoval (470, 60, 40, 40, 254)
drawfilloval (470, 60, 20, 20, gray)
drawoval (470, 60, 20, 20, 254)

drawfilloval (570, 60, 40, 40, 26)
drawoval (570, 60, 40, 40, 254)
drawfilloval (570, 60, 20, 20, gray)
drawoval (570, 60, 20, 20, 254)


%Metal Bar at the back:
var x2 : array 1 .. 4 of int := init (560, 560, 585, 580)
var y2 : array 1 .. 4 of int := init (135, 140, 115, 115)
Draw.FillPolygon (x2, y2, 4, 125)
Draw.Polygon (x2, y2, 4, 254)

%Windows on the truck:
var x3 : array 1 .. 4 of int := init (492, 510, 540, 540)
var y3 : array 1 .. 4 of int := init (120, 138, 138, 120)
Draw.FillPolygon (x3, y3, 4, 125)
Draw.Polygon (x3, y3, 4, 254)

%Front lights:
drawfillbox (440, 105, 450, 115, yellow)
drawbox (440, 105, 450, 115, 254)

%Back lights:
drawfillbox (603, 100, 610, 114, brightred)

%MOVING THE TRUCK:
loop
    %Moving the body:
    for move : 1 .. 8
        x (move) := x (move) - 1
    end for
    drawfillpolygon (x, y, 8, brightblue)

    %Moving the metal bar:
    for move2 : 1 .. 4
        x2 (move2) := x2 (move2) - 1
    end for
    drawfillpolygon (x2, y2, 4, 125)

    %Moving the window:
    for move3 : 1 .. 4
        x3 (move3) := x3 (move3) - 1
    end for
    drawfillpolygon (x3, y3, 4, yellow)
    delay (8)

    end loop
   
    for move4 : 0 .. 640

        drawfilloval (450 - move4, 60, 40, 40, 26)
        drawoval (450 - move4, 60, 40, 40, 254)
        drawfilloval (450 - move4, 60, 20, 20, gray)
        drawoval (450 - move4, 60, 20, 20, 254)

        drawfilloval (550 - move4, 60, 40, 40, 26)
        drawoval (550 - move4, 60, 40, 40, 254)
        drawfilloval (550 - move4, 60, 20, 20, gray)
        drawoval (550 - move4, 60, 20, 20, 254)

        delay (5)
   
       
       end for


%Moving the tires:


%Moving the front lights:
for move5 : 0 .. 640

    drawfillbox (420 - move5, 105, 430 - move5, 115, yellow)
    drawbox (420 - move5, 105, 430 - move5, 115, 254)

end for

%Moving the back lights:
for move6 : 0 .. 640

    drawfillbox (583 - move6, 100, 590 - move6, 114, brightred)

end for


Can u please help me arrange that in order to make the whole truck move.
THANK YOU.
Albrecd




PostPosted: Wed May 17, 2006 12:48 pm   Post subject: (No subject)

You could start by doing what jamonathin already told you.
skyler




PostPosted: Wed May 17, 2006 1:55 pm   Post subject: (No subject)

hi, thank you for ur reply Albrecd, but i'm kinda a beginner and i really didn't quite understand how to arrange to object in one loop to make them move , so if u could help me please i'd be grateful. THANK YOU
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  [ 5 Posts ]
Jump to:   


Style:  
Search: