Tetris Style Game Physics
alexxxhp
Member Posts: 161
I am making a game in the style of tetris but color code based instead of shapes but I cant get the game to destroy actors when all colors match 4 or more. what rules should be applied to tell the game to destroy when 4 of a kind collide... I have tried all different ways and don't seem to work thanks.
Comments
Each block or piece must obviously be an instance of one parent.
Say you want a grid based system - map out the coordinates for the grid. Store each number as a value globally (in the scene). Where ever a block lands - it's x or y coordinate will be one of these numbers. The coordinates of the blocks do not have to be dynamically stored or even stored in an array. Rather you make a rule that works like how a score counter works. This is tricky though as I can't explain the logic further.
Basically, what you want is if 4 blocks overlap or collide with eachother and happen to have the same x or y coordinate - they tick the counter. When the counter hits 4, it deletes the instances that ticked the counter. If a block has been removed that ticked the counter for say a horizontal row (it was deleted in a vertical row) the counter drops a number.
You might have to have a counter for each row and each column, so that requiring an array won't be necessarily necessary.
If you want tetris type pieces that fall down which consist of say 4 blocks each like the real tetris. You can have the constructed outside of the scene and simply recycle them. Outside of the screen area they are fixed. When called they are shifted to the area above the screen and are no longer fixed - they are prone to gravity and so fall. The only problem is, they'll fall in perfect formation, but once any block touches a stationary object, the rest will continue to fall until they come to rest.
That's a game which I think is somewhat similar to Tetris. I explain how to create it in The Unofficial GameSalad Textbook.
Really, the existing GS logic is strongly leaning toward shooters and platformers.
(Which I like, so is not a problem)
but some more "casual game / puzzle" oriented features could be good -
such as a visual "matrix" object - could be very handy for backgrounds too?
tile match detection, etc, etc.
tshirtbooth and vegasmike1 are right: it isn't impossible to do but it would be very difficult.