Translations of this page:

This is an old revision of the document!
—-

6. Working with inventory

In this chapter we’ll focus on work with the inventory. As there will be a lot of issues to cover, we should hop straight to it.

First let’s clarify, what inventory is. One of the typical adventure game aspects is the ability to collect various junk lying around in the game world and by using it on other junk player achieves ultimate goals. Also sometimes you might want to strike back and use the inventory junk (referred as items) on something in the game world.

WME has excellent support for inventory including combining items and item stocking. WME also supports multiple inventories in case you’d have more than one main actor or you’d want to include trading in your game.

Inventory has two main definition files:

  1. Inventory box definition - defines the place where your inventory will be stored. It consists of rectangular areas and scrollbars used to navigate in your inventory.
  2. Inventory items definition – defines individual items and attached scripts so you can set up necessary interactions.

Both files are assigned in the Project Manager and we’ve discussed them earlier but to recap, they’re inventory.def file and items.items file. Of course you can name it however you like, but let’s stick for now with the items at hand.

Before we start with that, copy somewhere contents of the resource for chapter 5. It consists of the blank project we discussed earlier and we’re going to eventually build a simple game on top of those files.

So let’s start with a inventory box definition. We’re going to base our interface upon the image inventory.bmp located in data/interface folder. The image looks like that

It’s very simple, yet we can easily explain the inventory mechanics on it. Before we dive into the definition file itself, we should look at the image. We see two red rectangles, which we won’t see in our game as they will serve only as a place holders for the buttons used for scrolling inventory left or right. Then we see 10 square parts which will be place holders for our items.

So with this in mind, let’s look at the inventory.def file located in interface folder.

INVENTORY_BOX 
{ 
  ITEM_WIDTH = 65 
  ITEM_HEIGHT = 65

Those are dimensions of individual items and they correspond to dimensions of the individual squares in the inventory box.

SPACING = 10

This defines how far apart are individual squares (items). This value is in pixels.

  SCROLL_BY = 1

When player clicks on previous or next button, the items rotate left or right respectively. This value specifies how many items will be rotated.

  HIDE_SELECTED = TRUE

If player selects an inventory item, it disappears from the inventory box (to prevent using item on itself for example).

AREA { 30, 12, 770, 77 }

Area defines the inventory item area. It’s relative to the inventory window, not to the screen. So even if you wanted to display inventory at the bottom, those values will still remain the same. Now these values are X,Y coordinates of the upper-left corner and X,Y coordinates of the lower-right corner of the inventory window. In other words, coordinates (30,12) refer to the upper-left corner of first inventory item and (770,77) refers to lower-right corner of 10th inventory item.

  EXCLUSIVE = FALSE

If set to true, player can’t do anything else until he closes the inventory window again.

Now comes the definition of the window itself. Note that our next chapters will deal with windows and controls much more extensively, but we’ll cover here what needs to be explained.

  WINDOW 
  { 
    X = 0 
    Y = 0 
    WIDTH = 800 
    HEIGHT = 90

We start with defining window position and dimensions. Those numbers are absolute, so unlike the Area, they refer to the screen position. Our window will be positioned at the top of the screen and will be 800 pixels wide and 90 pixels tall. If we wanted to position this window to the bottom of the screen, we’d simply change Y to 510 (600 – 90).

IMAGE = "interface\inventory.bmp"

The background image to be used for the inventory – we’ve seen it above already.

 
    BUTTON 
    { 
      TEMPLATE = "ui_elements\template\but.button" 
      NAME = "prev" 
      TEXT = "<" 
      X = 0 
      Y = 0 
      WIDTH = 30 
      HEIGHT = 90 
    } 
 
    BUTTON 
    { 
      TEMPLATE = "ui_elements\template\but.button" 
      NAME = "next" 
      TEXT = ">" 
      X = 770 
      Y = 0 
      WIDTH = 30 
      HEIGHT = 90 
    }



 
wmebook/ch6.1196945395.txt.gz · Last modified: 2007/12/06 13:49 by metamorphium
Recent changes RSS feed Creative Commons License Driven by DokuWiki