To do this tutorial you need version 1.1.6 or above and ExtraForYouAreNotAlone 1.0.8 or above. So make sure you update your project before you continue.
First we need to preare items for plants
Objects>objConstants>Game start
globalvar ITEM_DATA; ITEM_DATA = 11;
This will hold out plant data
Objects>Pause Menus>objInventory>Create
slots = ds_grid_create(invWidth*invHeight, 12);
This will allow the inventory to store the extra data
Scripts>Inventory>InventoryAdd
ds_grid_set(objInventory.slots, _emptyCell, ITEM_DATA, _array[11]);
We need to add the inventory script to handle the extra "DATA" info.
Scripts>Inventory>ItemExtractArray
_newArray[ITEM_DATA] = ds_grid_get(_grid, _index, ITEM_DATA);
Scripts>Inventory>ItemClear
ds_grid_set(_grid, _index, ITEM_DATA, -1);
Scripts>Inventory>ItemInsertArray
ds_grid_set(_grid, _index, ITEM_DATA, _array[ITEM_DATA]);
Scripts>Inventory>ItemMatch
&& (_item1[ITEM_DURABILITY_MAX] == _item2[ITEM_DURABILITY_MAX]) && (_item1[ITEM_DATA] == _item2[ITEM_DATA]);
Scripts>Items>ItemGetDefine
/// ItemGetDefine(name, type, count, object, icon, description, spriteSet, effect, value, durability, durability max, data);
_item[ITEM_DATA] = argument11;
Scripts>Items>ItemGetRubbishSword
_item[ITEM_DATA] = "";
Scripts>Items>ItemGetAwesomeSword
_item[ITEM_DATA] = "";
Scripts>Items>ItemGetGoldenSword
_item[ITEM_DATA] = "";
Scripts>Items>ItemGetLifePotion
_item[ITEM_DATA] = "";
Scripts>Items>ItemGetBerries
_item[ITEM_DATA] = "";
Scripts>Items>ItemGetShield
_item[ITEM_DATA] = "";
Scripts>Items>ItemGetEmpty
_item[ITEM_DATA] = -1;
Objects>objChest>Create
item = ItemGetDefine("NO NAME", -1, 1, -1, -1, "NO DESCRIPTION", -1, 0, 0, -1, -1, "");
Objects>objChest_Once_RoomEditor>Create
item = ItemGetDefine("NO NAME", -1, 1, -1, -1, "NO DESCRIPTION", -1, 0, 0, -1, -1, "");
Ok. Now we got a data holder for the plants. So we can now add extra info in every inventory item.
So now we need to create a Hoe so we can prepare the land and create fields.
Duplicate sprSwordWoddenSouth to sprHoeSouth
Edit
Transform>Resize canvas>Height 100px (set position south - keep aspect)
Transform>Rotate>90 (clockwise)
Transform>Resize canvas>Height 74px (set position north - keep aspect)
Transform>Shift>Horisontal 36 Vertical 15
Ok. First "Hoe" animation done.
Create a group named Hoe. So we can collect all there.
And move the animation there.
Duplicate sprSwordWoddenNorth to sprHoeNorth
Transform>Resize canvas>Height 100px (set position south - keep aspect)
Transform>Rotate>90 (c-clockwise)
Transform>Mirror/Flip>Flip vertically
Transform>Resize canvas>Height 74px (set position south - keep aspect)
Transform>Shift>Horisontal -26 Vertical -6
Origin Y 74
Duplicate sprSwordWoddenEast to sprHoeEast
Transform>Resize canvas>Height 100px (set position south - keep aspect)
Transform>Rotate>90 (c-clockwise)
Transform>Resize canvas>Height 74px (set position north - keep aspect)
Transform>Shift>Horisontal -9 Vertical 6
Duplicate sprSwordWoddenWest to sprHoeWest
Transform>Resize canvas>Height 100px (set position south - keep aspect)
Transform>Rotate>90 (clockwise)
Transform>Resize canvas>Height 74px (set position north - keep aspect)
Transform>Shift>Horisontal 9 Vertical 6
Ok. Animations done.
We now need a script that set the sprites.
Duplicate SetWeapon_WoodenSword to SetWeapon_Hoe
_weaponArray[NORTH] = sprHoeNorth;
_weaponArray[SOUTH] = sprHoeSouth;
_weaponArray[EAST] = sprHoeEast;
_weaponArray[WEST] = sprHoeWest;
Duplicate sprWeapon6 to sprHoe_Object
Edit
Remove one end and we got a hoe.
Our hoe.
Duplicate sprHoe_Object to sprHoe_Inventory
Edit.
Transform>Stretch 160x160
sprHoe_Object
Transform>Stretch to 32x32
Duplicate objRubbishSword to objHoe
Set sprite sprHoe_Object
As you know new objects need to be added in the array.
scr_Multiplayer_OBJECT_ARRAY_Enviroment
Enviroment_Object_array[46]=objHoe;
Duplicate ItemGetRubbishSword to ItemGetHoe
_item[ITEM_NAME] = "Hoe";
_item[ITEM_OBJECT] = objHoe;
_item[ITEM_DESCRIPTION] = "Farm the land";
_item[ITEM_ICON] = sprHoe_Inventory;
_item[ITEM_SPRITESET] = SetWeapon_Hoe;
Sorry. Did an error there. One sec.
SetWeapon_Hoe
objPlayerCharacter>parCollectible_Weapons
case objHoe: item=ItemGetHoe(); break;
scr_Multiplayer_ON_PLAYER_REQUEST_OBJECT_GRANTED
case objHoe: var item=ItemGetHoe(); // Set data fom pickup item item=scr_Multiplayer_Data_Get(data_,item); InventoryAdd(item); break;
Ok. Now we create the field.
Duplicate sprGrass to sprField
Edit.
Image>Colorize>16
Duplicate sprBushCut to sprFieldPlant
Image>Colorize>16
Duplicate objGrassSnow to objField_Once
sprField
Parent none
Create event:
hide = false;
Remove the above
scr_Multiplayer_Init_Enviroment();
scr_Multiplayer_ONCE_Enviroment();
Step event:
Remove // Randomly spawn a gem drop
Remove // Create an instance to show the stump
_inst.sprite_index = sprFieldPlant;
scr_Multiplayer_OBJECT_ARRAY_Enviroment
Enviroment_Object_array[47]=objField_Once;
Ok. Its time for the Carrot.
Duplicate sprCarrots to sprCarrot
Transform>Crop>0
Remove some in the bottom
These will be the carrots we pickup.
Duplicate sprCarrot to sprCarrot_Inventory
Transform>Stretch>Width 160 (Keep aspect)
Transform>Resize canvas> (Keep aspect off) height 160 (Position center)
This one is for the inventory.
Duplicate objBerries to objCarrot
Sprite to sprCarrot
In scr_Multiplayer_OBJECT_ARRAY_Enviroment
Enviroment_Object_array[48]=objCarrot;
Duplicate ItemGetBerries to ItemGetCarrot
_item[ITEM_NAME] = "Carrot";
_item[ITEM_OBJECT] = objCarrot;
_item[ITEM_ICON] = sprCarrot_Inventory;
In objPlayerCharacter>Collision parCollectible_Berries
case objCarrot: item=ItemGetCarrot(); break;
scr_Multiplayer_ON_PLAYER_REQUEST_OBJECT_GRANTED
case objCarrot: var item=ItemGetCarrot(); // Set data fom pickup item item=scr_Multiplayer_Data_Get(data_,item); InventoryAdd(item); break;
We will now create the seeds.
Duplicate sprBerries to sprSeeds
Edit image and Colorize partical Hue 64
Duplicate sprBerries_Inventory to sprSeeds_Inventory
Edit image and Colorize partical Hue 64
We now need to be able to equip the seeds so we can put them in the ground. So the seeds need to be a "weapon"
Duplicate object objHoe to objSeeds_Carrot
sprite to sprSeeds
In scr_Multiplayer_OBJECT_ARRAY_Enviroment
Enviroment_Object_array[49]=objSeeds_Carrot;
Duplicate script ItemGetHoe to ItemGetSeeds_Carrot
_item[ITEM_NAME] = "Carrot Seeds";
_item[ITEM_OBJECT] = objSeeds_Carrot;
_item[ITEM_DESCRIPTION] = "Grows to carrots.";
_item[ITEM_ICON] = sprSeeds_Inventory;
Seeds dont have durability.
_item[ITEM_DURABILITY] = -1;
_item[ITEM_DURABILITY_MAX] = -1;
And now we need to add the plant data. So the plant can grow.
_item[ITEM_DATA] = "Plant;6;sprCarrot_Plant;objCarrotBush";
Plant Tell us that its plant data
6 minutes to grow
sprCarrot_Plant is the grow animation
objCarrotBush Is the object that is created when it has fully grown
In objPlayerCharacter>Collision parCollectible_Weapons
case objSeeds_Carrot: item=ItemGetSeeds_Carrot(); break;
scr_Multiplayer_ON_PLAYER_REQUEST_OBJECT_GRANTED
case objSeeds_Carrot: var item=ItemGetSeeds_Carrot(); // Set data fom pickup item item=scr_Multiplayer_Data_Get(data_,item); InventoryAdd(item); break;
Ok. Now for the plant object.
Duplicate sprField to sprCarrot_Plant
But first disable Discord.
Duplicate sprField to sprCarrot_Plant
Edit the sprite and remove the old image.
Make some green dots
Add empty
Not there.
No.
Add empty
Make a small green plant
Copy it and paste a new
Scale it to 140
Copy it and paste a new
Scale it to 140
Copy it and paste a new
Scale it to 140
Copy it and paste a new
Scale it to 140
This will be our grow animation.
Duplicate objField_Once to objPlant_Once
Set sprite to sprCarrot_Plant
Set depth to -1
It must draw on top the field.
Create event:
// Stop Animation
image_speed=0;
// Check grow timer
alarm[0]=1;
Add alarm 0 event and add a code block
// Check plant
scr_Multiplayer_Check_Plant();
// Set new timer
alarm[0]=(room_speed*40)+irandom_range(0,room_speed*20);
I forgot to add the data for the check plant script.
multiplayer_data
multiplayer_data is a variable that all objects have in this engine.
scr_Multiplayer_OBJECT_ARRAY_Enviroment
Enviroment_Object_array[50]=objPlant_Once;
Ok. We will now create the carrot "Bush".
It goes like Field>Seed>Plant>Bush>Carrot
Duplicate sprGrass to sprCarrot_Bush
Draw a orange circle
copy last subimage from sprCarrot_Plant and paste it over sprCarrot_Bush
Our full grown carrot "Bush"
Duplicate objForestBush to objCarrotBush
sprite to sprCarrot_Bush
Step event
Remove // Randomly spawn a gem drop if (irandom(100) < dropChance) { }
We want it to always drop a carrot.
Change objBerries to objCarrot in both places
Remove // Create an instance to show the stump var _inst; _inst = instance_create(x, y, objTemporary); _inst.sprite_index = sprForestBushStump;
scr_Multiplayer_OBJECT_ARRAY_Enviroment
Enviroment_Object_array[51]=objCarrotBush;
Now we will assemble it.
objPlayerCharacter>Step>// Attacking
We must provide our weapon item data to the strike object.
_newStrikeMask.item_data=objPlayer.equippedWeapon;
_newStrikeMask.item_data=objPlayer.equippedWeapon;
Now we can use the item data in the strike object.
objPlayerStrike>Animation end
// Farming
scr_Multiplayer_Do_Farming(sprHoeNorth,sprHoeEast,sprHoeSouth,sprHoeWest,item_data[ITEM_DATA],objField_Once,objPlant_Once);
So we assign out hoe states. Provide the plant data. And set the Field object and the Plant object.
Now we need to add a hoe and a seed in the room editor so we can test it
Ok. Lets run and test it.
We changed out world so we must create a new one.
Ok. Lets equip the hoe and make some fields.
Ok. Now we equip our seeds and drop one in a field.
Ok. Lets see it grow. Remember it take 6 minutes. But lets fast forward some.
It grows!!!
Ok. Prepare yourself.
Congrats. It a carrot.
Ok. Lets see if we can harvest it.
Carrots!!!
Không có nhận xét nào:
Đăng nhận xét