# Boulders Affect / Movement

Get help using Construct 2

### » Wed Feb 12, 2014 1:04 am

Hi,

I have recently started making (or trying!) to make some 2D games, having lots of fun on the way but I'm currently total lost on trying to do something with Boulders / rock sprites.

I'm basically trying to get the same affect that the boulders have on 'Boulderdash' for anybody that has played it.

Here is a working HTML5 example of that game

boulderdash.krissz.hu/cave/A8YAEx1vuxvH/boulder1-intro/

If you notice how the boulders fall to the side if stacked on top of each other and there are gaps to the left or right, that is what I'm trying to achieve.

I'm new to construct today having given Stencyl a try but could not accomplish the above so going to go through the tutorials on here and see if I can do it.

If anybody has any advice / tips on doing the above I would be very Grateful.

Thanks!
B
11
S
2
G
1
Posts: 68
Reputation: 777

### » Wed Feb 12, 2014 1:38 am

I've done this though not in C2 but here's how I accomplished it loosely based on the original game logic.

First decide which objects you want the boulders to fall from. I selected boulders and gems. in classic BD they call these objects round.
assign a boolean var to each rock instance eg isRound and set to false by default.
Now you'll need to acquaint yourself with the "overlapping at offset" event.

Say you have a 3x3 grid and your rock is on the middle square.

123
4R6
789

On start of level for each rock:

Check if it's overlapping a round object at offset x=0, Y=(1 X tilesize)corresponding to square 8.

If it is then set the isRound var to true. The rock can now roll

Make a timed loop
System every 0.2 seconds
System for each rock
add a second condition so it only checks rocks that you permit may fall.
if isRound is true
then:
Check if it's overlapping an object on the square to your left.
if it is then check if it's overlapping an object on the square to your right.
If it isn't overlapping anything on the left ie the square is empty then check if it's overlapping anything in the square left one, down one if it isn't then fire the "Roll" function) if it is overlapping at either of those two points try the same thing on the right ie is X overlapping at X + tilesize, Y=Y then X + tilesize, Y + tilesize.
Back to the square of nine Rock is on 5 you check 4 then 7 if both empty roll rock left if either occupied check 6 then 9 if both empty roll right if either occupied then no roll possible but now is a good time to update the Rock vars as something may have changed since the last time So add an Else:
Check if it's overlapping a round object at offset x=0, Y=(1 X tilesize)corresponding to square 8. (As at beginning)
Game has moved all moveable instances and updated all instances to see if they are potentially movable.

Roll function can be simple movement 1 x tilesize left or right and let gravity do the rest bullet works best.

Use platform behaviour to detect if a rock is falling or has landed and toggle the isRound var otherwise you'll have rocks dropping off objects you don't want, round only!

As in BD the same movements can be applied to the diamonds to achieve the correct drop effect for those too.

Bertie Booster2014-02-12 01:43:55
There are 10 types of people in the World, those that understand binary and those who don't.
B
7
S
2
Posts: 93
Reputation: 797

### » Wed Feb 12, 2014 2:56 am

https://dl.dropboxusercontent.com/u/44710358/Boulder%20dash/boulder%20dash.capx @Neller this is not full example but for start making this example
B
119
S
32
G
53
Posts: 1,896
Reputation: 39,569

### » Wed Feb 12, 2014 9:12 am

Thanks for the replies guys,

Bertie Booster - thanks for that I will give it a try today, although will need to learn C2 first but shouldn't take me long hopefully :) , but reading what you say makes sense

delgado - thanks I had a look at that and looks great, the problem for me though is the main thing missing from it is the part I actually can't do (the falling rocks when stacked)

Again thanks for the fast responses, I will see if I can code something like Bertie Booster mentioned above when I finish work.
B
11
S
2
G
1
Posts: 68
Reputation: 777

### » Wed Feb 12, 2014 11:47 am

Yeah the falling rocks and diamonds like in original game is hardest to do
i try with physics and platform behavior all dont work perfect for me
B
119
S
32
G
53
Posts: 1,896
Reputation: 39,569

### » Wed Feb 12, 2014 11:05 pm

Here's one way to do the falling rocks:
https://www.dropbox.com/s/pl1y8rfo3temq ... .capx?dl=1
/examples21/boulderdash.capx

It differs from Bertie Booster's idea in that it uses a array for a grid instead of using overlapping at offset.
Last edited by R0J0hound on Mon Mar 19, 2018 7:06 pm, edited 1 time in total.
B
100
S
38
G
134
Posts: 5,555
Reputation: 85,323

### » Wed Feb 12, 2014 11:43 pm

That is a very very nice solution RojoHound, I'm a lover of nailing grid positions with arrays this works very well indeed.
There are 10 types of people in the World, those that understand binary and those who don't.
B
7
S
2
Posts: 93
Reputation: 797

### » Thu Feb 13, 2014 7:49 am

Had a look and that looks perfect, thanks R0J0hound

I will use that with it working so well and just build the game from there, still learning the basics of C2 atm so going to do it as I go.

Thanks for all your help guys
B
11
S
2
G
1
Posts: 68
Reputation: 777

### » Mon Feb 17, 2014 2:03 am

@R0J0hound you should make great game soon with your skills
B
119
S
32
G
53
Posts: 1,896
Reputation: 39,569

### » Sun Oct 25, 2015 11:33 pm

R0J0hound wrote:Here's one way to do the falling rocks:
https://dl.dropboxusercontent.com/u/542 ... rdash.capx

It differs from Bertie Booster's idea in that it uses a array for a grid instead of using overlapping at offset.

your capx is really great @R0J0hound and i just finished adapting it to use with a tilemap but it seems my way of looping though the tilemap to find the "rock" tiles is far more cpu intensive then your "for each sprite" loop.

is there maybe a better way to find the rocks / loop through a tilemap?

i also tryed the following, but it doesnt make much difference, i think.
B
39
S
11
G
5
Posts: 485
Reputation: 5,365

Next