Scriptkitten
The20
Don't make it more complex than it has to be. Use a two dimensional array of integers (how big was the playing area of that thing anyways? 10 times 20 or something?), free fields are 0, blocked fields are 1 and whatever else you need is another number. Byte would probably suffice, but i don't know if javascript has that distinction. Anyways, if you do that you only need to keep track of 4 fields for the current block. To check for collisions test if every block can move in a given direction, ignoring collisions with itself.
This is probably horribly inefficient and ugly as sin, but it should work and be fast enough for something as simple as Tetris.
See this is how it's been explained to me several times, from people here and in IRC and from tutorials online. But even then, whoosh, right over my head. So far I have a playing field that is 512x640, divided evenly into 16x20 squares. I have a function that will randomly spit out a shape and let it fall to the bottom, and if you click and drag the shape you can even move it around. I don't know how to incorporate a grid system/array thing into this though, and no idea how to implement "can I move here? Can I fall any more?". And I don't think I've ever worked with bytes in my life, so it leaves me even more lost .__.
here it is

I did try to rewrite it to be forced to use a grid similar to that level design tool I did for Rydian, but it seems like I can either do "grid thing" or "movable shape", never both.


I would take your 16x20 grid, and add one more row, making it 16x21. Any position in the array can have one of three values, 0, 1, or 2. 0s are empty, 1s are filled and mobile, and 2s are filled but immobile.

Now fill the bottom row with 2s all the way across. This makes the "floor" of your array. Now you can figure out whether a block can fall by checking first is it a mobile block, aka a 1, and second is it directly above a mobile block. If its a mobile block, and isn't above an immobile block, then it can fall.

That will get you started. From there you really just have to work out how to "lock" blocks from the same piece together, which it sounds like you've already done.