The goal of this lab is to implement a 2D version of the game tetris.
(15%) Add gravity
Now, add gravity to the object such that it moves downwards by itself.
The up "/\" movement should simply cancel the gravity and not move
pieces down anymore! Further, the down "\/" movement should either reinstate
gravity, if it was suspended or move the game piece immediately to the bottom
of the grid (if gravity is ON). Make sure, that the gravity is not 'too strong'.
I.e. the game should not be too fast nor too slow. Test this on the PClab
machines. Note: When I talk about "gravity" I don't actually mean that the
object accelerates as it falls down. I am assuming that it falls with constant
speed.
(10%) Add more objects
Whenever an object reached the bottom, release the control of the
current object and introduce a new object at the top of the drawing
area. Hint: In the beginning, this could always be the same primitive
(e.g. always a 2x2 block). Then you should also allow all seven
tetrominos,
the choice should also be random. You don't need collision detection yet.
(20%) Non-overlapping
Since we are dealing with solid blocks, they cannot overlap. In fact
we would have to stop any movement if it would move onto "space"
occupied by other blocks already drawn. This can be achieved by
setting up a virtual 2D array that keeps track of the occupied
screen space. Each field in the array has a flag, that says, whether
the screen block is occupied or not. This array needs to be checked
before we execute a movement (only for the final position, but not
for the intermediate positions of the animated move). When we "release"
an object and a new one is introduced we need to permanently "store" the current/old
object into the array. Since we do not want the old pieces to disappear
from the screen, we also need to render the array itself, or better
all occupied blocks of the array together with the position of the
current object.
(20%) Fail-safe User Interaction
So far the user could move the objects out of the array. You
will need to implement a test that this cannot happen anymore. Test
whether a movement will move the object outside the array. If
the test is positive, do not execute the user command.
(20%) Keeping Score
Whenever we "release" one object and it is stored in the
array, check whether one row is completely occupied. If that is the
case, clear it from the array and move all the objects about that row as
far down as possible without entering already occupied blocks.
Output the number of rows deleted thus far. This is the score.
(10%) Game Over/New Game
When the tetrominos stored in the array reach the top line so that there's no space left for new blocks the game
should be reset and start anew.
(5%) Change the pixels per block
Add two input buttons to increase or decrease the size of the blocks.
(2%) non-empty initialization
Instead of an empty grid start with a grid, that has a random
bottom, i.e. there should be a "mountain range" of blocks located at
the bottom of the playing field.
(3%) Changing the level of difficulty
An input button where you can increase and decrease the level
of difficulty. This parameter should be directly tied to the gravity,
i.e. the speed with which the objects fall down.
In addition to that, you could also use the level of difficulty as a multiplier for the score and automatically
increase the difficulty every 10 (or so) lines that were cleared to make the game more interesting.
(3%) Screen shake, explosions, etc.
Add some special effects! When a tetromino reaches the bottom,
the screen could shake. Or make some explosion-effects if a line gets cleared.
If you have any other cool idea here, try to impress us.
(2%) Show the next block coming
Add a small window showing the next block that will enter the scene.
In order to get a full mark, you need to do all of the assigned tasks AND adhere to to lab procedures while creating readable and efficient code. I.e. if you accomplish only 70% of the tasks correctly, but you do not adhere to lab procedures, your final mark will be 70*(1-0.05) = 66.5%.