Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding Room for a Shape on a Grid
    text
    copied!<p>I'm working on a game where you have an 8x12 grid where each cell is the same size and all the cells are directly next to one another.</p> <p>You drag around various Tetris-like shapes and place them on the grid in valid locations, a valid location being one where all the cells that the shape will occupy are not occupied by some other shape.</p> <p>My problem is that I'm not sure how to search the grid space for valid locations. I've been searching for an algorithm that will solve this sort of problem, but I have come up empty handed thus far. It seems like it should be pretty straightforward to detect valid locations, but I have not been able to come to a successful solution.</p> <p>Any processes, algorithm suggestions, or ideas for how to go about solving this would be extremely helpful. Thanks!</p> <p><strong>EDIT:</strong></p> <p>Here is the expected functionality: When the shape is in a valid location, it can be dragged between valid locations freely and follows the mouse pointer. However, when you try to drag the shape into an invalid area (ie movement in the direction specified would place one or more blocks of the shape in invalid locations), it stays in the last valid location. </p> <p>At this point, when the mouse is in an invalid area, I want to do some "predictive" movement so that if the player moves the mouse cursor near a valid position, the shape then "snaps" into place, say if the valid position is two grid spaces away.</p> <p>Thanks for your suggestion so far; I hadn't thought of that method!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload