Puzzle "Push" Mechanic

Get help using Construct 2

Post » Mon Oct 14, 2013 11:33 am

Hey all,

I am making a puzzle game wherein pieces are moving through a grid maze and the player eliminates them by selecting them when they have aligned. Pieces are constantly being added to the grid "pushing" the pieces in front of them forward. Therefore, if you have eliminated some pieces in the middle of the grid, pieces "further down the line" shouldn't move until the empty grid spaces have been filled. Unfortunately, I don't know a way to implement this, short of trying some sort of physics situation (which I feel might over complicate the matter). Does anyone know of a simple way to do this?

Thanks!!

Capx
B
13
S
5
G
1
Posts: 23
Reputation: 3,170

Post » Mon Oct 14, 2013 2:52 pm

Tricky..

In my mind something like detect what rows the tiles are on. When one is removed, if it's on a row moving right then detect if there are tiles on the same row with a greater X than the empty slot, stop these from moving until the slot is occupied.plinkie2013-10-14 14:58:00
B
46
S
16
G
79
Posts: 2,171
Reputation: 46,859

Post » Tue Oct 15, 2013 9:07 am

@plinkie I think I get what you're saying, but I'm not sure how I would go about implementing it.

I had originally thought that I could try and have each tile detect whether or not there was a tile "behind" it relative to the direction it was traveling, but I can't figure out how I could get that to then affect every tile "ahead" of the tile that has been triggered as "stopped".

Anybody have any thoughts on this?
B
13
S
5
G
1
Posts: 23
Reputation: 3,170

Post » Tue Oct 15, 2013 10:13 am

I had a think and possibly a better idea...give them IDs starting from 0 and counting up. When one is removed randomly from the middle of the queue i.e. it has ID #3, disable the movement logic for anything with a lower ID number. This will work better as I realised that you will probably need to halt tiles on other rows. So if the tiles are lined up as 5 4 3 2 1 0 and you remove 3, it appears as 5 4 [ ] 2 1 0, you stop 2 1 0 from moving and it would end up 5 4 2 1 0 eventually. I didn't look in detail at how you were doing the movement but I could see co-ord type logic so just disable that. You should be able to easily compare an instance variable and run a foreach function for every object that has a lower ID.
B
46
S
16
G
79
Posts: 2,171
Reputation: 46,859

Post » Tue Oct 15, 2013 10:37 am

When making a grid-based game like this, it's generally not a bad idea to run the game logic using arrays.

Your game pieces would be represented by different values and you could then just loop through every cell and move the value to the next one until there is an empty(0) cell.
B
23
S
6
G
10
Posts: 1,041
Reputation: 7,553

Post » Tue Oct 15, 2013 10:51 am

@Plinkie I think this might work, as I'm hoping to have several different layouts, so I am hesitant to make the logic to reliant on the level layout. I suppose I'll have to look more into how UID's work, unless there's a better way to go about assigning id's to sprites?

@PixelRebirth I'm not sure how I'd go about using matrices for this, but I do have some experience using them. Would I be able to use it with different level layouts?

Thank you so much for the quick and helpful responses!!
B
13
S
5
G
1
Posts: 23
Reputation: 3,170

Post » Tue Oct 15, 2013 10:57 am

Arrays don't pose any particular problem I can think of when used in multiple layouts. Your game logic would likely work in an event sheet included in all of your level layouts.

Maybe I'll make a little example later to better illustrate what I'm getting at.
B
23
S
6
G
10
Posts: 1,041
Reputation: 7,553

Post » Tue Oct 15, 2013 12:10 pm

Here is an example of what I was talking about:

https://dl.dropboxusercontent.com/u/2306601/pushArray.capx

I decided to use a 1-dimensional array that basically just contains a long continuous list of your game pieces (or rather values that represent the pieces of course).

Made a couple of functions to push a new value into the array and then to actually draw the playfield. Hope it gives you an idea.
B
23
S
6
G
10
Posts: 1,041
Reputation: 7,553

Post » Tue Oct 15, 2013 12:14 pm

@PixelRebirth

Nice! I really should look into arrays a bit more..
B
46
S
16
G
79
Posts: 2,171
Reputation: 46,859

Post » Wed Oct 23, 2013 9:43 pm

@PixelRebirth Wow, that's exactly what I was trying for! Thank you so much!!
B
13
S
5
G
1
Posts: 23
Reputation: 3,170

Next

Return to How do I....?

Who is online

Users browsing this forum: ametueraspirant, dand, mickclarke and 29 guests