Good afternoon,
I designed a block pushing game but I can't figure out how to make the game work without lag.
You are able to move up, down, left and right on the field using the arrow keys. When you push into a block, it moves it over by 16px. When you push a block into another one, they both move. This is done by finding the furthest empty space and leap-frogging the block to it.
Unfortunately once you stack more than 5 together an evident slowdown occurs. The line of blocks will appear to get shorter before waiting at least a few ticks and then righting itself, but this isn't satisfactory.
It seems like my method of evaluating each block looking for the next empty grid slot is too slow for a computer to handle in a single frame. I'm trying to find a faster way to do it, as this will definitely get in the way when moving enemies you must trap are dropped in. Also the blocks cannot tell fast enough when they are against a wall (even though the code works) and a large chain will plow through it with impunity.
I've added a capx in case anyone wants to mess with it themselves.
https://drive.google.com/open?id=1ZQFji-wKQ05A4L-0aluGT8IFli_lUwiW