Computer Science Canada

i need help moving it

Author:  computer_killer [ Thu Dec 16, 2004 12:08 pm ]
Post subject:  i need help moving it

what is the code for moving an object? im doing frogger for a class project. Laughing Embarassed

Author:  Delos [ Thu Dec 16, 2004 1:46 pm ]
Post subject: 

None exists.

If you want to move an object/picture on the other hand, there are numerous ways of doing it, the most common being that one uses variable x-coord and y-coord values, and in some sort of loop systematically change them.

Post your code:
- we'll get a better idea of where you are
- you'll more precise help

Author:  Tony [ Thu Dec 16, 2004 5:07 pm ]
Post subject:  Re: i need help moving it

computer_killer wrote:
what is the code for moving an object?

code:

Object.move(newLocation)

now that's assuming that your object has a working move method. Wink

Author:  Cervantes [ Thu Dec 16, 2004 5:18 pm ]
Post subject: 

Tony: And that the object moves in a one dimensional plane Wink

You probably won't have an object, per se, as you're working in Turing. You will probably have a bunch of variables that you clump together to store information about your "object".
When you draw your object on the screen, you'll be using (most likely, as Delos pointed out) two variables, x and y. That is, your Draw command will use these two variables. Thus, changing these variables will change the location of the "object", making it "move".

If you want to be able to move the "object" in one line, you'll have to make a procedure (like what Tony was getting at):
code:

procedure MoveObject (newX, newY : int)
  objectX := newX
  objectY := newY
end MoveObject

MoveObject (100, 148)

Author:  Tony [ Thu Dec 16, 2004 5:29 pm ]
Post subject: 

Cervantes wrote:
Tony: And that the object moves in a one dimensional plane Wink

Not if newLocation is a datatype that includes more than one dimention Wink Notice how I haven't specified that it's
code:

3Dpoint newLocation = new 3Dpoint(x,y,z)

Laughing

Author:  Cervantes [ Thu Dec 16, 2004 5:47 pm ]
Post subject: 

Somehow, when I posted that comment, I knew you were going to comeback with some computer kung-fu science and prove me wrong.
Bah!
I think we should be keeping things simpler than that, in this thread.

Author:  Tony [ Thu Dec 16, 2004 6:05 pm ]
Post subject: 

fair enough. And it's kung-foo Wink
so..
code:

var x : int := 0
loop
    x += 5 %move 5 pixels to the right
    Draw.FillBox (x, 100, x + 5, 105, blue)
    delay (20)
    cls
    exit when x >= maxx %reached the end of the screen
end loop


: