How to create and check collisions with different width tiles?

For example Hotline Miami style. Room border tiles have different width instead of floor tiles. Tables, bath - the same question. Hot to import, store and collide them? ???

First and foremost, game programming is largely about faking effects in a way doesn’t require us to simulate the universe. Tilemaps are just one such tool for doing this. You don’t have to restrict yourself to using Tiles. You can mix and match anything you want to if it gets you to your end goal. There’s nearly always multiple approaches to any given problem, it’s up to you to find and choose the best approach for your requirements. Down below are some approaches I can think of. There was more, but I encourage you to think about different solutions.

  1. Just because an object appears smaller or larger than a tile does not mean they are not made out of tiles. Smaller objects can be created by a tile with a smaller graphic in it, and large objects can be created with multiple tiles.

  2. Thirdly, while your game has tiles in it, does not mean everything has to be tiles. The items in the room that you see could just be sprites.

  3. You could have multiple layers, each with their own properties. Set these properties to what fits for you.

As far as collision goes, again, you have multiple options. It depends on what you do with the above, and what fits your requirements of course. Here are some approaches you could take, try to think of more:

  1. Checking rectangles for collision is incredibly basic. Objects could just be a list of rectangles.

  2. Tiles could have a rectangle(s) indicating their collision zones.

Narrow down the exact requirements of your game in this aspect, and try choose a solution that best fits. If you need help, we’re here.

For now, I prefer string-based tile map. Just for example:
BBBBBBBB
B…B
B…B
B…B
BBBBDBBB

D - door
B - border
. - background floor texture.

As I understand correctly - it is good approach, in my case, set border width a bit smaller, not fixed width == height tile size. In addition, check collisions based on width of board tile. While other tiles will be with tileWidth == tileHeight rule. Isn’t it ?

Well that’s 1 requirement: That your level must be represented by one array of characters. This means every tile will be of the same size, which still very much works for what you want to do.

Here are some other things you will may want to consider:

  • Is character movement tile based?
  • If not, must the player collide with thin walls exactly, or can they stop at the tile edge?
  • Will there be more than one type of floor texture?

Yes, I’m using one 2d array. But I’m not agree with you - I can use different size of tiles, but I hate this! It procedure additional calculations… But really don’t like this. This is root cause of my question.

  1. Player movement is not tile based.
  2. Planning exactly collisions with all things in game world. Based on picture just for example - collide with bath, doors, bad, etc…
  3. Yes, like picture, different textures for each room|level

With those requirements established, you can now make a better judgement on what you need to do.

Player movement isn’t tile based - This means you need collision volumes that are independent of the tile size.

Each room has different textures - This (ideally) means you need to have objects on another layer while we paint the floor underneath. This means you won’t have to make a new tileset for each ground type. Walls and such will only take up part of a tile, and the other part will be transparent, so you can see the ground underneath them.


From the requirements, I propose the following:

You have two layers of tiles. One layer is the ground. The second layer is any objects and walls, anything that has transparency. Every tile on the second layer specifies a collision rectangle for it’s tile. When checking collisions, you check the tile you are touching, then check the collision rectangle.

There’s a few ways you could vary this, but it’s probably the easiest approach and it will work fine. Beds and baths and such can be made by combining multiple tiles.

Ok, looks good! Will test!
Thank you a lot!

PS:
But what about doors? Take a look at picture. :slight_smile:
Do I need additional tiles for door background? On that case we have transition between background textures… :clue:

So, I understand all. But I need special editor for that stuff… Ho I compare levels and set all things in needed place…

Doors can be made with tiles, though it will visually unappealing if it’s jumping tile by tile. I’d either make no transition and have it open or closed, or specially handle the case for doors. For a simple solution, in the file, you could have D as door start, and EEEEE for the space you want the door to take up.

You don’t need an editor, although it would be helpful. It wouldn’t be hard to make a basic one. Writing levels in notepad as you were is certainly fine for a project that I presume won’t have large levels. You could even use an editor such as “Tiled” and read in it’s exported files, which you’re probably not ready to do, but it’s good to challenge yourself. :wink: