HowToAddGrowers: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
imported>Teiv |
imported>Kymara update to include other types of grower and some examples |
||
| (44 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
Adding an grower is as easy as adding an item. To prepare for the tutorial you have to get a copy of stendhal source, you can visit [http://sourceforge.net/project/showfiles.php?group_id=1111&package_id=145790 Sourceforge Project Page] to get a copy. |
|||
= Types of Grower = |
|||
To prepare for the tutorial you have to get a copy of stendhal source, you can visit [http://sourceforge.net/project/showfiles.php?group_id=1111&package_id=145790 Sourceforge Project Page] to get a copy. |
|||
The type of grower we are using for this example is called a 'passive' grower. An coconut grows at a spot, and it looks like an coconut has fallen to ground. The grower image on the ground is the same as the image of the item in your bag and to get it to bag you drag and drop. Or you can eat it directly from ground. Other examples of passive entities which just grow from ground are wood, iron ore, spinach, mushroom and toadstools. These times use ''PassiveEntityRespawnPoint''. |
|||
But there are other types of grower. For example think of the carrots growing in the grain field in semos plains. There, the grower image is a planted carrot. What you see in bag is a whole carrot. To get it from ground to bag you must right click and Pick it, or double click it to get into bag. These types use ''VegetableGrower''. |
|||
Even more advanced is the grain itself. This has several different images as it grows from just planted to ripe. You can only pick grain if you have a scythe. These types use ''GrainField''. |
|||
= Edit food.xml = |
|||
First step is to add the apple to food.xml (since 0.65 the files are splited from items.xml). |
|||
= Passive grower example - the coconut = |
|||
The passive grower is the simplest example which is why we start with coconut. |
|||
== Create item == |
|||
First step is to add the coconut to data/conf/items/food.xml |
|||
This is all explained in the [[HowToAddItemsStendhal]] tutorial. |
|||
| ⚫ | |||
| ⚫ | |||
To be able to add the item to the map you have to make a tile for it. It must have a white background and a black border of 1 pixel around. Each tile has a size of 32x32 pixel, but if you have more than one similar item which you wish to make a grower for, you may line up the tiles. Then give the whole picture of the lined up tiles a generic name to describe all the items in it. For example, a picture with fruits in is then saved to tiled/tileset/logic/item/fruits.png . Later we will refer to this generic name you chose as the ''clazz''.<br> |
|||
| ⚫ | |||
== Edit PassiveEntityRespawnPointFactory.java == |
|||
You have to open ''src/games/stendhal/server/entity/mapstuff/spawner/PassiveEntityRespawnPointFactory.java'' to add the coconut finally to game.<br> |
|||
If you add apple to fruits.png in tileset you have to add apple to: |
|||
<pre> |
<pre> |
||
clazz.contains("fruits") |
|||
<item name="apple"> |
|||
<type class="food" subclass="apple" tileid="-1"/> |
|||
<description>You see a nice shiny apple.</description> |
|||
<implementation class-name="games.stendhal.server.entity.item.Food"/> <attributes> |
|||
<amount value="20"/> |
|||
<frequency value="30"/> |
|||
<quantity value="1"/> |
|||
<regen value="3"/> |
|||
</attributes> |
|||
<weight value="1.0"/> |
|||
<value value="1"/> |
|||
<equipable> |
|||
<slot name="lhand"/> |
|||
<slot name="rhand"/> |
|||
<slot name="bag"/> |
|||
</equipable> |
|||
</item> |
|||
</pre> |
</pre> |
||
When you add a new kind of grower you have to add a new ''clazz'', an example you find in the file itself. After the switch you have to add following code: |
|||
<pre> |
|||
case 0: |
|||
passiveEntityrespawnPoint = new PassiveEntityRespawnPoint("coconut",500); |
|||
break; |
|||
</pre> |
|||
The number after ''case'', is the number of the picture in your tileset file, '''counting from zero for the first tile'''. Between the brackets belong the information for the item you wish to add. The ''500'' means that the item will respawn in 500 turns. (One turn is 300ms on the live server, if you want to work out what that is in real time). |
|||
After this all is done and you can add the item to your map. |
|||
= Vegetable Grower example - a carrot = |
|||
Most of the attributes are explained in the [[HowToAddItemsStendhal]] tutorial. For the grower there one important line at the begining. This line tell the server that this item is a grower: |
|||
To add a vegetable grower which should have a certain image when it is not ripe, and another image when it is ripe, and another image for the item in bag, we look at the carrot example. |
|||
== Create item == |
|||
as above |
|||
== Create image for map editor == |
|||
as above |
|||
== Edit PassiveEntityRespawnPointFactory.java == |
|||
When you come to edit ''src/games/stendhal/server/entity/mapstuff/spawner/PassiveEntityRespawnPointFactory.java'', you again start with saying what file you are using: |
|||
<pre> |
<pre> |
||
clazz.contains("vegetable") |
|||
<implementation class-name="games.stendhal.server.entity.item.Food"/> <attributes> |
|||
</pre> |
</pre> |
||
(say) |
|||
then the next part you make sure you're saying you use a VegetableGrower, for the item e.g. : |
|||
<pre> |
|||
case 1: |
|||
passiveEntityrespawnPoint = new VegetableGrower("carrot"); |
|||
break; |
|||
</pre> |
|||
The case '1' is because it is the number 1 picture in the vegetable.png when we start counting from 0. |
|||
==Create grower images== |
|||
Now we need a picture of the carrot growing, it should be 32x64 with the topmost tile being an image of the unripe seed. We usually make this a blank tile, in fact. The ripe planted carrot is in the bottom most tile. The image must be saved in ''data/sprites/items/grower/'' with the name ''item''_grower.png. For example carrot_grower.png. If you got the name exactly right, that image is automatically used for the growing carrot. |
|||
= More complicated examples = |
|||
| ⚫ | |||
... such as grain field are beyond the scope of this tutorial. However all you need to know should be within the files in ''src/games/stendhal/server/entity/mapstuff/spawner'', which themselves have comments to explain what is happening. Good luck! |
|||
| ⚫ | |||
To be able to add the apple to the map you have to make a tiled for the apple. It must have a white background and a border of 1 pixel around. The picture need a size of 32x32 pixel. <br> |
|||
| ⚫ | |||