Placing object in room and disabling walkable area underneath it [SOLVED]

Started by rbaleksandar, Fri 10/09/2010 00:40:54

Previous topic - Next topic

rbaleksandar

Hi, guys.

 I looked in the manual and didn't find nothing about this so I hope you can give me at least some kind of a hint how to solve the problems I mention below.

 Imagine that we have a room (AGS room) that represents a room (like a room in a house with walls, windows, door etc.). Since we want to recreate a 'real' room, we have let's say 4 walls and floor. The floor is of course a walkable area. At the beginning we have nothing in this room therefore the character can walk all over the floor. Now let's say our character has an object in the inventory that I as a player want to place on the floor (a chair, table, sofa etc.). A table (or whatever other piece of furniture) is considered to be an obstacle for our character. Therefore when we place it on the floor, the character should not be able to go through it but only to go around it. My problem is that I don't know how to do that. I want to disable a certain RANDOM part of the walkable area representing the floor when I place some kind of furniture there, so that the character will be forced to go around it or not at all (if it's placed in a corner of the room for example and there's no way to go around this obstacle). Besides - correct me if I'm wrong - there is no way to dynamically create (with dynamically I mean creations of object when running the game) walkable/non-walkable areas after the game is compiled and runs and there's no way to make a certain part of a walkable area non-walkable. I looked at the properties of an object too but couldn't find anything that may make it impassable for the character(s). So I guess it's walkable areas or nothing.


 The other thing is that there seems to be no way to dynamically create objects too. The only possible solution I came so far is to make n sets of objects limited to a certain amount. For example we have a set of 20 chairs, a set of 3 tables, a set of 2 TV-sets etc. For example PLAYER 1, who plays the game, wants to put 3 chairs somewhere in the room but PLAYER 2 wants to use 15. As you can see the method I came up with has two great disadvantages - predefining the amount of a certain objects limits the player if he/she wants to use more of it AND it also can become dead weight (if I predefine the set of chairs to have 10 pieces in it but the player actually uses only 3).

Cheers!
I am a mighty pirate. Arrrrgh!

GarageGothic

For the walkable area issue, you can use Object.BlockingHeight and Object.BlockingWidth to make a rectangular area around the object non-walkable.

Now, as for dynamic object creation, you *could* simply create a pool of existing but hidden objects in each room to draw from, and whenever the player drops an item, you assign the appropriate graphic to one of the objects, make it visible and put it at the correct coordinates. You would, however, need to keep track of its name in a separate String array since you cannot change Object.Name at runtime.

HOWEVER, a different solution could be to use Characters instead of Objects for the items. This would first of all only require you to create as many Characters as there are inventory items in the game, and Character.Name *can* be changed at runtime in case there's not a finite amount of each item (e.g. you don't need a Character name "table" to put a table, just get an unused character and name it that along with changing his graphic. Keep in mind that if you use this approach you'll have to assign all the item graphics as frames in the view editor and then use Character.LockViewFrame to set the graphic of each item in-game. Character also supports the BlockingHeight/BlockingWidth properties, BTW.


rbaleksandar

Thanks a lot! :)

  I still can't understand the thing with the characters though.  ::) Let's say I have created 10 spare characters. How exactly will I be able to put 20 chair-characters in the room? You say that I have to simply use an unused character and change it's identity, and after that just use it as an object. How exactly does this work? I mean if the player wants to put 20 chairs but I have only 10 characters in reserve than what?  :P The number of characters and their creation has to be specified before the build process of the game (that is - before playing it). So it's still limited... Am I missing something here?  ???
I am a mighty pirate. Arrrrgh!

GarageGothic

Well, as I said "require you to create as many Characters as there are inventory items in the game" meaning individual items, so 20 chairs means 20 characters, sure. If you want an infinite number of items available to the player, of course its no solution.
But since characters can be placed in any room it makes more sense to have a pool of, say, 100 characters total than creating 40 objects (max amount) for every room just in case the player decides to fill it with furniture. Also, with a bit of scripting you can reuse characters between rooms and store their positions and graphics in a struct in the room script so they can be assigned again when the player enters that room.

The other alternative would be writing your own pathfinder and use DrawingSurface functions to draw the furniture on a full-screen sprite. Then player/item collisions could either be checked using GetPixel on the sprite or using rectangular checks against a struct storing the coordinate/size of the furniture in the room.

rbaleksandar

  Thanks again. I'll try the character-thing. I've decided to limit the number of objects the player can place on the floor. I mean, it's better this way. After all the room (and the floor that goes with it) represents a finite space so there is only place for finite number of things that you can place in there. I'll simply have to decide how big each object (character) has to be in order to give the impression that you can place infinite let's say pieces of furniture but there is simply not enough space to do that. ;)
 I'll also check the DrawingSurface functions.


Cheers. :)
I am a mighty pirate. Arrrrgh!

SMF spam blocked by CleanTalk