VIEWPORT as walls.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By THE HELIX

I am creating a game similar to TETRIS.The viewport is (450 *875). I gave the blocks kinematic body 2D and the walls staticbody 2D.The walls hold the blocks but after sometime when more blocks fall the bottom ones go through the collision body which cannot hold more blocks.How can i make the viewport as walls to hold the blocks or is there other ways for holding them ?

:bust_in_silhouette: Reply From: Kaligule

If your game is similar to tetris (discrete timesteps, few moving blocks (current block) and some old blocks that don’t move on a grid) I don’t think I would use collision_shapes for the walls and parts at all.

I would have a game scene which holds the old blocks and the current block as children. Then in every timestep (0.5 seconds or so) I would call custom “move” function to the current block. After that you can check if the state of the rest of the game should change (finished rows, current block gets old block and a new one spawns, special bonuses get applied, check for the game to end, etc).
That way the old blocks will never move because their “move” function is never even called. They should just stay were they are, so why apply gravity to them?

Does this help you? Or did I read too much into the phrase “similar to Tetris”?