Thread: Game inventory

  1. #1
    Registered User
    Join Date
    Feb 2009

    Game inventory

    ok im a newb at c programming so im a little lost on how to make an in game inventory screen

    if anyone has tutorials or other idea that will help push me in the right direction that would be helpful

    thanks again for reading and replying

  2. #2
    Registered User
    Join Date
    Feb 2009
    Do you already have the inventory? If not, a linked list would be one way to store the data, and it is easy to traverse.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Or even just an array. That would put an upper limit on the number of items in your inventory, of course, but that shouldn't be too much of a problem for users of your game.

    A linked list might seem better, because you'll probably be doing a lot of insertions and deletions in the inventory, but an array would be easier to implement and might make more sense, too. If you given each inventory item a letter, for example, the user wouldn't want these letters to keep changing; so just clearing an element in the inventory array would be sufficient. You wouldn't have to shift all of the other items over to fill the empty spot.

    Other than that, once you have an inventory, displaying it should be as easy as looping through each element in the inventory and displaying that element. For example, with an array:
    struct item_t {
        char *name;
        int type;  /* for internal use; -1 means unused */
    item_t inventory[MAX_ITEMS];
    /* ... */
    int i;
    for(i = 0; i < MAX_ITEMS; i ++) {
        if(inventory[i].type != -1) {
            printf("%d %s\n");
    Something like that.
    Last edited by dwks; 02-27-2009 at 02:23 PM.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. Open-source Game Project
    By Glorfindel in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 03-24-2009, 01:12 AM
  3. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  4. Inventory, text game
    By Blizzarddog in forum Game Programming
    Replies: 60
    Last Post: 02-10-2003, 03:23 PM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM