Differences

This shows you the differences between the selected revision and the current
version of the page.


wmebook:ch6 2007/12/07 14:31 wmebook:ch6 2008/01/10 12:04 current
Line 1: Line 1:
====== 6. Working with inventory ====== ====== 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.+In this chapter we’ll focus on the work with 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. +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 another junk player achieves ultimate goals like saving world etc. 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. 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.
Line 16: Line 16:
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. 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+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
{{wmebook:inventory.jpg|}} {{wmebook:inventory.jpg|}}
-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. +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 placeholders for our items.
So with this in mind, let’s look at the inventory.def file located in interface folder. So with this in mind, let’s look at the inventory.def file located in interface folder.
Line 158: Line 158:
**AMOUNT_OFFSET_Y** - the Y offset in pixels of the amount label relative to item's position **AMOUNT_OFFSET_Y** - the Y offset in pixels of the amount label relative to item's position
-So now we are able to define our inventory and individual items and let’s look at the way, how you can connect items with the actual game.+Now we are able to define our inventory and individual items and let’s look at the way, how you can connect items with the actual game.
As I’ve written already, there are two ways, how to approach inventory – **Global** (one inventory for the whole game) and **Actor based** – each actor has his own inventory. As I’ve written already, there are two ways, how to approach inventory – **Global** (one inventory for the whole game) and **Actor based** – each actor has his own inventory.
Line 201: Line 201:
</code> </code>
-Not very logical game play, eh? But it shows the point. Sometimes it’s good to destroy item altogether for example if we want to combine two items to get one or if we use the item and don’t want player to have the possibility to reacquire it. For this we have in stock the DeleteItem method.+Not very logical game play, eh? But it shows the point. Sometimes it’s good to destroy item altogether for example if we want to combine two items to get one or if we use the item and don’t want player to have the possibility to reacquire it. For this we have in stock the **DeleteItem** method.
Before we look more into items handling, let’s look at the item in the inventory. We know, that in items.items there’s a script assigned to it. This is the file, which takes care of the item when it gets to the inventory. It’s not limited to a single scene as our previous script was and this way we should count with the fact that the player would try to use this item anywhere in the game. It would be really painful to create individual responses for each hotspot so basically we want to have unique responses for logical things and some generic “It doesn’t make any sense to use the book here.” for the rest of the hotspots. Before we look more into items handling, let’s look at the item in the inventory. We know, that in items.items there’s a script assigned to it. This is the file, which takes care of the item when it gets to the inventory. It’s not limited to a single scene as our previous script was and this way we should count with the fact that the player would try to use this item anywhere in the game. It would be really painful to create individual responses for each hotspot so basically we want to have unique responses for logical things and some generic “It doesn’t make any sense to use the book here.” for the rest of the hotspots.
Line 290: Line 290:
</code> </code>
-Now what we’ve done is that we’ve created another actor named Sally which uses the same graphics as a Molly, but it’s entirely different person. We have her reference stored in the global variable actor2 and we’ve placed her in our Room scene. Next thing we’re going to do is that we’re going to implement a neat character switching.+Now what we’ve done is that we’ve created another actor named Sally which uses the same graphics as a Molly, but it’s entirely different person. We have her reference stored in the global variable //actor2// and we’ve placed her in our Room scene. Next thing we’re going to do is that we’re going to implement a neat character switching.
If player clicks on Molly or Sally (without an inventory item selected) game gives control to the second actor. If player clicks on Molly or Sally (without an inventory item selected) game gives control to the second actor.
Line 322: Line 322:
</code> </code>
-Now we could use single file for this, but later on it pays off to have those separated when we want to perform different tasks with each actor.+Although we could use single file for this, later on it pays off to have those separated when we want to perform different tasks with each actor.
-Now run the game and note that we can now switch between actors by simple Left Click on them. +Now run the game and note that we can switch between actors by simple Left Click on them.
-So now having this done, we’ll return to our inventory and try some interactions. First what we need to do is open our trusty **game.script** and actually code in the generic logic of inventory item interaction. What we want to achieve is that whenever we left click with a selected item on a hotspot, we try to call the corresponding method named by an item name. So if we click with a book, we’d try to call a method “Book” of the target entity.+Having this done, we’ll return to our inventory and we try some interactions. First thing what we need to do is open our trusty **game.script** and actually code in the generic logic of inventory item interaction. What we want to achieve is that whenever we left click with a selected item on a hotspot, we try to call the corresponding method named by an item name. So if we click with a book, we’d try to call a method “Book” of the target entity.
This can be easily done by modifying the Left Click event to read: This can be easily done by modifying the Left Click event to read:
Line 382: Line 382:
Again it’s very simple logic. If actor variable containing the active actor is set to the clicked actor, we read the documentation or we say the other line. The event “book” is called because we modified the **game.script** to do this. Clear as mud? Again it’s very simple logic. If actor variable containing the active actor is set to the clicked actor, we read the documentation or we say the other line. The event “book” is called because we modified the **game.script** to do this. Clear as mud?
- 
Now we have one illogical thing. It doesn’t matter who picks up the book, both have the book in the inventory. This is the global inventory approach and it’s ok if we have one actor on the stage. But as we’ve introduced two actors, we should separate their inventories. Now we have one illogical thing. It doesn’t matter who picks up the book, both have the book in the inventory. This is the global inventory approach and it’s ok if we have one actor on the stage. But as we’ve introduced two actors, we should separate their inventories.
 
wmebook/ch6.1197034266.txt.gz · Last modified: 2007/12/07 14:31 by metamorphium
Recent changes RSS feed Creative Commons License Driven by DokuWiki