[java] Java Tetris...
Yea ahha im asking a tetris question. Its quite embarrassing since i have been using Java for a couple of years now and I have been able to create 2D games, tile based, arcade type shooters, etc...but I cant get my head around TETRIS!!
(this project is kind of just a spur of the moment kind of thing because i realized out of everything, i havent created Tetris and thats one of the first BEGINNER projects :(..)
I was wondering if someone could help me break it down. So far I have figured I would need a Game class, Board class, and piece class..Now i also figure that the board would be represented by a 2D an array right? and whatever piece is displayed on that 2D array we would just change those current spots (i.e board[x][y] = 1, or w.e number the piece is..) and all that seems to be logical and seems like it would work, but the problem comes in when drawing the pieces and adding them to the board. Would i just take one piece (the straigh I piece) and in a method
called "setPiece(int x, int y) set the position of the current piece individually every time.
Like in my game loop have it do something like this
piece.drop();
board.setPiece(x,y) //do this for every block of the piece..
and if it hits another piece or the bottom just leave those cells of the 2D array their current number?
sorry if its confusing...just trying to get my thoughts together and looking for some advice.
Quote:spur of the moment kind of thing
Why? Portfolio? Check something off? Getting it done?
Realistically speaking, computers are blazing fast these days, so worrying too much about optimizations isn't strictly needed.
The most trivial way is, before you drop any piece, simulate how it intersects with board. If it does, glue it in current position. Simply running a quad loop to test intersection is dirty, but trivial to code.
Representing pieces. There's "clever" solutions. But a 4x4x4 array works just fine (each piece rotated (max of 4 times), largest piece is 4x4.
"Drop" is not an action piece performs. Piece is agnostic and self-sufficient with regard to world. A board defines what drop is, and there will always be only one piece.
The setPiece is redundant. Piece exists within a board. When you drop it, you do the collision test, if that passes, you move it down.
Quote:and if it hits another piece or the bottom just leave those cells of the 2D array their current number?
Board can be simple 18x10 array. You also don't need to actually move the piece, all you're interested in is its current position. No need to actually superimpose it on the board - do that only if it collides.
On every collision, check for full lines. This, as well as collision test itself, can be trivially implemented as limited scan. Since there's no gravity in tetris, if a row is removed, test for rows above. When you've removed all of them, drop the remaining pieces above last row down.
Well ill try again later because this thing has been pissing me off, and the only reason i wanted to do it is because when i was thinking about it i realized i had no idea how it is done (still dont) yet everyone suggests it as a beginner project so i felt like i should at least make one.
I think im over complicating it right now so i will come back to it later.
one question.
If i use a 4 X 4 array (why would i need a 4x4x4 array?
isnt this all thats required
xxxx
xxxx
xxxx
xxxx
since i can do
0xxx
0xxx
00xx
xxxx
etc..
how would i put that onto my board 2D array?
(like add that "piece" to the board)
I think im over complicating it right now so i will come back to it later.
one question.
If i use a 4 X 4 array (why would i need a 4x4x4 array?
isnt this all thats required
xxxx
xxxx
xxxx
xxxx
since i can do
0xxx
0xxx
00xx
xxxx
etc..
how would i put that onto my board 2D array?
(like add that "piece" to the board)
You should try to work out the pseudocode for the game first.
Otherwise, you won't get far since it's suprisingly complicated.
Otherwise, you won't get far since it's suprisingly complicated.
Well thats kind of all i wanted to hear really lol (its complicated) because the only reason i was attempting it right now is because everyone recommends it to beginners. But i guess its good for beginners because it would help them think out the logic and all that in it...so i think I will just have to pass on tetris for now :P...
Hey man don't let it beat you ^_^ it's a hell of a lot less complicated than 3D math.
This guy did it in an hour http://www.gamedev.net/community/forums/topic.asp?topic_id=192483
Enjoy ^_^
This guy did it in an hour http://www.gamedev.net/community/forums/topic.asp?topic_id=192483
Enjoy ^_^
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement