Re: A89: Re: Re: Tile-based Game Engine in C
[Prev][Next][Index][Thread]
Re: A89: Re: Re: Tile-based Game Engine in C
more like this:
char tilearray[] = {0,0,15,3,10,...}; /// Level-data
int sometile0[] = { 0x...};
int sometile1[] = { 0x...};
...
int* translationtable[] = {sometile0,sometile1,sometile2,...};
then you have a for-loop that steps through tilearray, reading its value,
translateing the value in tilearray to a sprite-pointer with
translationtable, and then writeing that sprite to screen at a fixed
position depending on where in tilearray you are.
the reason for a separate translationtable is if you have a large level,
then it is a waste of space to put sprite-pointers in the level-data since a
pointer is 4 bytes. With this setup you can "only" have 256 different
sprites in one level though (which in fact is quite a lot.). (or more
correct, 256 on the same screen since you _could_ change the
translationtable when you move around, but that would probably be quite
messy, so a setup with int:s in tilearray would probably be better then. But
thats up to the programmer do decide.)
I have never implemented something like this in C though...
///Olle
From: "Joshua Coyne" <antgage@apk.net>
>
> in C would it be something similar to:
>
> int sometile1[] = { 0x...};
>
> char tilearray[] = {&sometile1,...};
>
> Olle Hedman wrote:
>
> > You don't save the whole tiles in the array.
> > What you do is you have an array with say a byte that represents which
tile
> > number to display.
> > then you have a pointerlist to the different sprites. if you find say
the
> > number 32 in your array, you take the sprite located at the place the
32:nd
> > pointer in the list points out and writes it to screen at the position
> > designated to that place in the array.
> > This way you change the list when you change levels, and reuse the same
> > sprite at multiple places witout dubbling the data.
> >
> > ///Olle
References: