#150298 - NinjaMonkeyPirate - Fri Feb 01, 2008 6:06 pm
How have any of you done this? By which i mean, cheacking for a collision between a sprite (i.e. player) and the background they are standing on.
So far, I use a rectangle for the player "base", the size that their feet would be on the map, and check it against the current tile(s) that rectangle is above(standing on), and used a u8 to describe the "passability", that is, what directions across which the tile can be passed.
For example, if the tile the player is standing on has the values PASS_RIGHT | PASS_UP, the plaer will move if they press up or right, pressing left or down will do nothing.
The problem with this is having to set a variable for each tile in a tilemap, which sucks without some kind of tool, so before I make one, does anygbody have a better technique?
#150299 - gauauu - Fri Feb 01, 2008 6:21 pm
I do similar to what you are doing, with a few things to make it easier:
First, (maybe this is what you mean), I associate the passability based on the graphics tile in the tileset, not on the map of tiles that makes up the level. (i.e. all wall graphic tiles are unpassable)
Second, which just makes my life slightly easier, in my tile graphics definitions, I group all similar tiles (in passability) into one section, so instead of specifying passability for each tile, I specify it for the group
(i.e. all tiles between 0 and 30 are completely passable. all tiles between 31-50 are not passable unless you are flying. etc) So I just have one file that specifies these groups, which is easier to maintain.
I don't do anything with differences between passability in terms of up/left/down/right...I do it in terms of movement types. Land movers have a passability of a certain type, flyers another, ghosts another.
Also, (which is probably relatively obvious) the bounding box I use for my player or enemies when checking against map collisions is the same bounding box that I use when checking against them colliding with each other.
#150312 - NinjaMonkeyPirate - Fri Feb 01, 2008 8:37 pm
hmm, I think I like some of those.
I only use a different bounding box because of the top-down view, I want to check collision with the feet, not the player's head, so it can still look like the player is looking over it.
And I do the same as per tile instead of map, and I try to keep similar things together (grasss tiles near dirt tiles, etc...), but I hadn't thought of tile grouping.
How do you manage that? I just made an array of U8s the same size as my tile array, and look them up by the same index. That is, for every tile, i have a u8 "Pass_Flag" with the same index.
Also, what kind of game are you working on? It sounds like a strategy game, where mine is a bit more RPG/adventure-ish (at least it will be), which is why I am more concerned with direction than unit type.
Thanks for the ideas
#150319 - gauauu - Fri Feb 01, 2008 11:08 pm
I manage it by changing a configuration file that gets turned into a C array.
My configuration file looks sort of like:
Code: |
minFlyingCollide: 50
minGhostCollide: 80
|
which gets translated into a C array that looks sort of like:
Code: |
int tilesetCollisionBoundaries[] = {50,80};
|
Then to check if it's a collision, do something like:
Code: |
bool isCollision(int collideType, int tile)
{
int minCollideTile = tilesetCollisionBoundaries[collideType];
return (tile >= minCollideTile);
}
|
Not exactly, but that's basically it. (To be exact, I cheat a bit, since there's a few complicated exceptions...for each tileset, I have a different function that gets called that uses a bunch of ifs and switch blocks to manage the more complicated exceptions. Those functions are ugly as sin, but it makes the general case much cleaner)
I'm also doing an action/adventure type game, Anguna. (I've been working on it for a couple years now, and it's SO close to being done, maybe just a few more weeks)
Regarding your bounding box for their feet...each of my characters have 2 separate definitions: one for what their sprite looks like and where it sits relative to the character's "master position", and one that tells their bounding box (where their feet and body are) size and where that sits relative to their "master position". All collisions (map, character-enemy, bullet-character, etc) are checked against that bounding box.
#150326 - NinjaMonkeyPirate - Sat Feb 02, 2008 2:08 am
Oh cool, I played you're demo, thought it was fun.
Anyhoo, so what you have is an an array for each tileset of each tile group right?
#150350 - gauauu - Sat Feb 02, 2008 8:03 pm
Thanks!
Yup...for each tileset, I have an array of each grouping of similar tiles.