oahda
|
|
« Reply #4 on: June 07, 2010, 11:56:09 PM » |
|
Game Maker is object-oriented. Take advantage of this fact. In general, two main classes (in Game Maker called objects) should be enough; Inventory and Item. Inventory will be a class actually containing items, and Item will be a superclass to derive any individual types of items from.
The Inventory class should contain functionality for drawing the inventory and manipulating it in any way the user should be allowed to. This might include deleting items or putting them in a different order, and hovering over them to see a description.
The Item class could be pretty simple to begin with. Assign it a few variables; title, description, attack, defense and level, for example, depending on what you want. Another handy property would be a variable containing the allowed amount of items of a certain kind to stack in one inventory slot. The sprite of each item should be the icon to display in the inventory. The base class Item needs no sprite.
As you want to create new types of items, derive them from the original Item class, setting it as its parent, and assign a sprite. Then set the proper values for the variables you previously declared in the base class; you even have the opportunity of randomisation, as previously suggested.
Now, move back to the Inventory class. This class should contain an array, in which items are to be put. When drawing the inventory, loop through the elements of this array, and properly place them into the inventory grid, retrieving the sprite member variable from each item. If you have decided for item stacking to be present, also print out the amount of items in the current stack in the loop; this should also be handled by an array in the Inventory class.
Now check the position of the mouse. If it's hovering over one of the icons (do a simple rectangle check), draw a box displaying the title, description, required level and anything else you want in there, also retrieved from the member variables of the instance in the current index of the array in your iteration. If you've discovered that the mouse is hovering over the icon, you also want to check for clicks for interaction; a left click might do one thing with the item, and a right click might do another thing. If the icons should be able to be moved around, holding down the mouse should obviously allow you to drag this icon around until the mouse is released, and something else should happen depending on where the player decided to let go of the mouse button.
I hope this can point you in the right direction and shed some light upon your confusion.
|