First Unity project - Boulderdash/Rocks'n'Gems-like 2D game - Any tips ?

Hi there,

firstly, sorry if this whole text is awful to read, I can add pictures of my project if you need later!

I’m working on my very first project (started few days ago) which is a Boulderdash-like game (more like Rocks’n’Gems but this one is less known).

Here’s a little video gameplay from Rocks’n’Gems :

Since I’m still at the basics of Unity, I don’t really know what would be the “best” ways to reach that.
For now I have 5 tilemaps, each containing dirt-tiles, wall-tiles, edge-tiles, and the last two contains respectively diamonds and rocks (I use a prefab brush from the 2D extras found on github, so I can add real objects on the tilemaps).

dirt-tile : breakable by player just by walking on it
wall-tiles : only breakable with explosions
edge-tile : indestructible (edge of the map)

NB : There is no TilemapColliders on tilemaps

Player : has a BoxCollider2D and a RigidBody2D, so that he can gather diamonds by walking on them or get destroyed by collision with ennemies. Player movements are done with a Vector3.MoveTowards for a smooth movement, seems pretty good so far. I can destroy dirt-tiles without any problem and I get blocked by edge/wall-tiles (that are detected with a little code that checks Tilemap.hasTile).

Diamonds : have BoxCollider2D set as isTrigger so that the player can gather them and can kill players/ennemis if they fall on them.

Rocks : not implemented yet.

Gravity isn’t “normal gravity” since objects will fall at a constant speed, so I guess using RigidBody’s gravity is tricky, I went for something else with a Vector3.MoveTowards, but that might be complicated ?


Now I’m struggling with diamonds falling and detecting stuff. Atm each diamond casts 3 RayCast (down, down/left, down/right) to check if there are items under, as well as a chunk of code that will detect if there are tiles under them, but I feel like this is an over-complicated way.

(down/left, down/right) are here so that diamonds could fall on left or right side even if there is something beneath them (see the rock falling at 0:09 on the video linked).


I’m thinking that maybe it could be easier by storing integers (or bytes since it takes less memory) in a giant array (like 100x100), each cell in the array represents a coordinate in my 2D world and each integer refers to an object/tile (i.e. : 0 = dirt, 1 = diamond, 2 = wall, …).
Since everything is grid-snapped (i.e. all objects are at perfect positions, except when moving), keeping track of them could be easy, and checking if there is an object at pos XY is simply done by scanning the value of the cell in the array.

For exemple :

XOX
OXX
XOO

X = dirt
O = diamond

Array would look like :
[[ 0 , 1 , 0]
[ 1 , 0 , 0]
[ 0 , 1 , 1]]

However when objects are moving I might have issues. Also wouldn’t it be very inneficient CPU-wise to just scan the array at every frame or every given time ?

Well it’s still a giant mess that I’m trying to change into something that looks like a game… it might also be a mess to read and understand it, sorry for that, let me know if you need more informations, and of course I don’t mind sharing pictures if that helps :slight_smile:

Also simple question, is it a good first project to start with ? Or am I trying something a bit too hard ?

Thanks for reading!

Nathan

1 Like

Just use Unity - Scripting API: Tilemaps.Tilemap.GetTile to check those nearby tiles.

Well I’m already using it for tiles, but it seems to not work when I use a tile filled with GameObjects (prefab brush). Anyway it’s a bit too much for me at the moment, I’ve moved to a simpler game for now which I really enjoy making :), perhaps I’ll get back on this project later.

1 Like

Hey Riyujin did you go ahead with this project? Could you share the progress or some code? I think it’s an interesting idea! :slight_smile:

In actual fact, a couple of years ago, with the help of an old mate of mine, I actually made a Boulderdash clone, give me a minute and I’ll dig up the YouTube footage.