Computer Science Canada Help adding a few features to Tetris |
Author: | Snario [ Fri Jun 08, 2012 8:52 pm ] |
Post subject: | Help adding a few features to Tetris |
I'm using the code that this website provides to build a Tetris game: http://zetcode.com/tutorials/javagamestutorial/tetris/ I'd like to add: - A ghost piece that rests where the piece would land if the player pressed space or nothing at all. - A way to hold a piece for later use (e.g., you get a line piece but want to use it when there is a good space, so you hold it and another piece comes) The holding I feel like I have a good sense of how to get it to work, but the ghost piece isn't working as I expected it to. |
Author: | Amarylis [ Fri Jun 08, 2012 9:13 pm ] |
Post subject: | RE:Help adding a few features to Tetris |
What have you tried so far for the ghost piece? |
Author: | Snario [ Fri Jun 08, 2012 9:31 pm ] | ||
Post subject: | Re: Help adding a few features to Tetris | ||
This is what I've tried so far:
Obviously the code isn't quite right. Basically what I want to do is find the lowest possible spot that the block would fit if kept on the same path. So that means I need to find the maximum value for y in the board of the lowest values that each part of a shape can rest on and then orient the shape based on that value. |
Author: | Snario [ Sat Jun 09, 2012 10:57 am ] | ||
Post subject: | RE:Help adding a few features to Tetris | ||
Alright so I updated that code a bit and it sort of works now, the shape is drawn in the correct x positions but the y value are a bit off. Ghost shapes appear inside already placed shapes and if the board is empty sometimes some of the blocks fall beneath the lowest line.
|
Author: | Snario [ Sat Jun 09, 2012 7:17 pm ] |
Post subject: | RE:Help adding a few features to Tetris |
I'm checking this thread every 5 minutes or so by the way, so if you want any additional info I'll be able to reply very quickly. :p I've put the Ghost project aside for now, working on a timer and high scores system as well as a reset button at the moment. |
Author: | Amarylis [ Sat Jun 09, 2012 9:43 pm ] |
Post subject: | RE:Help adding a few features to Tetris |
My suggestion is to use the system you have for checking when the original piece has reached the bottom-most point it can be placed at on your ghost piece to figure out where it's bottom-most point is |
Author: | Snario [ Sun Jun 10, 2012 2:57 pm ] | ||||||
Post subject: | Re: Help adding a few features to Tetris | ||||||
I got it to work! If anyone is interested in the solution, here it is: Created a ghost method that gathers the co-ordinates of a ghost piece using the contents of the dropDown method but modified a bit (you will see later in the tryMove method)
Then inside the if statement of the paint method
Had to add this if statement to the tryMove method, and the ghost boolean
|
Author: | Snario [ Sun Jun 10, 2012 6:50 pm ] |
Post subject: | RE:Help adding a few features to Tetris |
Is there any way I can put this entire application inside of a Desktop Application rather easily? By which I mean the entire application is inside a box and outside of the box I can add some buttons and such. |
Author: | Snario [ Mon Jun 11, 2012 2:17 pm ] |
Post subject: | RE:Help adding a few features to Tetris |
Also could anyone tell me how I could go about adding a main menu and screen to display all of the high scores? I know how to do all of the leaderboard stuff, but I don't know how to display it. |