PHP & MSQL help

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
Phantom Coder
Posts: 45
Joined: Sun Sep 19, 2010 6:06 am

PHP & MSQL help

Post by Phantom Coder »

Hi everyone,

has anyone played Astro Empires? I was wanting to make a galaxy the way they set it up. The have the game galaxy in a grid that is 10 x 10 100 squares from 00-99 depending on what server your on it might be A for alpha, B Beta A00 - A99. and inside each square you can click on that and it will give you another grid of 100 squares. 00-99 and if you click inside one of the squares again you get like a solar system with planets and asteroids, gas giants ect ect.

some squares are empty, some just have junk like dust storms, if i remember right.

How could I go about doing something like that.

Also to go from lets say A10 to A11 it would take about a month to go between them unless you have the tech for warp drive and then it can take 2 or 3 days real time.
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: PHP & MSQL help

Post by Jackolantern »

The map would just be how you set up the database. The individual star systems would have their own entry in the database with a unique ID, maybe as rows in a Star System table. Then you have an intermediate table for each cell on the master map. Each cell would have its own unique ID to speed up queries, but the best way to keep up with them would be through 2 columns: xValue and yValue, or something similar. As you can guess, these would be the X and Y values that determine where on the map each cell is. Each cell entry would have a column that holds the ID of the star system it contains, or perhaps 0 if it is empty.

This way, you can programmatically move players around on the map. Each player could have their own X and Y values stored in their table that represents the star system they are in. If they want to travel "north" to the next star system, you can just subtract 1 from their Y value (assuming the typical computer coordinate system where 0,0 is in the upper-left corner), and you now have the new star system coordinate.

As far as real-time waits on travel, just add code to the movement functionality (possibly when they confirm that they want to travel) to add their information to a traveling table, or however you want to work it out, including how much time their movement will require as well as the real-world time they initiated the travel. That way when they try to do something else, you can first check their their status to see if they are traveling (you could perhaps add a flag to their database entry if they are traveling or not to check). If they are traveling, you can grab all of their traveling info from that table, see how long the travel takes and compare that to when they started traveling to see if they should be done now or not. If they are, you could possibly send them to another page that maybe introduces them to the new star system, outlines the resources they used traveling, or whatever. And if they are not done traveling, you could stop them, or handle that whatever way your design dictates.

Hope this helps! :cool:
The indelible lord of tl;dr
User avatar
Phantom Coder
Posts: 45
Joined: Sun Sep 19, 2010 6:06 am

Re: PHP & MSQL help

Post by Phantom Coder »

Here is a few screenshots of what i would like to try to duplicate: I think they are using a multidimensional array to hold the data.

Galaxy View:
Image

The region and galaxy drop down menu:
ImageImage

Zoomed in view of the galaxy:

1x zoomed
Image

2-3 times I lost track my mouse was messing up:
Image

4x zoomed
Image

5x Final zoom level I think:
Image

System View:
Image

Planet View:
Image

I have been raking my brain on how to set up the database, and it seems they only make a new galaxy when the game get over crowed like adding a galaxy 2 twice a month or so.

Thanks jackolantern for the response maybe these images will let you or anyone else to see visually what i was trying to duplicate. Maybe someone would make a tutorial on it. my php mysql skills is still in the infantry state.
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: PHP & MSQL help

Post by Jackolantern »

I don't really know how multidimensional arrays would help here. Arrays are loaded in RAM, and are thus volatile and gone once the page has been executed. The galaxy, star system and other data is stored in a database. Having a table for the galaxy cells that contain IDs of individual star systems are basically the non-volatile, database-backed version of multidimensional arrays. You could add however many layers onto this as you want. If you wanted a galaxy map with cells, with each cell representing a solar system that itself has cells and each of those cells being a planet, for example, you could have each galaxy cell contain a reference to a solar system table (probably named with the X, Y coordinates in its name for programmatic reference), and that solar system table has X, Y coordinates to hold a reference to each planet. So you can see how you can make this as deep as you want. :)

The screenshots don't really change anything as far as I can tell. Maybe if I played it for a while I would see something I am missing, but for the most part they are really just graphics. From what I understand, the underlying map mechanism is not very complex. Probably just X, Y galaxy entries with references to lower-level solar system database entries. Is there something else I am missing? :cool:
The indelible lord of tl;dr
User avatar
Phantom Coder
Posts: 45
Joined: Sun Sep 19, 2010 6:06 am

Re: PHP & MSQL help

Post by Phantom Coder »

I been trying to figure out hot to get the html and css to create a grid of 10 x 10 and I searched and searched and searched for any help on making a grid in php, css, html and I find nothing I know this must see to you guys that this is pretty simple and I am a dumb ass LOL. but we all got to start from somewhere. I do not even know if I should start with making the page display an empty 10 x 10 grid first or not.
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: PHP & MSQL help

Post by Jackolantern »

Sometimes you have to take a trip back into the old days lol. Yes, there are nifty CSS Tables coming in the future, but oddly enough, Internet Explorer is the only one who has them implemented correctly. So just make a good 'ole HTML table. For example, here is a 3 x 3 grid where each cell has a hypothetical cell image that would be easy to programmatically access in PHP:

Code: Select all

<table>
        <tr>
            <td><img src="1x1.jpg"</td>
            <td><img src="1x2.jpg"</td>
            <td><img src="1x3.jpg"</td>
        </tr>
        <tr>
            <td><img src="2x1.jpg"</td>
            <td><img src="2x2.jpg"</td>
            <td><img src="3x3.jpg"</td>
        </tr>
        <tr>
            <td><img src="3x1.jpg"</td>
            <td><img src="3x2.jpg"</td>
            <td><img src="3x3.jpg"</td>
        </tr>
    </table>
The indelible lord of tl;dr
User avatar
Phantom Coder
Posts: 45
Joined: Sun Sep 19, 2010 6:06 am

Re: PHP & MSQL help

Post by Phantom Coder »

HAHAHA.... Thanks I thought tables was bad in these days and age. of css3 and html5. I knew how to do it with tables. Thanks Jack you made me chuckle this morning when I read your post.

EDIT
So let me get this straight to see if I am understanding what I want to do.
I have to make a php routine that would generate the above galaxy image slice it up in 100 squares and store them somewhere. and store the data in a database(lol what ever data that would be) j/k. I guess it would have to store the location , player data, or what ever it is out of my league as of now, but wont be in the near future.
Then create a table that would populate the page with the sliced up images and create a link to the appropriate page?

when i look at the source of the webpage I am trying to learn how they did it it not in tables though and each star is their own separate image, and they have 5 levels of zoom which has a different grid image. normal is 45px x 45px grid squares and the max zoom is like 128px x 128px grid and they have a image for each grid zoom to let you know which sector that is moused over. As you zoom in you can see another 10 x 10 grid inside the bigger grid. Also each star image is it own link to it own solar system inside the galaxy.

If I was to use tables, how would I get around the pixelation of the images when you zoom in on them. or even have the table cell be divided into 100 cells inside of each cell. This is where my quandary lies.
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: PHP & MSQL help

Post by Jackolantern »

Tables are just not to be used for full website layouts, but maps fall into their real usage of tabular data. For tabular data, nothing beats a table!

I am not sure how they did it without tables. They may be using a shiv to provide compatibility with CSS tables. Not worth it in my opinion.

As far as the zoom, you would really need to have different resolutions of the images and swap them as needed with Javascript, since there is no way that I know of scale bitmaps without pixelation in the browser. Even some of the more advanced RIA platforms like Silverlight require you to have different resolutions to support its zoom feature.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: PHP & MSQL help

Post by hallsofvallhalla »

you can have a multi-deminsion without the array

Take for instance this pretty grid I drew up(i would print this and put it on the wall :P)

Image

you can store the galaxy in several ways

1. Data view

Row/Column/Depth

In the photo there are two C4 R4 locations, Depth 1, and Depth2, So its D1, C4, R4

2. Grid View

have a table for each depth, then a field for each row to get the column data and separate by periods. Each number means what you want to display, 1 = nothing, 2 = blue planet, 3 = orange planet, 4 = space station So row 4 would look like 1.1.4.2.1.1
so Row 4 Column 4 would be a blue planet. Now lets say you want only a 3 column grid view, as in the player can only see three squares, you chop off or rather only query everything but the squares around R4C4, or 4.2.1 and pull the rows around him. You could store a 40,000 locations with 4 depths, with would be 4 tables with only 100 rows with a text field of 200 characters.
User avatar
Phantom Coder
Posts: 45
Joined: Sun Sep 19, 2010 6:06 am

Re: PHP & MSQL help

Post by Phantom Coder »

I guess I really have a lot to learn because I guess it more complicated than I first thought. LOL could I request you do a tutorial series on this subject?
Post Reply

Return to “Advanced Help and Support”