Pf Projec Report n
Pf Projec Report n
PROGRAMMING FUNDAMENTALS
PROJECT REPORT
PROJECT CREW;
HAMZA AMEEN (242894) AYYAN IZHAR (242889)
Abstract
Page | 1
This report presents the development of a Tetris game built using C++ and
the Raylib library. The objective was to replicate the classic Tetris game while
incorporating a graphical user interface (GUI) to enhance user interaction. The
game includes core gameplay mechanics such as block movement, rotation, line
clearing, scoring, and level progression. Additional features like sound effects
and customizable themes were also implemented. This report also highlights the
key libraries, functions, and design considerations involved in the development
process.
Introduction
Background
Tetris, developed in 1984 by Alexey Pajitnov, has become one of the
most iconic and enduring puzzle games. In Tetris, players must manipulate
falling blocks to clear horizontal lines. The game ends when the blocks stack
up to the top of the screen. This project aimed to recreate the gameplay
mechanics of Tetris using C++, incorporating a GUI with the help of the Raylib
library to enhance the overall experience.
Objectives
The Tetris Game project was developed as part of the Programming
Fundamentals course to apply basic and intermediate C++ programming
concepts. The primary goal was to create a functional and engaging game
that showcases problem-solving, logic, and creativity while providing a fun
user experience.
This section explains the key programming concepts and structures used in
the development of the Tetris game.
1. Arrays
Arrays are one of the foundational data structures used in this game. The grid
that holds the blocks is represented by a two-dimensional array, where each
element corresponds to a cell on the Tetris board.
Purpose in Tetris: The grid is a 10x20 matrix where each cell can either be
empty or occupied by a part of a Tetrimino. The array is used to store the current
state of the game and is essential for detecting when a row is full and when the
game ends.
Page | 2
2. Loops
Loops are crucial for tasks such as rendering the game grid, moving blocks, and
clearing lines. In Tetris, loops are used to:
Continuously check for user input (e.g., arrow keys to move or rotate blocks).
Update the game state by moving blocks down the grid.
Scan the grid to detect full lines and clear them.
Purpose in Tetris: Loops are used for repeatedly executing actions in the game
(e.g., moving blocks, checking collisions). This ensures that the game runs
smoothly and updates at a constant rate.
3. Functions
Functions are used to break down the game logic into manageable, reusable
parts. The game's logic is modularized into functions that handle specific tasks
such as block movement, rotation, line clearing, and collision detection.
Purpose in Tetris: Functions simplify the game’s structure and make the code
easier to manage. For example, the rotateBlock() function rotates the current block,
and the clearLine() function clears any full line from the grid.
4. Conditional Statements
Conditional statements are used extensively in Tetris for detecting events such
as when a block collides with the grid or when a line is full.
5. Collision Detection
Collision detection is essential to the game mechanics, preventing blocks from
overlapping or going out of bounds.
Purpose in Tetris: When a block reaches the bottom of the screen or touches
other blocks, the game needs to check if the block can move any further. This is
done using collision detection, where the current block's position is compared
against the occupied positions in the grid.
Page | 3
Design and Implementation
System Architecture
The system architecture of the game consists of three major components:
1. Game Logic: This module handles the core mechanics of the game, such as
the block movement, rotation, line clearing, and scoring.
2. GUI Rendering: Responsible for rendering the game grid, blocks, and UI
elements such as the score, and game-over screen, etc.
3. Event Handling: Manages user input, particularly key presses for moving and
rotating blocks, pausing and restarting the game, and handling the game-over
condition.
Page | 4
Core Components
Features
Core Features
Page | 5
Bonus Features
Sound Effects:
Sound effects were added to enhance the gameplay experience. Sounds
were played when rotating blocks, clearing lines, and triggering the game-over
event. Raylib’s LoadSound() and PlaySound() functions were used to implement
this feature.
Results
Performance:
The game runs smoothly at a steady 60 frames per second (FPS) even on
systems with lower hardware configurations. The use of Raylib’s efficient
drawing functions ensures that the game performs well.
Gameplay:
The gameplay experience is intuitive, with the player using the arrow keys to
control the blocks, and the game ends when the grid is filled up.
User Experience:
The game is easy to control, and the GUI is designed to display essential
information like the score. Sound effects add to the immersion of the game.
Below is a screenshot showing the "Game Over" screen after a player
completes a game session:
Conclusion
Page | 6
The Tetris game was successfully developed, replicating the core
mechanics of the classic game while introducing a graphical user interface. The
use of C++ and the Raylib library enabled smooth gameplay and efficient
rendering. The additional features, such as sound effects provided a richer
experience for the player. Future improvements could include adding a
multiplayer mode, level progression and more advanced visual effects.
References
Appendix
Page | 7
Page | 8
Page | 9