I’m sort of a newbie to C. I’m writing an RPG using SDL. It’s tiled-
based, but I’ve had trouble getting the map data structure working.
I need only one map at a time, so I defined it as an global variable.
But inside the map. I also have a a tile structure, it just has some
unused flags and a variable representing what tile to use in a tilset.
Inside the map stucture there is a 2d array of tiles, only the dimensions
depend on what map.w and map.h are. Well, it’s not working right. Here’s
what I got so far:
[SNIP]
typedef struct map_t
{
Uint32 flags; /* Not used yet /
int w, h; / Width and Heighth of the map /
tile_t tile[][]; / Tiles inside the map */
} map_t;
typedef struct tile_t
{
Uint32 flags; /* This tile’s flags {Not used yet) /
int image; / Image in the tileset used */
} tile_t;
map_t map;
[UNSNIP]
Thanks.–
Mark A. Nicolosi <markan_at_penguinmail.com>
you say its not working right…whats it doing wrong? perhaps someone can
help you more then eh? (:> ----- Original Message -----
From: markan@penguinmail.com (Mark A. Nicolosi)
To:
Sent: Monday, December 16, 2002 9:23 PM
Subject: [SDL] Map structures
I’m sort of a newbie to C. I’m writing an RPG using SDL. It’s tiled-
based, but I’ve had trouble getting the map data structure working.
I need only one map at a time, so I defined it as an global variable.
But inside the map. I also have a a tile structure, it just has some
unused flags and a variable representing what tile to use in a tilset.
Inside the map stucture there is a 2d array of tiles, only the dimensions
depend on what map.w and map.h are. Well, it’s not working right. Here’s
what I got so far:
[SNIP]
typedef struct map_t
{
Uint32 flags; /* Not used yet /
int w, h; / Width and Heighth of the map /
tile_t tile[][]; / Tiles inside the map */
} map_t;
typedef struct tile_t
{
Uint32 flags; /* This tile’s flags {Not used yet) /
int image; / Image in the tileset used */
} tile_t;
This isn’t SDL related – you may wish to try www.gamedev.net and www.flipcode.com, which have TONS of tutorials on this kind of stuff.
Brian
I’m sort of a newbie to C. I’m writing an RPG using SDL. It’s tiled-
based, but I’ve had trouble getting the map data structure working.
I need only one map at a time, so I defined it as an global variable.
But inside the map. I also have a a tile structure, it just has some
unused flags and a variable representing what tile to use in a tilset.
Inside the map stucture there is a 2d array of tiles, only the
dimensions
depend on what map.w and map.h are. Well, it’s not working right.
Here’s> what I got so far:
[SNIP]
typedef struct map_t
{
Uint32 flags; /* Not used yet /
int w, h; / Width and Heighth of the map /
tile_t tile[][]; / Tiles inside the map */
} map_t;
typedef struct tile_t
{
Uint32 flags; /* This tile’s flags {Not used yet) /
int image; / Image in the tileset used */
} tile_t;
That’s basically wanted I wanted; A way to be able have different sized
maps and I had know idea, how to allocate the map. ThanksOn Tue, Dec 17, 2002 at 04:39:19PM +1100, Gerald Kaszuba wrote:
typedef struct map_t
{
Uint32 flags; /* Not used yet /
int w, h; / Width and Heighth of the map /
tile_t tile[][]; / Tiles inside the map */
} map_t;
I’d personally recommend that you allocate memory for the the tiles
while loading the map, since you may use different sized maps:
typedef struct map_t
{
Uint32 flags; /* Not used yet /
int w, h; / Width and Heighth of the map */
tile_t tile; / Tiles inside the map */
} map_t;
‘tile’ becomes a pointer to the allocated memory like so:
map.tile = malloc((sizeof(tile_t) * map.w * map.h);
Then to access a tile’s image at (x,y) you would use:
map.tile[x + y * map.w]->image
You must free the memory once loaded:
free(map.tile)
Also, you should be defining tile_t before you use it in map_t.
I hope that answers your question!
Gerald
–
Mark A. Nicolosi <markan_at_penguinmail.com>
Is there a way to be able to access different tile’s members (That’s what
it’s called right?) easier, that’s a lot of writing. Thanks again.On Tue, Dec 17, 2002 at 04:39:19PM +1100, Gerald Kaszuba wrote:
Then to access a tile’s image at (x,y) you would use:
map.tile[x + y * map.w]->image
Sorry, but thanks for the links. I looked around GameDev, but couldn’t
find anything but a few links to some tile-based FAQs, that didn’t
help much.On Mon, Dec 16, 2002 at 11:44:58PM -0600, Brian Hook wrote:
This isn’t SDL related – you may wish to try www.gamedev.net and www.flipcode.com, which have TONS of tutorials on this kind of stuff.
Brian
–
Mark A. Nicolosi <markan_at_penguinmail.com>