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

Username:   Password: 
 RegisterRegister   
 Relative Movement
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Latagore




PostPosted: Wed Oct 17, 2007 9:40 pm   Post subject: Relative Movement

How might I do relative movement (Where you use left and right to turn the character and up and down to move relative to facing direction) for a character that the user controls? I've tried using an angle, but it seems kind of hard to do since objects are oriented with x and y coordinates.
Sponsor
Sponsor
Sponsor
sponsor
Nick




PostPosted: Thu Oct 18, 2007 7:00 am   Post subject: RE:Relative Movement

first of all how many directions do u want to be able to move and second what will ur character look like (for many directions it will be hard to create ur own graphics as u will ne to create a new one for each direction)
cpu_hacker4.0




PostPosted: Thu Oct 18, 2007 10:53 am   Post subject: Re: Relative Movement

Yeah...just make a procedure for each different direction that draws what the character will look like, and call the corresponding procedure when you push the key that moves the character in that direction.
Latagore




PostPosted: Thu Oct 18, 2007 11:00 am   Post subject: Re: Relative Movement

I know how to turn it, just not how to turn it back and forth. I want to be able to turn 36 different directions, at least.

EDIT: And since it is from top down, I can just rotate the picture in a picture editing program or simply use the shapes provided in Turing.
Nick




PostPosted: Thu Oct 18, 2007 12:09 pm   Post subject: RE:Relative Movement

ok just make a procedure that activates if the user hits left or right and make it change a varible that tells the computer which direction the user walks and use the Pic.Rotate to change the direction the picture is facing... that should work
Saad




PostPosted: Thu Oct 18, 2007 1:14 pm   Post subject: RE:Relative Movement

You should be using trig to get which angle the player is facing and rotate the picture based on the angle. Also you should use reals for the x,y coordinates and round the coordinates for the pixel locations
Mazer




PostPosted: Thu Oct 18, 2007 1:49 pm   Post subject: Re: Relative Movement

Latagore @ Thu Oct 18, 2007 11:00 am wrote:
I know how to turn it, just not how to turn it back and forth. I want to be able to turn 36 different directions, at least.

EDIT: And since it is from top down, I can just rotate the picture in a picture editing program or simply use the shapes provided in Turing.

If you're going ahead with using external images, why not just use Pic.Rotate to generate images for the other angles?

1) Start the game and load the picture
2) Make copies of the picture using Pic.Rotate for each angle you want in an array
3) Store x,y, and angle for your player (preferrably in some structure)
4) Input: left/right will add/subtract X degrees from the angle, up/down will add SPEED * cos(angle) to x, SPEED * sin(angle) to y
5) Draw picture(angle) at x, y.

EDIT: And there's a bit more to it, that was just the general idea. You want 36 directions? That's reasonable, but make the array of pictures 0..35 and the angle in the range of 0 <= angle < 36, and when you're picking the picture to draw make sure you take the angle div 10. You'll want to go with a real number when doing the trig calculations..
Latagore




PostPosted: Thu Oct 18, 2007 2:58 pm   Post subject: Re: Relative Movement

Mazer @ Thu Oct 18, 2007 1:49 pm wrote:
Latagore @ Thu Oct 18, 2007 11:00 am wrote:
I know how to turn it, just not how to turn it back and forth. I want to be able to turn 36 different directions, at least.

EDIT: And since it is from top down, I can just rotate the picture in a picture editing program or simply use the shapes provided in Turing.

If you're going ahead with using external images, why not just use Pic.Rotate to generate images for the other angles?

1) Start the game and load the picture
2) Make copies of the picture using Pic.Rotate for each angle you want in an array
3) Store x,y, and angle for your player (preferrably in some structure)
4) Input: left/right will add/subtract X degrees from the angle, up/down will add SPEED * cos(angle) to x, SPEED * sin(angle) to y
5) Draw picture(angle) at x, y.

EDIT: And there's a bit more to it, that was just the general idea. You want 36 directions? That's reasonable, but make the array of pictures 0..35 and the angle in the range of 0 <= angle < 36, and when you're picking the picture to draw make sure you take the angle div 10. You'll want to go with a real number when doing the trig calculations..


Unfortunately, I didn't learn sin and cos. But thanks, that helped a lot.
Sponsor
Sponsor
Sponsor
sponsor
jolly50




PostPosted: Sun Nov 11, 2007 7:11 pm   Post subject: Re: RE:Relative Movement

momop @ Thu Oct 18, 2007 12:09 pm wrote:
ok just make a procedure that activates if the user hits left or right and make it change a varible that tells the computer which direction the user walks and use the Pic.Rotate to change the direction the picture is facing... that should work



momop, (or someone else)

can you elaborate more on this...

I'm working on game and I want the character to rotate left or right depending on which way he is facing.

Thanks
Clayton




PostPosted: Sun Nov 11, 2007 7:37 pm   Post subject: RE:Relative Movement

Pretend your screen is a Cartesian Plane. Whenever the left arrow key is pressed, add x to the angle you want to face. If the right key is pressed, subtract x from the angle instead.
jolly50




PostPosted: Sun Nov 11, 2007 7:45 pm   Post subject: RE:Relative Movement

Alright..thats makes a little more sense...

so, how would you right that in a game?

I know you would have procedure's, but what would be inside the procedures?
Mazer




PostPosted: Sun Nov 11, 2007 7:46 pm   Post subject: Re: Relative Movement

You have to consider what kind of camera angle you'll be using.

Fully top down down like Grand Theft Auto? Fine, you can make a picture (or set of pictures for an animated sprite) and use Pic.Rotate to copy it for different angles.

Sorta top down like A Link To The Past? No, you'll need to draw separate sprites for up, down, left, and right (or more if you want 8 degrees). You may be able to copy and flip the left/right sets depending on how lazy you are and how symmetrical the character is.
jolly50




PostPosted: Sun Nov 11, 2007 7:50 pm   Post subject: RE:Relative Movement

I'm using like a side angle view...umm

almost like the original Mario game?!?!? (If that makes more sense)
Mazer




PostPosted: Sun Nov 11, 2007 7:51 pm   Post subject: Re: RE:Relative Movement

jolly50 @ Sun Nov 11, 2007 7:45 pm wrote:
I know you would have procedure's, but what would be inside the procedures?

If you don't know what you would have in a procedure then you wouldn't have a procedure.

Think of it this way:
- you need to know if the user hit a key that corresponds to rotating their onscreen character
- you need to know what angle the character is currently facing
- you need to know how to draw the character when it's facing a given angle (whether it's by drawing a bunch of lines with coordinates you calculate through trig, or by using previously made images as sprites)

How would you want to organize that?

EDIT: Why are you trying to rotate anything in Mario?
jolly50




PostPosted: Sun Nov 11, 2007 7:56 pm   Post subject: RE:Relative Movement

I'm just trying to make it so that when the right arrow key is pressed then Mario would be shown running (different sprite) then if the left arrow key is pressed Mario would be shown running left. stuff like that..
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 2  [ 28 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: