Post tutorial RSS Altering the ASOD Universe, part 1 (Planets)

The asod universe is initialized from Main.java . Source code is available on the official website and is essential for this tutorial. Get this from asod.dev.java.net before beginning.

Posted by on - Intermediate Client Side Coding

Understanding the code

space[0] = new cosmos(0, 500, 100, "Sigos");
            space[0].setSolarSystem("Ziaac");
            space[0].setPlanetTexture(Toolkit.getDefaultToolkit().getImage(getUrl("test_planet_0000.png")));
            space[0].setDockedTexture(Toolkit.getDefaultToolkit().getImage(getUrl("test_surface_0006.png")));
            space[0].dockable = true;
            space[0].selling = new String[]{"Water", "Food", "Ice", "Biological Data"};
            space[0].sellingPrices = new int[]{10, 12, 5, 400};
            space[0].buying = new String[]{"Electronics", "Clothing", "Geologic Data", "Raw Ore", "Astronomy Data", "Stellar Data", "Stellar Gases"};
            space[0].buyingPrices = new int[]{45, 60, 600, 10, 700, 750, 20};
            space[0].availableShips = new String[]{"Starhawk", "Celeric Class Frigate"};
            space[0].shipCost = new int[]{10500, 2500};
            space[0].faction = "Core"; 

Looks daunting? That code initialized planet Sigos in Ziaac. Here's a breakdown:

space[0] = new cosmos(0, 500, 100, "Sigos");

space is an array that was created earlier in the code. It holds up to 80 objects at the time of release, but you can easily increase the amount. [0] designates the first element in the array, or in this case the first object.

Now for the arguments, the arguments are type, positionx, positiony, and name. Here are the types:
0 - Planet/Station/Base
1 - star
2 - asteroid field
3 - gas cloud
4 - starbridge
5 - NPCs

space[0].setSolarSystem("Ziaac");

This code sets the solar system the object is in.

space[0].setPlanetTexture(Toolkit.getDefaultToolkit().getImage(getUrl("test_planet_0000.png")));

This code tells what the object looks like from space.

space[0].setDockedTexture(Toolkit.getDefaultToolkit().getImage(getUrl("test_surface_0006.png")));

This code tells what the object looks like when docked.

space[0].dockable = true;

This code determines if its dockable, in this case it is.

space[0].selling = new String[]{"Water", "Food", "Ice", "Biological Data"};

This code determines what can be bought from the base. It matches up with

space[0].sellingPrices = new int[]{10, 12, 5, 400};

which determines the prices. In this case Water costs 10, Food costs 12, Ice costs 5, etc etc.

space[0].buying = new String[]{"Electronics", "Clothing", "Geologic Data", "Raw Ore", "Astronomy Data", "Stellar Data", "Stellar Gases"};
 space[0].buyingPrices = new int[]{45, 60, 600, 10, 700, 750, 20}; 

The above code is just like the selling code except with what can be sold to the base.

space[0].availableShips = new String[]{"Starhawk", "Celeric Class Frigate"};

This controls the ships that can be bought there.

space[0].shipCost = new int[]{10500, 2500};

This determines how much the ships cost, the starhawk costs 10,500 funds here.

space[0].faction = "Core";

This determines who the planet belongs to, used to regulate standings based docking.

Those are all the arguments. Now, make some changes and compile/run asod and observe their effects.

ASOD's Method
ASOD's engine reads these from inside the program, and then renders based on the player's current solar system.

Knowing this, you see that the in-game objects are specified from inside the code and the textures are retrieved from inside the jar file.

This allows for portability.

Real world Example
Alrite! Lets add a planet to Ziaac (Note: Adding solar systems is as simple as putting objects in a system and creating a starbridge to the system, this will be discussed later).

1. Using what you know, go to the end of the ASOD universe declarations. Create a new planet, making sure that your using the last object's number +1 in space[], called Tilii.

2. Place the planet in Ziaac.

3. Go use a graphics editor such as GIMP to create the needed textures. ASOD uses a screen resolution of 1024, 768.

4. Plug in the textures. Set the dockability of your planet.

5. Create commodities for buying/selling, remember to match item with price across the corresponding arrays.

6. Add any ships you want. The ships built into the game are the (without "") "Chronos", "Celeric Class Frigate", "Starhawk", "Slasher Miner", "Slasher Frigate", "Core Frigate".

7. Make this a core planet, but the factions built in rite now are: "Core", "Slasher", "No Faction","Merchants Guild".

8. Compile and run. Go to your object and smile.

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.