Page 1 of 2

Inventory system

PostPosted: Sat Sep 22, 2012 7:11 pm
by MrJolteon
I need an inventory system in my game, and I want it to be similar to, if not the same as, the one in Submachine 6.
However, I don't know how to do that. I'd appreciate it if anyone could help me.

If you need any more information, like what items I'm going to add, send me a PM.
And also, I know that I need to use arrays. I just have no idea how.

Thanks in advance.
-Jolt

Re: Inventory system

PostPosted: Sat Sep 29, 2012 6:03 pm
by MrJolteon
Bump.

Re: Inventory system

PostPosted: Sat Sep 29, 2012 6:07 pm
by skydereign
If you detail the actual mechanics that you want, I can help setup the inventory.

Re: Inventory system

PostPosted: Sat Sep 29, 2012 6:24 pm
by MrJolteon
1: Inventory is shown at the bottom of the screen (I can probably do that myself)
Image
2: When mouse is hovered over inventory, show item name. (Don't need them floating up. Shouldn't be too hard, even for me.)
Image
3: When clicked, make item follow the mouse, and leave a transparent image behind. When this is clicked, place item back in inventory.
Image
4: When used in correct place, remove item and transparent image from inventory, and move the other items towards the center of the inventory (Optional).
Image
5: Pickups are shown in game environment.
Image
6: When pickup is clicked, add item to inventory, remove pickup.
Image
7: I also want an item to be in the inventory when the game starts.
(No screenshot available.)

Take your time.

Re: Inventory system

PostPosted: Sun Sep 30, 2012 3:47 pm
by Fojam
probably using an array for that would be best. And nice graphics btw

Re: Inventory system

PostPosted: Sun Sep 30, 2012 4:09 pm
by MrJolteon
Fojam wrote:probably using an array for that would be best.

That's exactly what I said in the original post.
And nice graphics btw

Those are screenshots from Submachine 6, by Mateusz Skutnik.

Re: Inventory system

PostPosted: Tue Oct 02, 2012 9:44 pm
by schnellboot
how do you drop the picked up item back into the inv?

Re: Inventory system

PostPosted: Tue Oct 02, 2012 10:02 pm
by skydereign
By clicking the transparent item left behind when you choose the item in your inventory. Are you making a demo for MrJolteon? If so I won't bother making one.

Re: Inventory system

PostPosted: Tue Oct 02, 2012 10:06 pm
by schnellboot
I didn't start yet, but I think yours will be more efficient anyway so I will let you make one.
If you're busy I make it.

Re: Inventory system

PostPosted: Tue Oct 02, 2012 11:11 pm
by skydereign
Well, here's a quick version I made in class. It has plenty of room for improvement though. It currently is rather messy, since it only uses one actor to handle all items and item displays, and I hadn't worked out a uniform system beforehand. But this was just the proof of concept. And since schnellboot was offering to make one, I thought I'd post it, perhaps for some inspiration. I won't be able to fix this ged up for a couple of days, so if you want to schnellboot, go ahead and make your own, or work from this one.

Re: Inventory system

PostPosted: Tue Oct 09, 2012 10:50 am
by MrJolteon
Bump.

Re: Inventory system

PostPosted: Sun Oct 28, 2012 4:58 pm
by MrJolteon
I'll just use the one Sky made.
I just have a question about it; How do I make the items not line up in a 3x[y] grid? I want them lined up horizontally.

Re: Inventory system

PostPosted: Sun Oct 28, 2012 9:21 pm
by skydereign
Replace the global code with this. The changes were just the positioning on lines 35, 40, and 41. Before it was using division and modulus to break it into rows of three, now it doesn't.
Code: Select all
#define MAX_INV 9
int inv[MAX_INV] = {0};
int cur_item = -1;
int cur_type = -1;

void
inv_clear ()
{
    int i;
 
    for(i=0;i<MAX_INV;i++)
    {
        inv[i]=-1;
    }
}

#define ITEM_CREATE 0
#define ITEM_MOVE 1

int
inv_add (int type, int action)
{
    int i;
 
    for(i=0;i<MAX_INV;i++)
    {
        if(inv[i]==-1) // empty
        {
            inv[i] = type;
            cur_type = type;
            switch(action)
            {
                case ITEM_CREATE:
                CreateActor("item", "ricon", "view", "(none)",
                        view.width/2-60+i*60, view.height*2/3, true)->inv_pos = i;
                break;
 
                case ITEM_MOVE:
                ChangeParent("Event Actor", "view");
                xscreen = view.width/2-60+i*60;
                yscreen = view.height*2/3;
                inv_pos = i;
                break;
            }
            cur_type = -1;
            return 1;
        }
    }
    return 0;
}

void
inv_remove (int idx)
{
    inv[idx] = -1;
}

Re: Inventory system

PostPosted: Mon Oct 29, 2012 6:15 am
by MrJolteon
Alright, thanks.
+1

Re: Inventory system

PostPosted: Mon Oct 29, 2012 6:35 am
by MrJolteon
One more question,
I added the script to my game, but now items won't move anywhere at all. How do I fix this?
My game's screen resolution is 480x640, in case that's needed.