Author |
Message |
omni
|
Posted: Mon Mar 08, 2004 5:24 pm Post subject: 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.
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
McKenzie
|
Posted: Mon Mar 08, 2004 5:38 pm Post subject: (No subject) |
|
|
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:
code: | 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
|
Posted: Mon Mar 08, 2004 6:20 pm Post subject: (No subject) |
|
|
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
|
|
|
|
|
omni
|
Posted: Mon Mar 08, 2004 7:34 pm Post subject: (No subject) |
|
|
what do you mean?
|
|
|
|
|
|
Tony
|
Posted: Mon Mar 08, 2004 7:39 pm Post subject: (No subject) |
|
|
ohh... I think i get what you mean by boolean operators... and you could use them... you can also use if = comparison.
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
omni
|
Posted: Mon Mar 08, 2004 8:02 pm Post subject: (No subject) |
|
|
ya thats what I was planning to do with them. using in if statement,
but still having trouble
|
|
|
|
|
|
McKenzie
|
Posted: Tue Mar 09, 2004 8:35 am Post subject: (No subject) |
|
|
ya, you would use AND because you only care about the case where the collision occurs.
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
omni
|
Posted: Tue Mar 09, 2004 5:41 pm Post subject: (No subject) |
|
|
thanks sir, err.. McKenzie
|
|
|
|
|
|
omni
|
Posted: Tue Mar 09, 2004 8:45 pm Post subject: (No subject) |
|
|
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
Description: |
|
Download |
Filename: |
tetris.t |
Filesize: |
6.57 KB |
Downloaded: |
249 Time(s) |
|
|
|
|
|
|
Paul
|
Posted: Tue Mar 09, 2004 8:58 pm Post subject: (No subject) |
|
|
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
|
Posted: Tue Mar 09, 2004 9:03 pm Post subject: (No subject) |
|
|
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?
|
|
|
|
|
|
|