Best way to make boulderdash type effect in defold

Hi,

Currently about to finish my first game using Defold, totally loved the program its great and enjoyed all the learning content and now I have a bunch of basics down want to go about making my next one but for the idea I had in mind it would have smilar features of the falling rocks in boulderdash, hopefully enough of you old enough to know what i mean :smiley:

I was wondering whats the best way to go about this, dont think anything in the tutorials would help with this and im struggling with it in my head, wondering if anybody had done anything smiliar and had any tips, if I can get that part down I can easily do all the rest I would need.

For any that dont know, I guess boulderdash is a ‘grid’ type, if nothing is under a rock it falls 1 tile down, until it lands (thats probablt quite easy just with gravity alone) , however once it does land if there is nothing to the right or left of it, it would then fall right or left, hope that makes sense, done a quick drawing ignore the poor quality hopefully makes it make more sense :slight_smile:

thanks in advance

Since everything is happening on a grid I would start by creating a data structure to represent the grid and some functions to check the content of the grid.

You can use nested Lua tables to represent the grid and access it like:

local grid = {}
for x=1,10 do
    grid[x] = {}
    for y=1,10 do
        grid[x][y] =  { type = "empty", id = nil }
    end
end

Your boulders, diamonds, dirt and anything else you want in the game can then be represented in the grid, with a “type” and an “id”. The type will identify the object “diamond”, “dirt” etc and the id is the id of the game object.

You can then iterate over the table row by row, bottom to top and identify conditions when boulders should fall and create a list of all boulders that should fall. It is then simply a matter of going over that list of boulders and updating the grid and animating the boulders (using go.animate).

It is quite similar to how you deal with something like a match 3 game with falling candies or whatever.

1 Like

Thanks a lot, I tried something similar last night before bed which kinda half worked but I think your idea is going to be better.

I used a tilemap and looped over the tiles every 0.1 seconds, and detected if the tile is a boulder, then it checked under it etc and to the side and updated the tile below to a boulder and the current tile to empty, it worked ok but dont think its the correct way, yours sounds much better thanks

Sure, a tilemap will also work, but it is not very efficient to loop over a large tilemap like that. It is better to have the data as a Lua table. Also, with tilemaps you won’t be able to animate the falling boulders (although I don’t believe the original had any fall animation for the diamonds and boulders either).

yeah it was only a 20x20 tilemap, so like you said it would be pretty bad once that got bigger and some of the levels i had in mind would be quite large.

The falling boulders looked ok as the tilemap was updating every 0.1 seconds so it did look like they was falling but not in a smooth way like they would being animated, but again like you mentioned the original didnt, but they didnt have defold and animate() back then to help them :smiley:

The other issue I would run into down the line using a tilemap to do it would be detecting the boulders falling onto a players head, this will be much easier with the lua route you suggested.

thanks

1 Like