1. Use the Arrow keys to move around for a bit. 2. Bump into the dark gray things a lot. 3. Realize that you can't go through them at all. 4. Read the Notes and Credits below for the explanation. 5. See inside the project.
Okay, so how does this work? Tiles are a group of pixels. How many pixels are in a group of pixels? That's the size of each tile or tileSize. Each tile in this project is 32 pixels in width and height. That's why the tiles are squares. Are you ready for the good news? If you represent all objects as tiles, you significantly simplify collision, movement, and more! Because of that, it took less than a hour or so to create this project. How did I stop the highlighted box from going through the dark gray things or solid tiles? I checked if there was a tile in the position that it was attempting to move to first. If a tile was in that position, I didn't allow it to move there. If a runner was to the left, trying to go right, and there was a monster at right, the runner don't go right. How did I show all the tiles with one sprite named Tiles? I used a common rendering script involving clear, stamp, and a custom block that has screen refresh turned off. The same loop structure is used to check all tiles for collision with the highlighted box or if the highlighted box is attempting to move into one of the tiles. For more details on this, you should see my project named rendering engine v0.2. Why are some scripts unused in the sprite named Tiles? Those scripts are what I used to make a quick maze editor that made what you see on the stage. Why does the highlighted box mathematically move only 32 pixels in four directions? Where's velocity? Acceleration? Because then I will have to deal with tile penetration. Velocity and acceleration will make the highlighted box overlap with tiles. We want to know if a collision will happen BEFORE the highlighted box overlaps or touch any tile. There's a solution to this as you would expect, but I'll leave it up to you for now to figure it out as an exercise. Why is this not a game? It's meant to be a tutorial, but it could be a game. Maybe remix this and give it a go?