Jump to content

Interaction moving tetris/pentomino blocks, plus what sprite to best use..?


BdR
 Share

Recommended Posts

I want to create a game with tetris/pentomino style blocks (although they can consist of more than 5 parts), where the blocks can move all at once and they will interact with each other (i.e. bump into each other). Also, the blocks can bump into the border around the game area.

 

When the player makes a move, all blocks should fall in a certian direction until they can't move any further. This means some blocks will collide and stop at the border, but some blocks will be stopped because of other blocks that are in the way. So there are "chain reactions" in detecting wether or not a block can move.

 

I think this can be done in 2 ways;

  1. Move all blocks one tile at a time and determine the allowed moves for each tile move.
  2. Or, calculate the distance each block will move beforehand and then use different tweens to move every block.
That last method is tricky because of the interaction between the blocks. See picture below.

 

261g4yv.png

 

In this example situation, when all blocks move down then block A can move 2 places down and then bumps into the border. Block B can move 3 places down (not 4 places until the border!) because it will then be blocked by A. And so on for the other blocks. So my questions are

  1. Does anyone know of a good algorithm to deal with this kind of block sliding and interaction? Can anyone point me int right direction to get started
  2. What is best for performance? Make each block be a combined composite sprite using Phaser,BitmapData? Or use several tiled sprites, and maybe anchor them together?
Link to comment
Share on other sites

I think you can change the real body of a sprite (with cropRect, among others), but I don't know if you can give it any shape. There is also a way of drawing graphics (example : https://phaser.io/examples/v2/display/graphics), but I don't know if you can apply a sprite on top of it.

 

You can also group several images with cacheAsBitmap, so you could regroup squares to make any form and not impact performance. But the logic would be slightly more complicated.

Link to comment
Share on other sites

Maybe it will be better if you calculate a series of chained tweens on a group of blocks using cacheAsBitmap property, so when a block has reached its final position it will be removed of the tweening group and then start the next tween with the remaining blocks that still have to move.

Link to comment
Share on other sites

  • 4 months later...

Still working on this game, for anyone interested I used the second method from the opening post. So I've created an algorithm that determines the distance each block will slide and then move all the sprite-group with tweens.


Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...