Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Circular Sprite Movement

Author
Message
Pixelator
16
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 9th Jun 2010 06:15 Edited at: 9th Jun 2010 06:16
Hello, all. I'm starting a rather large project, considering the only things I've programmed in a year and a half were robots, and I've already stumbled into trouble. I'm starting a space trading game, where the player can travel between many planets in several solar systems, buying and selling trade goods. The solar system view has a star in the center with the planets in the system "orbiting", or rather revolving in set circles, around it. My question is what would be the most efficient way to have the planets' sprites revolve around the star?

Everything is more than the sum of its parts.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Jun 2010 06:34
Hello,

Some cartesian to polar coordinate math should do the trick:



Enjoy your day.
Pixelator
16
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 9th Jun 2010 06:47 Edited at: 9th Jun 2010 06:54
Oh wow. Thats... quite much more involved than I had expected. I hate to sound ungreatfull, especially after dissappearing for so long then suddenly poping back up with problems, but is there perhaps a slightly simpler way? my worry is that the computations will eat FPS with all else going on at the same time: Piloting the ship within the system, other AI ships (?)

edit:

Oops! I apologise, I just now gave a good hard look at the code, then decided it would be easier if I put my glasses. COrrect me if im wrong, but is everything before the last little chunk just creating the Planet and Sun graphics?

Everything is more than the sum of its parts.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 9th Jun 2010 07:21 Edited at: 9th Jun 2010 07:23
Yes, only the three lines in the main loop are doing any work.
I thought I'd clean it up a bit. I have coding OCD at the moment, I can't look at a piece of code without tidying it up!


Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Jun 2010 09:39 Edited at: 9th Jun 2010 09:43
Quote: "Oops! I apologise, I just now gave a good hard look at the code, then decided it would be easier if I put my glasses. COrrect me if im wrong, but is everything before the last little chunk just creating the Planet and Sun graphics?"

Yeah, Obese87 organized the code a bit so it's easier to follow (thank you Obese )

The actual orbit math is:

ang = wrapvalue(ang+1)
x=xrad*cos(ang)+centerx
y=yrad*sin(ang)+centery

Where
ang is the current angle of rotation
xrad is the x radius of the elliptical orbit
yrad is the y radius of the elliptical orbit
centerx is the x position of the point to rotate around
centery is the y position of the point to rotate around

Enjoy your day.
Pixelator
16
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 9th Jun 2010 18:47
Ah, thankyou very much Latch, that'll be just the ticket

Everything is more than the sum of its parts.

Login to post a reply

Server time is: 2024-03-29 09:15:07
Your offset time is: 2024-03-29 09:15:07