Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
collision detection in tetris
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.

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

Posted: Mon Mar 08, 2004 6:46 pm   Post subject: (No subject)

as oppose to not using and/or ?
Tony's programming blog. DWITE - a programming contest.
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.

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

tetris.t
Description:
Filename:  tetris.t
Filesize:  6.57 KB

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?
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 12 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: