Author Topic: Star Maps  (Read 823 times)

Offline AltarofScience

  • Level 12
  • *
  • Posts: 90
  • Reputation: +1/-0
    • View Profile
Star Maps
« on: October 12, 2011, 09:08:32 PM »
I want to make a universe map for my game.
How would I go about that?
I need multiple galaxies, well actually a number of galaxies determined by a set number.
Each galaxy needs a number of star systems, probably a random number between 2 set numbers.
And each system needs a number of planets, also a random number between 2 set numbers.
I assume I stick the code in while loops like:

$ugal=10;
$gal=0;
while($gal<$ugal){
\\code to position galaxy
$v=rand();
$usys=$v
$sys=0;
while($sys<$usys){
\\code to position system
$r=rand();
$uplan=$r
$plan=0;
while($plan<$uplan){
\\code to position planet and create stats
$plan++;
}
$sys++;
}
$gal++;
}


Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Star Maps
« Reply #1 on: October 13, 2011, 05:02:59 AM »
You know, I thought it was me who had an ancient coding style, never thought I could see a linear coding style in XXI century :D Use functions.

So, now once my grumpy complaining quota is met, time for the solution :)

Code: [Select]
function createPlanet($gid,$sid,$pid) { sql("INSERT planet ..."); }
function createSystem($gid,$sid) {$amount=rand(1,12); for($n=0;$n<$amount;$n++) createPlanet($gid,$sid,$n); }
function createGalaxy($gid) {$amount=rand(20,50); for($n=0;$n<$amount;$n++) createSystem($gid,$n); }
function createUniverse() {$amount=rand(5,10); for($n=0;$n<$amount;$n++) createGalaxy($n); }

createUniverse();

Offline BlackScorp

  • Level 15
  • *
  • Posts: 123
  • Reputation: +6/-0
    • View Profile
    • Cruel Online
Re: Star Maps
« Reply #2 on: October 13, 2011, 05:20:22 AM »
hm.. about 25 years ago, there was a Game on C64 about planets and space. this game had close to unlimited Universe with Galaxys, Starsystem und planets. to save each location of planets and Galaxys and Starsystems they used a math function. But i still dont know which math algorythm it was. but you could get all systems in a galaxy with somethink like this displaySystems($galaxy_id,$seed); then you could display all Planets with displayPlanets($star_id,$seed) and also all galaxys with disaplayGalaxies($seed); depends on the seed youre able to have Parallel Universe.

if you would know that algorythm you dont had to save your universe in a database
« Last Edit: October 13, 2011, 05:30:25 AM by BlackScorp »

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Star Maps
« Reply #3 on: October 13, 2011, 05:32:19 AM »
Elite/Frontier. As for seed you don't need to save it, just make it static $seed=1; You will get identical results each time you randomize it.

Code: [Select]
function createPlanet($gid,$sid,$pid) { $resource=rand(1,5); echo("Planet: #$pid, resource:$resource"); }
function createSystem($gid,$sid) {$amount=rand(1,12); for($n=0;$n<$amount;$n++) createPlanet($gid,$sid,$n); }
function createGalaxy($gid) {$amount=rand(20,50); for($n=0;$n<$amount;$n++) createSystem($gid,$n); }
function createUniverse() {$amount=rand(5,10); for($n=0;$n<$amount;$n++) createGalaxy($n); }

srand(1);
createUniverse();
Of course that one is very primitive and not usable for performance reasons.

Offline BlackScorp

  • Level 15
  • *
  • Posts: 123
  • Reputation: +6/-0
    • View Profile
    • Cruel Online
Re: Star Maps
« Reply #4 on: October 13, 2011, 05:35:48 AM »
Elite/Frontier

yep... and still belief that calculate the position of the planets is better than generating random numbers and save it to the database

Offline AltarofScience

  • Level 12
  • *
  • Posts: 90
  • Reputation: +1/-0
    • View Profile
Re: Star Maps
« Reply #5 on: October 13, 2011, 08:33:39 AM »
Actually I already wrote a code to generate the coordinates of galaxies and systems, the main problem I have now is making galaxies have shapes, like spirals?
I actually know how to make basic shapes, be putting limits on the max x and y coords based on the radius of the galaxy. And I know how to make a circle with arms, using tall skinny triangles, but I would like, for aesthetic reasons, to have a galaxy that looks like a real spiral one.  

Also, another thing is, I do not know how to display the galaxy in the browser so that it is more than a bunch of coordinates, but actually has a shape. I did some googling and it sorta looks like I may want to use something called an image map? But I do not know how to do this.

As for functions, I guess they could save some work, and I know how to write them, but writing the way I do is also really easy and fast for me. Its like functions are people who touch type with all their fingers, but I can type just as fast with 2 fingers, and still don't have to look at keyboard. It scares people actually when I type, which is good for some lulz, because they don't expect it to be possible to type so fast without formal touch typing.

Also, I know what Elite is, although I've never played it, I play a lot of 4x games, so you hear about early games a lot, especially from 4x hipsters.

I really do need to save the stuff in a database though, the game is actually not too much like elite. it is multiplayer and there is a lot of interaction with planets. People colonize them and such.
« Last Edit: October 13, 2011, 08:45:38 AM by AltarofScience »

Offline BlackScorp

  • Level 15
  • *
  • Posts: 123
  • Reputation: +6/-0
    • View Profile
    • Cruel Online
Re: Star Maps
« Reply #6 on: October 13, 2011, 08:44:16 AM »
http://en.wikipedia.org/wiki/Archimedean_spiral

with this you can generate your x/y coordiantes, you save the Coordiantes in array and print it out with json_encode php function. now you will have a JSON Array in JavaScript. now yare able to add Divs and give them Positions

Offline AltarofScience

  • Level 12
  • *
  • Posts: 90
  • Reputation: +1/-0
    • View Profile
Re: Star Maps
« Reply #7 on: October 13, 2011, 08:48:04 AM »
http://en.wikipedia.org/wiki/Archimedean_spiral

with this you can generate your x/y coordiantes, you save the Coordiantes in array and print it out with json_encode php function. now you will have a JSON Array in JavaScript. now yare able to add Divs and give them Positions

Yes that is helpful, but i also need to be able to do other things. You know like, a galactic core with a variable arms, like the milky way.

also, is there a way i can use php to do it? I would rather not need to learn json syntax and what not. so far i have avoided any language but php and sql in my game, and although i might use js or jquery if people decide the interface is not pretty enough, i am trying to stay away from non-php as much as possible.
« Last Edit: October 13, 2011, 08:50:40 AM by AltarofScience »

Offline BlackScorp

  • Level 15
  • *
  • Posts: 123
  • Reputation: +6/-0
    • View Profile
    • Cruel Online
Re: Star Maps
« Reply #8 on: October 13, 2011, 09:49:22 AM »
but you know if you make as much as possible on the client side, you dont need a power server. everythink what you need for just displaying i would make it as JavaScript

Offline AltarofScience

  • Level 12
  • *
  • Posts: 90
  • Reputation: +1/-0
    • View Profile
Re: Star Maps
« Reply #9 on: October 13, 2011, 10:02:58 AM »
Ugh, well, the game will have max 100 players, its a private invite only game server, not for monies. Would that be a huge load on the server? I really don't wanna deal with js/jquery/ajax/json stuff.
How would I generate the image in php? I guess I could make a black background and each system location would be a white dot. But it seems like that would require a huge image, since coordinates go from -1mil to 1mil for x and y and -200k to 200k for z.

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Star Maps
« Reply #10 on: October 13, 2011, 10:11:15 AM »
Draw a black/white picture of a spiral map. Then generate sector coordinates and map them to the image. If X,Y is on black it means coordinate is wrong, regenerate the sector. If it is on white it stays.
Also, I would make more chances for the sector near the center of the galaxy (based on x,y distance from the center). The simplest would be "for each unit of distance there is 1% chance for regenerating the sector".

Offline AltarofScience

  • Level 12
  • *
  • Posts: 90
  • Reputation: +1/-0
    • View Profile
Re: Star Maps
« Reply #11 on: October 13, 2011, 10:52:45 AM »
how would i map them to the image?

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Star Maps
« Reply #12 on: October 13, 2011, 11:36:39 AM »
Read each pixel and put in a 2D array?
You need to do it only upon setup so performance is irrelevant.

Offline AltarofScience

  • Level 12
  • *
  • Posts: 90
  • Reputation: +1/-0
    • View Profile
Re: Star Maps
« Reply #13 on: October 13, 2011, 12:20:16 PM »
if i was okay with using dot clusters as galaxies, reason: lazy, how would i create a grid and put my coordinate pairs on that grid? or just a black backdrop, like, i have a black page, and I assign an area as the center, 0,0 of the image. then i put the coordinates on the image based on the "center".

so 0,0 and then I want to create a white dot at: -55467, 67891. a white dot represents a star system. white dots will be clickable, but first i need to figure out how to make them appear in the right spot on my image.

i'm sorry if i am dumb, or confusing, i am mostly trying to make a game with particular rules and i started working on it on August 31, and by started I mean i started reading html and css tutorials. the only other time i did any web page stuff is on my neopets page when i was 11, so on like php freaks, a lot of people complain that i don't know basic stuff.

Offline BlackScorp

  • Level 15
  • *
  • Posts: 123
  • Reputation: +6/-0
    • View Profile
    • Cruel Online
Re: Star Maps
« Reply #14 on: October 13, 2011, 12:45:09 PM »
test somethink like this out:

<form method="POST" action="">
<input type="image" src="map.jpg" alt="Map">
</form>

check out what you will get ;) print_r($_POST);

Offline AltarofScience

  • Level 12
  • *
  • Posts: 90
  • Reputation: +1/-0
    • View Profile
Re: Star Maps
« Reply #15 on: October 13, 2011, 01:40:17 PM »
yes, that would print an image, but how would i get my points connected to it.

Offline BlackScorp

  • Level 15
  • *
  • Posts: 123
  • Reputation: +6/-0
    • View Profile
    • Cruel Online
Re: Star Maps
« Reply #16 on: October 13, 2011, 04:47:01 PM »
didnt you tested it? you will get x and y mouse coordinates where you klicked in

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Star Maps
« Reply #17 on: October 13, 2011, 06:06:46 PM »
"GD"

Offline AltarofScience

  • Level 12
  • *
  • Posts: 90
  • Reputation: +1/-0
    • View Profile
Re: Star Maps
« Reply #18 on: October 14, 2011, 11:32:52 AM »
I made a map, the only slight issue is that while the universe map and galaxy 0 maps are properly centered, the galaxy 1 and galaxy 2 maps do not center properly.

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal