Lab 1b

2D Transformations and Interactions - 2D Tetris

Due: Sunday, April 22nd 2018, 23:55

Start Early!!!


Individual Effort:
No team participation is really encouraged in the case of the homework or the labs.
You're are not allowed to use any libraries or extra code except gl-matrix, webgl-utils.js and some helper functions in order to initialize WebGL / load shaders. Especially Three.js is not allowed! If you're not sure or want to use some library, ask the teaching assistant first.
Late Submission:
Don't get behind in the lab assignments - always start early!
In this course you will have a total of 4 (four) grace days that you can distribute however you like. See here for more information on grace days.

Objectives:


Do the following before you proceed:


Goal:

The goal of this lab is to implement a 2D version of the game tetris.


Tasks:

Continue Assignment 1a and proceed with the steps below.
Follow this guideline step-by-step, but be sure to read the overall text before you start. Also thoroughly test your program after each step so that you can find bugs easier and quicker.

(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.


Extra Credit (max 5%)

(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.


Submission


Grading Criteria

Grading the labs will be based on the following:

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%.


Last modified: February 28, 2018
Lukas Herzberger / lukas DOT herzberger AT univie DOT ac DOT at