# ANSI C Video Game Item System

I am looking to program my own little Role Playing Game using...

• ANSI C or "standard C", (NOT C++) as my programming language
• The SDL2 development library

I have got a very basic and simple type of game up and going,
(I am learning ANSI C as I develop this hobby game).

I want to implement an item system to the game, so I have been looking through the internet for advice, but it seems like the closest I can get are solutions to C++, Java and other object oriented languages. I can't seem to find a good implementation in C, other than THIS guide, so I thought I could post this question specifically for ANSI C both for me and for others that might be looking to achieve the same goal.

My attack plan is to create a struct to lay out a blue print of what an item is, much like a class in an OOP language. Then, perhaps create an array that defines objects of this type and fills in the details for each item.

This is what I have so far:

#ifndef ITEMS_H_INCLUDED
#define ITEMS_H_INCLUDED

/* Create a structure that represent an item.
@see https://www.tutorialspoint.com/cprogramming/c_structures.htm */
typedef struct Item {
//Unique ID to be used as a reference to the item.
unsigned int id;

//Name of the item.
char name[20];

//Brief description about the item.
char description[50];

//Defines the category of the item; equipment, consumable, etc...
unsigned char type;

//Used for equipment; defines the strength of the weapon/armor.
unsigned char stats[4];

//The X and Y coordinates of the starting point of the sprite.
unsigned int sprite[2];
}item;

#endif // ITEMS_H_INCLUDED


The id-attribute will be used to spawn the item in different locations, such as...

• In the player's inventory
• In a store
• On the floor to be picked up

I'm looking to hard code the item DATA in the source file, but I'm also open for solutions like reading item information from a file, and such.

• Can you clarify, what is your question? Did you encounter a specific problem in making your system so far that we can help you solve? Is there a specific gap or missing feature in the system as you've written it thus far that you need help implementing? Sep 9, 2019 at 22:59
• I have an issue conceptualizing it and I'm not sure which approach/implementation is the best, most effective way and which is most scalable. Seeing that C is not an OOP language, how would I translate an item system written in OOP languages like C++ or Java, into a language like C? I hope this clarifies my question. Sep 9, 2019 at 23:18
• What specific benefit do you observe in OOP implementations that you need help adapting to C? Sep 9, 2019 at 23:23
• Defining the different items and creating an instance of the item. Sep 9, 2019 at 23:40
• Cool. Now what distinguishes those item types from one another? We see your type field — is that not sufficient for what you need? How have you tried instantiating an item so far? We really need to see what your requirements are and where you've hit a wall chasing them before we can help you find the appropriate door in that wall to get to where you want. Sep 9, 2019 at 23:42