
-----------------------------------
omni
Mon Mar 08, 2004 5:24 pm

collision detection in tetris
-----------------------------------
I got the rotation down pat, now I need some help on the collision detection. 
The current piece is stored as a 1..4*4 array of int . 
A '1' says that this place is taken up by a block and a 0 says its free.
The board itself is also one huge one dimensional array 1..12*39 of int
Note these aren't 2 dimensional arrays I want to keep them 1 dimensial.

-----------------------------------
McKenzie
Mon Mar 08, 2004 5:38 pm


-----------------------------------
Ouch. 2-Dim is the way to go. Ignoring that, you are obviously trying to compare your piece vs the board to find collisions.  I assume that you are already restricting the piece so that it can't go off the edges. The check will look something like:
var pieceAt := where bottom left corner is in the board array
var hit:=false
for h : 0 .. 3
    for w : 1 .. 4
        if piece(h*4 + w) + board(h*12 + w + pieceAt) = 2 then
            hit :=true
        end if
    end for
end for

-----------------------------------
omni
Mon Mar 08, 2004 6:20 pm


-----------------------------------
if I were to change the 1 and 0's to boolean true and false, in order to compare the two I would have to use the boolean operators right?

ex:
OR XOR AND ?

-----------------------------------
Tony
Mon Mar 08, 2004 6:46 pm


-----------------------------------
as oppose to not using and/or ? :?

-----------------------------------
omni
Mon Mar 08, 2004 7:34 pm


-----------------------------------
what do you mean?

-----------------------------------
Tony
Mon Mar 08, 2004 7:39 pm


-----------------------------------
ohh... I think i get what you mean by boolean operators... and you could use them... you can also use if = comparison.

-----------------------------------
omni
Mon Mar 08, 2004 8:02 pm


-----------------------------------
ya thats what I was planning to do with them. using in if statement,
but still having trouble

-----------------------------------
McKenzie
Tue Mar 09, 2004 8:35 am


-----------------------------------
ya, you would use AND because you only care about the case where the collision occurs.

-----------------------------------
omni
Tue Mar 09, 2004 5:41 pm


-----------------------------------
thanks sir, err.. McKenzie

-----------------------------------
omni
Tue Mar 09, 2004 8:45 pm


-----------------------------------
here is my program so far, bugs are evident, but I just want to get some opinions and whether it is worth programming for the People.

edit: has someone else previously made a tetris game like mine?

Ctrl and ALT are to rotate and 'j' and 'l' to move left and right

-----------------------------------
Paul
Tue Mar 09, 2004 8:58 pm


-----------------------------------
hm, a couple of bugs, the next piece appears in the x coordinate of where the last peice fell. When you turn it near the edge, it goes all wacky. The piece rotates funny (or does it?) oh, and I can turn it when there isn't space.

-----------------------------------
omni
Tue Mar 09, 2004 9:03 pm


-----------------------------------
i've got the first few problems fixed, but the detection of whether the piece has enough room to rotate or not is going to be hard.

Note: if I can get the bugs fixed, should there be a cooperative mode, or vs or both?
