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
Printable View
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
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.
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:
Something like that.Code: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");
}
}