BdR Posted June 29, 2015 Share Posted June 29, 2015 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;Move all blocks one tile at a time and determine the allowed moves for each tile move.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. 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 areDoes 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 startedWhat 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 More sharing options...
BdR Posted July 6, 2015 Author Share Posted July 6, 2015 No one? Link to comment Share on other sites More sharing options...
Skeptron Posted July 7, 2015 Share Posted July 7, 2015 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 More sharing options...
Carlos Posted July 7, 2015 Share Posted July 7, 2015 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 More sharing options...
BdR Posted December 4, 2015 Author Share Posted December 4, 2015 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 More sharing options...
drhayes Posted December 4, 2015 Share Posted December 4, 2015 I wouldn't use physics to do this. Logically, all these pieces exist on a grid that you can check very quickly... especially if only one piece is moving at a time. Link to comment Share on other sites More sharing options...
Recommended Posts