|
|
View previous topic - View next topic |
Author |
Message |
Mousie_kebabs Pretty, Pretty Fairy Princess
Joined: 11 Aug 2005 Posts: 12
|
Posted: Sun Aug 14, 2005 11:56 pm Post subject: Simple Rotational Movement |
[quote] |
|
Hey,
I have seen many games on http://www.allegro.cc that use rotational movement (not sure if I am calling it the right thing so I wil explain)
Basically, you use the left and right arrow keys to spin, and up and down to accelerate and deaccelerate in the direction you are facing.
I have no clue how to do this, and was wondering if there is any simple way to go about it. I will be using Allegro, Dev-Cpp and C.
Thanks for any help,
Mousie.
|
|
Back to top |
|
|
DeveloperX 202192397
Joined: 04 May 2003 Posts: 1626 Location: Decatur, IL, USA
|
Posted: Mon Aug 15, 2005 5:24 am Post subject: Re: Simple Rotational Movement |
[quote] |
|
mousie_kebabs wrote: | Hey,
I have seen many games on http://www.allegro.cc that use rotational movement (not sure if I am calling it the right thing so I wil explain)
Basically, you use the left and right arrow keys to spin, and up and down to accelerate and deaccelerate in the direction you are facing.
I have no clue how to do this, and was wondering if there is any simple way to go about it. I will be using Allegro, Dev-Cpp and C.
Thanks for any help,
Mousie. |
okay, I dont have enough time at the moment to write a full-blown tut/ with compilable sourcecode, nor can I cover the rotation.
But, here is how you can get the 'spacey' fly-around controls:
oh, also, I'm typing this in the messagebox for the forum..so dont expect perfect indentation & stuff :D
Code: |
#define MAXIMUM_ACCEL 4
// heres a basic object type
class Simple
{
public:
int position_x, position_y;
int velocity_x, velocity_y;
int acceleration;
Simple(){};
Simple(int x, int y){};
~Simple(){};
// a few functions to 'fly' in space
void Accelerate()
{
if(acceleration<MAXIMUM_ACCEL)
{
acceleration++;
}
};
void Decelerate()
{
if(acceleration>(MAXIMUM_ACCEL*-1))
{
acceleration--;
}
};
void Forward()
{
velocity_y = -acceleration;
};
void Backward()
{
velocity_y = acceleration;
};
void StrafeLeft()
{
velocity_x = -acceleration;
};
void StrafeRight()
{
velocity_x = acceleration;
};
void Update()
{
position_x += velocity_x;
position_y += velocity_y;
};
};
// now somewhere in your project, do:
// center ship respawn vector for a 640x480 screen:
#define SPAWN_SHIP_X 320
#define SPAWN_SHIP_Y 240
Simple* Ship = new Simple(SPAWN_SHIP_X, SPAWN_SHIP_Y);
bool GameQuit=false;
while(!GameQuit)
{
// other stuff..
// move ship
if (key[KEY_ESC])GameQuit=true;
if (key[KEY_A])Ship->Accelerate();
if (key[KEY_Z])Ship->Decelerate();
if (key[KEY_UP])Ship->Forward();
if (key[KEY_DOWN])Ship->Backward();
if (key[KEY_LEFT])Ship->StrafeLeft();
if (key[KEY_RIGHT])Ship->StrafeRight();
// update coordinates
Ship->Update();
DrawShip(Ship->position_x, Ship->position_y);
// blit it...
}
// release memory used.
delete Ship;
|
Sorry for the sloppiness, I'm exhausted, and I don't have the neccessary resources on this computer to create a full working example.
I'll tell ya what, if this dont help, as soon as I get my development computer back up and running, I will write a full example for you, including full rotation & better physics than this very basic velocity-based example. ttyl.
oh, and if you have questions, you can email me at ccpsceo@gmail.com
or post here on this forum. _________________ Principal Software Architect
Rambling Indie Games, LLC
See my professional portfolio
|
|
Back to top |
|
|
Mousie_kebabs Pretty, Pretty Fairy Princess
Joined: 11 Aug 2005 Posts: 12
|
Posted: Tue Aug 16, 2005 8:45 pm Post subject: |
[quote] |
|
Thanks for that, but thats not exacterly what I mean. From reading that I gatherd, that the ship can move up, down, left and right. I mean like Asteroids.
Like, the left arrow key makes the ship SPIN to the left, and the right key makes it spin to the right, and if you press up you move at the angle you are facing.
Mousie.
|
|
Back to top |
|
|
DeveloperX 202192397
Joined: 04 May 2003 Posts: 1626 Location: Decatur, IL, USA
|
Posted: Wed Aug 17, 2005 6:12 pm Post subject: |
[quote] |
|
mousie_kebabs wrote: | Thanks for that, but thats not exacterly what I mean. From reading that I gatherd, that the ship can move up, down, left and right. I mean like Asteroids.
Like, the left arrow key makes the ship SPIN to the left, and the right key makes it spin to the right, and if you press up you move at the angle you are facing.
Mousie. |
I know its not exactly what you meant.
I even told you in my post that it wasn't.
I only covered the flying through space physics of what you wanted.
I didn't cover the rotation.
I'll get you that rotation code as soon as I can. _________________ Principal Software Architect
Rambling Indie Games, LLC
See my professional portfolio
|
|
Back to top |
|
|
Mousie_kebabs Pretty, Pretty Fairy Princess
Joined: 11 Aug 2005 Posts: 12
|
Posted: Wed Aug 17, 2005 6:21 pm Post subject: |
[quote] |
|
Ah, right didn't see that. I must remember to read more carefully next time.
|
|
Back to top |
|
|
DeveloperX 202192397
Joined: 04 May 2003 Posts: 1626 Location: Decatur, IL, USA
|
Posted: Sat Aug 27, 2005 1:07 am Post subject: |
[quote] |
|
mousie_kebabs wrote: | Ah, right didn't see that. I must remember to read more carefully next time. |
I didnt forget about you mousie. :D
I've just been extremely busy lately.
I'll get to the rotation code as soon as I can.
Just letting you know, incase you were wondering if I had forgotten about it.
I'm sorry that I don't have it done yet. :\
ttyl.
Peace. _________________ Principal Software Architect
Rambling Indie Games, LLC
See my professional portfolio
|
|
Back to top |
|
|
Mousie_kebabs Pretty, Pretty Fairy Princess
Joined: 11 Aug 2005 Posts: 12
|
Posted: Sat Aug 27, 2005 11:09 pm Post subject: |
[quote] |
|
No need to apolagise... hmm (Say sorry, not sure about the spelling there :-p)
No need to hurry, I am the one asking the favour so I wont be getting angry if you take your time :)
I might aswell do some research into and try and work it out for myself, seeing I have nothing better to do.
Thanks in advance,
Mousie.
|
|
Back to top |
|
|
Terry Spectral Form
Joined: 16 Jun 2002 Posts: 798 Location: Dublin, Ireland
|
Posted: Sat Aug 27, 2005 11:35 pm Post subject: |
[quote] |
|
You may find this tutorial useful. It starts with the basics of vectors and trig and moves onto some pretty cool effects like rotozooming. I found it very useful when I read up on floormapping recently. _________________ http://www.distractionware.com
|
|
Back to top |
|
|
Mousie_kebabs Pretty, Pretty Fairy Princess
Joined: 11 Aug 2005 Posts: 12
|
Posted: Thu Sep 22, 2005 9:53 am Post subject: |
[quote] |
|
I've got the rotation sorted now.
Thanks for all your help.
Code: |
Car.x += Car.x_vel;
Car.y += Car.y_vel;
Car.radian_angle = ((1.40625 * Car.angle) * -1) + 450;
Car.radian_angle *= 0.017453277;
Car.x_vel = cos(Car.radian_angle) * Car.velocity;
Car.y_vel = -sin(Car.radian_angle) * Car.velocity;
|
_________________ Beep!
|
|
Back to top |
|
|
LeoDraco Demon Hunter
Joined: 24 Jun 2003 Posts: 584 Location: Riverside, South Cali
|
Posted: Thu Sep 22, 2005 10:19 am Post subject: |
[quote] |
|
Out of pure curiousity, where, exactly, did those magic constants come from? If you are quick to respond with "PI", you might consider replacing them with the --- presumably --- higher precision math.h constants; beyond, perhaps, increasing the precision of your application, you'll also note that (A) the use of the constants should entail less key-strokes, and (B) their use also makes the code more readable and maintainable. _________________ "...LeoDraco is a pompus git..." -- Mandrake
|
|
Back to top |
|
|
Mousie_kebabs Pretty, Pretty Fairy Princess
Joined: 11 Aug 2005 Posts: 12
|
Posted: Fri Sep 23, 2005 9:53 pm Post subject: |
[quote] |
|
Well, I nearly had it sorted, just the Allegro angles are all funky and pointless. So I emailed a person who had made a car racing game and asked for a bit of help. And he just gave me those. _________________ Beep!
|
|
Back to top |
|
|
|
Page 1 of 1 |
All times are GMT
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|