Computer Science Canada Relative Movement |
Author: | Latagore [ 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. |
Author: | Nick [ 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) |
Author: | cpu_hacker4.0 [ 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. |
Author: | Latagore [ 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. |
Author: | Nick [ 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 |
Author: | Saad [ 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 |
Author: | Mazer [ 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.. |
Author: | Latagore [ 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. |
Author: | jolly50 [ 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 |
Author: | Clayton [ 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. |
Author: | jolly50 [ 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? |
Author: | Mazer [ 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. |
Author: | jolly50 [ 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) |
Author: | Mazer [ 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? |
Author: | jolly50 [ 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.. |
Author: | Clayton [ Sun Nov 11, 2007 7:58 pm ] |
Post subject: | RE:Relative Movement |
Then it's not an issue of rotating the sprite, it's just of flipping it left/right. Try looking up Pic.Flip() (or something similiar) in the Turing Help file. F10 is your friend. |
Author: | jolly50 [ Sun Nov 11, 2007 9:41 pm ] | ||
Post subject: | RE:Relative Movement | ||
...ok I looked it up... but what if I already have the sprites made up? I already have a Mario that looks left, right, crouch, jump etc. Is there a way to just write something like:
... or something similar to that? |
Author: | Mazer [ Sun Nov 11, 2007 9:45 pm ] |
Post subject: | RE:Relative Movement |
Okay, yeah. |
Author: | jolly50 [ Sun Nov 11, 2007 9:46 pm ] |
Post subject: | RE:Relative Movement |
There is way?!?!?!? When I try this it doesn't work |
Author: | Mazer [ Sun Nov 11, 2007 9:56 pm ] |
Post subject: | RE:Relative Movement |
That could mean anything. You really need to elaborate to get a good answer. What did you try? What didn't work? Here are my thoughts: pic1? pic2? These are horrible names. I wanted to say "No" and leave it at that but I suppose this could actually work. How about replacing "pic1" with "currentFrame" and "pic2" with "facingRight". It's actually going to be more complicated for animation but I refuse to give a shit right now. Do your game logic to figure out which frame should be rendered (stored in the variable called currentFrame), and then at the end of your loop draw currentFrame. |
Author: | jolly50 [ Sun Nov 11, 2007 10:01 pm ] |
Post subject: | RE:Relative Movement |
sorry about not elaborating... i tried running the above code i put... the game runs, but the character doesn't change images at all... thats why it doesn't work I will look up the currentFrame.. |
Author: | Nick [ Sun Nov 11, 2007 10:10 pm ] |
Post subject: | RE:Relative Movement |
well what image aru u using with Pic.Draw? if u are changing current image to equal left or right yet passing facing left throgh Pic.Draw... theres a problem |
Author: | jolly50 [ Mon Nov 12, 2007 7:30 am ] |
Post subject: | RE:Relative Movement |
I'm not using any Pic.draw for my sprites... (Just for the fireball I use Pic.Draw) I have just been using Sprite.New for all my sprites |
Author: | Mazer [ Mon Nov 12, 2007 8:15 am ] |
Post subject: | RE:Relative Movement |
The sprite module is old. From what I remember it hasn't been in use since 3.1 or something. You might have mentioned that. Try using Sprite.Change. |
Author: | jolly50 [ Mon Nov 12, 2007 12:59 pm ] | ||||
Post subject: | RE:Relative Movement | ||||
Ok, I looked up Sprite.Change... the syntax for it is like:
would I write a code like this?...
...what I don't understand is, for the SpriteID would I put the currentframe sprite, then in the PicID put the runningright sprite... or would I have the new sprite id and picid... When i try this code it doesn't change the sprites |
Author: | Mazer [ Mon Nov 12, 2007 1:24 pm ] |
Post subject: | RE:Relative Movement |
Minimize the amount of extra junk. When you have something like "mariorunright" it implies you'll have something like "mariorunleft" as well. In that case, why bother changing the picture for the sprite? Have a single sprite. Maybe call that currentFrame like before. Now if the character is facing right do Sprite.ChangePic(currentFrame, RunningRight) where RunningRight is a picture you loaded. Not a sprite. |
Author: | jolly50 [ Mon Nov 12, 2007 8:35 pm ] |
Post subject: | RE:Relative Movement |
what do you mean by: "where RunningRight is a picture you loaded. Not a sprite." Then how would I load my RunnungRight? Would I use something like Pic.Draw? |
Author: | Mazer [ Mon Nov 12, 2007 11:31 pm ] |
Post subject: | RE:Relative Movement |
Pic.Draw is used to draw a picture. Pic.FileNew is used to load a picture. |