Eye of the Beholder Clone: How to organize data?

Started by BrightBulb, Thu 23/08/2012 17:45:04

Previous topic - Next topic

BrightBulb

Hello everyone,

I was wondering what would be the best way to script an Eye of the Beholder / Lands of Lore / Dungeon Master Clone. Specifically I have following questions:

1. How would I organize the data from a maze? That is where walls, items or monster are? Some sort of struct array?

2. What would be the best way to display the dungeon? Using a room with a lot of objects for all the walls, items and monsters?

Thanks.


Khris

1. I'd use an array of structs, yes.
One instance per grid square, with fields for the walls. Either just north and west, with the two other walls being defined by the squares to the south and east, or, if you want to have walls that don't have the same texture on both sides, four wall fields for each.

I'd make everything else (monsters, items) separate, those simply store their current grid coordinates. And get displayed if they are among the visible squares. But you could also add a monster field holding the index of the monster currently occupying the square.

2. I'd probably draw everything to the room background. You could use objects and change their sprite or turn them on and off, it's a matter of taste I guess. Since the number of objects is limited to 40, you might be cutting it close though. And combining objects and drawn stuff is tricky because of the pseudo 3D.

BrightBulb

Thanks for the answer.

1. I'm not quite sure what you mean with instance (I'm really no expert on struct or arrays) and fields.

2. Forgot about the object limit and 40 is most probably not enough.

Khris

A struct is a template for storing data. Think of it as a form that is filled out, with fields that hold data. Each filled out form is an instance.
So each grid square's data is stored in a single instance, which each specific piece of information being stored in a field.

Example:
Code: ags
// header

enum WallTypes {
  eWallRock,
  eWallBrick,
  eWallForest
};

struct square {
  int NorthWall, WestWall;
  int Ground;
  int Monster;
  int Item;
};

import square s[1000];

// main script
square s[1000];
export s;

This creates an array from s[0] to s[999]. You can now access the fields like this:
Code: ags
// inside function that loads map
  s[0].NorthWall = eWallRock;
  s[0].EastWall = eWallForest;
  s[3].Monster = eMonsterGoblin;

Of course you wouldn't set each field individually but iterate through s[] and use map data in text format or something like that to set them.

Since every square has an x and y coordinate, you need to define the width and height of the map at the start of the map data. Then you can convert x;y into index i and back:
Code: ags
int GetIndex(int x, int y) {
  return y*width + x;
}

int GetX(int i) {
  return i%width;
}

int GetY(int i) {
  return i/width;
}

SMF spam blocked by CleanTalk