1. RPG objects

OK, so I got some objects in the RPG laying on the floor at x, y coordinates.
Now then what happens when the hero picks them up and puts them in a sack
in a box in his pack in his boat or wherever, or maybe one of the enemies picks
up something and puts it in his whatever. The objects don't have fixed x,y
coordinates
so how do I keep track of where they are?

Somebody must have worked this all out before.

new topic     » topic index » view message » categorize

2. Re: RPG objects

John McAdam wrote:

> OK, so I got some objects in the RPG laying on the floor
> at x, y coordinates.

Fine, you have X and Y coordinates that are associated with the room the
object is currently in. So:

   the[Dagger][INSIDE] = SomeRoom
   the[Dagger][X] = 10
   the[Dagger][Y] = 20

To draw the items, just see what's in the room:

   -- draw the items in the room
   for item = 1 to length( the )
      if the[item][INSIDE] = currentRoom then
         draw( the[item][X], the[item][Y], the[item][IMAGE] )
      end if
   end for

When the object is being held by something (like the player), you don't use
the X and Y coordinates. At most, you just draw the container it's in. So
picking something up:

   procedure pickUp( integer item )
      the[item][INSIDE] = Player
   end procedure

causes it to 'disappear' the next time you draw the room. It's easy to see
if it's in your inventory:

   procedure inventory()
      for item = 1 to length( the )
         if the[item][INSIDE] = Player then
            puts( the[item][NAME] & " " )
         end if
      end for
   end procedure

> Now then what happens when the hero picks them up and puts
> them in a sack in a box in his pack in his boat or wherever,
> or maybe one of the enemies picks up something and puts it in
> his whatever. The objects don't have fixed x,y coordinates
> so how do I keep track of where they are?

You are asking two questions: how do you track what something is inside, and
how do you track the x,y position of that object. Tracking what something is
inside is easy:

   the[Dagger][INSIDE] = Sack
   the[Sack][INSIDE] = Box
   the[Box][INSIDE] = Pack
   the[Pack][INSIDE] = Boat
   the[Player][INSIDE] = Boat

Now, for a Zork sort of game, you do something like that:

   > enter boat
   You are now in the boat. There is a pack here.

   > open pack
   You're not holding a pack.

   > take pack.
   Taken. You are holding a closed pack.

   > open pack
   Opened. The pack contains a closes sack.

   > take sack
   There is no sack in the boat.

   > take sack from pack.
   Taken. You are holding an open pack and a closed sack.

   > open sack
   Opened. You are holding an open pack and an open sack. The
   sack conains a dagger.

   > take dagger from open sack.
   Taken. You are holding an open pack, an open sack and a dagger.

This is the kind of "realism" that grinds adventure games to a halt. But for
a graphical game, there's no issue: you just draw the things that are in the
room, which is the current container. Boats and other vehicles are typically
implemented as special cases here... Anyhoo, when you drop something, you
assign it to the coordinates of where you currently are:

   procedure drop( integer item )
      the[item][INSIDE] = the[Player][INSIDE]
      the[item][X] = the[Player][X]
      the[item][Y] = the[Player][Y]
   end procedure

The next time you draw the room, the item will appear where it was dropped.

-- David Cuny>

new topic     » goto parent     » topic index » view message » categorize

3. Re: RPG objects

Hi John,

----------
> ïÔ: John McAdam <johnmcadam at clix.pt>
> ëÏÍÕ: EUforum <EUforum at topica.com>
> ôÅÍÁ: RPG objects
> äÁÔÁ: Wednesday, November 21, 2001 22:12

> 
> OK, so I got some objects in the RPG laying on the floor at x, y
coordinates.
> Now then what happens when the hero picks them up and puts them in a sack
> in a box in his pack in his boat or wherever, or maybe one of the enemies
picks
> up something and puts it in his whatever. The objects don't have fixed
x,y coordinates
> so how do I keep track of where they are?

I use global or local variables 
for the *similar* tasks, I do not
write the games.

For example:

integer obj_1_x, obj_1_y
integer obj_2_x, obj_2_y
------- and so on

Or

global sequence things
things={{x1,y1},{x2,y2},{x3,y3},{0,0},{0,0},{0,0}}
------- and so on

Then you can just use things[1][1] for
not fixed x coordinate of the 1st thing
and things[1][2] for not fixed y coordinate
of the 1st thing.

You drag this thing with mouse and reassign
the current mouse's coordinates to
that your variable. These variables are
global or local, not private, so they keep
new coordinates outside procedures and
functions.

Local - for include file's procedures and
functions (or for main file's procedures
and functions).
Global - for all after the point of
declaration.
(refman.doc 2.4.2 Scope section)

If you then drag the box full of the things,
you just add box's coordinates to all
things' coordinates.

If me understand your question well,
this method must work.

Regards,
Igor Kachan
kinz at peterlink.ru

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu