That line of code is very ineficient but saves me the memory required for a
seperate map for collision detection. I would not recomend using it as it
is not the best way. But....
Basicaly link x and y are screen relative so they are converted to
world relative coordinants by multiplying world x(what screen link is in not
his actual worldx) times screen width(in pixels) plus link x. This gives
absolute x. I then divide by the width of a tile(16) and that gives my the
tile x coordant. Then the world y times screen height plus link y to get
absolute y. Divide it by tile height(16) to get tile y. Then my index into
the map array is map[ tile_x + tile_y * WorldWidthInTiles]. This gives me
the tile number that i am in. I then compare this against all the tiles i
can walk on and if it is not one i can walk on i restore the old x and y.
This method only checks one point so i add 8 to x and 9 to y to make the
point in the center of link. This way i can still walk halfway into most
tiles. But that looked better to me. This should be a little easier to
follow.
tile_x = ((link.x+8) + worldx * SCREENWIDTH) / 16; //the divides can be
converted to shifts so not too bad
tile_y = ((link.y+9) + worldy * SCREENHEIGHT) / 16;
temp = OverWorld[tile_x + tile_y * WORLDWIDTHINTILES];
SCREENWIDTH and SCREENHEIGHT are in pixels and are the width and height of a
single screen. Since my world only shows one screen at a time this was
easier for me to implement. If your world scrolls then you should allready
have your sprites in world x and y coordants then you just need to divide by
the width/height of your tiles to get what tile you are in. You should
either use a seperate array to store what tiles you can walk on or arrange
your tiles so that all the tiles you can walk on are at one end (you could
use
if(temp > BigestWalkableTile)
{ //cant walk here}
Adding more complex interactions with the background will almost certainly
require another layer to your map that holds just that data.
hoped this helped.
-dovoto
-----Original Message-----
From: Steven Bruce [mailto:kinetic_creationz@...]
Sent: Wednesday, May 30, 2001 1:12 PM
To: gbadev@yahoogroups.com
Subject: RE: [gbadev] Re: Block Tiles using 256 Colours and BG Mode 0
Yep, that's what I thought. :)
Dovoto you did that little Smelda game didn't you?
I've been having a look through it and decided I'd
like to copy your way of Collision Detecting. However
the real killer line is not very well explained in
comments:
temp =
OverWorld[((x+(16*x/240)+8)/16)+((y+(16*y/160)+9)/16)*16*(ScreensW)+
(16*(world_y*ScreensW)*11+16*(world_x))];
Could you please explain how you came up with this
extremely complicated looking algorithm please. I've
been pulling my hair out trying to write my own but it
just isn't working out at all. I'm doing
sprite-background collision detection for a 32x32
sprite and 32x24 size background that scrolls left and
right. Maths was never one of my strong subjects :o)
Steve B.
--- "Rogers, Jason L. ET2 (CVN71)"
<rogersjl@...> wrote: > Block 0 for
both background data and map is the same
> location in memory. If
> you are putting both tile data and the map at block
> zero you are overwriting
> one of then. It is best to place your map data at
> one end and your tile
> data at the other end.
> -dovoto
>
> -----Original Message-----
> From: kinetic_creationz@...
> [mailto:kinetic_creationz@...]
> Sent: Wednesday, May 30, 2001 11:48 AM
> To: gbadev@yahoogroups.com
> Subject: [gbadev] Re: Block Tiles using 256 Colours
> and BG Mode 0
>
>
> --- In gbadev@y..., Jimmy Mårdell <yarin@a...>
> wrote:
> > At 14:36 2001-05-30 +0000, you wrote:
> > >Hi
> > >
> > >A fairly straight forward question here. Can you
> have 4
> Backgrounds
> > >being shown at the same time using 1 256 colour
> palette for each
> > >background or can you only have 2x256 colour BGs.
> Surely you can
> have
> > >4 256 BGs being shown at the same time can't you.
> >
> > Yes, but "1 256 colour palette for each
> background"? All backgrounds
> > share the same 256 colour palette.
>
> Yeah, Sorry I didn't mean to say that. I meant 1 256
> colour palette
> for all backgrounds.
>
> >
> > > I'm trying to get
> > >it to work with mode 0 and it doesn't seem to
> like the same VRAM
> > >Character Block and VRAM Screen Block being used
> for Char and
> Screen
> > >data from the same map. In other words it seems
> to muck up
> somewhere
> > >and my tiles get corrupted if they're not in
> different VRAM
> blocks. I
> > >always thought you could have 4 simultaneous 256
> colour BGs in
> mode 0
> > >but maybe it's restricted to 4 16 Colour BGs
> > >only???????????????????????????????
> >
> > Remember that the screen data for each background
> layer has to
> > be stored in VRAM too! If you use all 256*4 tiles,
> that will
> > eat up all 64k VRAM (using 256 colours) and leave
> no room for
> > screen data.
> >
> > If all background layers are 256x256 in size, the
> screen data
> > for each layer will be 2048 bytes in size. One way
> to map the VRAM
> would
> > be to allow max 224 tiles for each layer; the
> screendata for
> > each layer would fit precisely then. Of course, if
> one layer uses
> > at most, say, 128 tiles, you could map the VRAM
> differently.
> >
>
> Well at the moment I'm only using a maximum of 30
> tiles for my
> 256x256 game screens. So should I be able to load
> straight into VRAM
> block 0 for both the Screen and Character Data? I
> should be able to I
> think. They both use exactly the same 64k RAM don't
> they so one of
> them would have to begin (in RAM location) where the
> other one ends.
> Am I right or am I talking utter rubbish :) This is
> where it gets
> confusing for me :o)
>
>
>
> > --
> > Jimmy Mårdell "Man with friend
> who run from tiger,
> > mailto:yarin@a... need not run faster
> than tiger,
> > http://www.acc.umu.se/~yarin/ but run faster
> than friend."
>
>
> unsubscribe: gbadev-unsubscribe@egroups.com
>
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
> unsubscribe: gbadev-unsubscribe@egroups.com
>
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie
unsubscribe: gbadev-unsubscribe@egroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/