Ekwipunek bez Tabeli (bez array) - Videoporadnik

1

Tagged

Stats

869 visits, 1,061 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 23 Apr, 2014. Last updated 25 Feb, 2019
Subscribe to Construct videos now

Hello! In this tutorial i will show you how to make an inventory.

Layout

First thing you need to do is to make 2 sprites:

- Item_Slot - Should be 16, 32, 64 (...).

- Item (dropped) - You can make a sword or something.

Make 2 new animations in both sprites. In Item it should be another item and in Item_Slot you need to make animations that shows your Item.

At the end, rename the Item_Slot animations to ID_0, ID_1, ID_2 and in Item ID_1, ID_2.

Variables

For Item_Slot make 3 variables:

- Item_Id - should be 0 on start. This variable holds the item ID in it.

- Slot_id - it's unique id for your slot, first make 4 slots, it will be growing number (1st one Slot_id = 1, 2nd Slot_id = 2 (...) )

- Locked - it should be 0 on start. This variable shows if the slot is locked ( = 1) or not ( =0)

Duplicate your item, and change it's variables to 1 and 2

Before we go to the Event Sheet, add Mouse object.

Event Sheet

When:

- Item created

Do:

Item|Set animation to "ID_" &Item.ID

Add event where:

- When LMB clicked on 'Item'

- Slot.Slot_Id = 1 (1 is for the first slot)

- Slot.Locked = 0

Do:

Slot|Set Slot.Item_Id to Item.id

Slot|Set animation to "ID_" &item.id

Item|Destroy

Slot|Set Slot.Locked to 1

Do the same for every slot you have, the only thing you need to change is Sprite.Id_Slot = (every slot id)

So, if you have 4 slots, copy event 4 times and in first, change Slot_id to 1;2;3;4.

Item debugging

In this engine, there is an bug. If 2 items overlapp themselves and player press them, only 1 item gets into the slot.

This is how i solved it:

When:

- Item is overlapping Item

Do:

Item|Move at angle > Pixels 2 > Angle random(0,360)

It should debug itself quickly.

Dropping

In top-down game, you need to create character sprite.

When:

- RMB clicked on Slot

- Slot.Locked = 1

Do:

Slot|Set animation to "ID_0"

Character| Spawn an object "Item"

Item|Set ID to Slot.Item_ID

Item|Set animation to "ID_" &Slot.Item_ID

Slot|Set Slot.Item_ID to "0"

Slot|Set Slot.Locked to 0

  • 1 Comments

  • Order by
Want to leave a comment? Login or Register an account!