Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 48 additions & 11 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,51 @@
add_executable(cpp_game
colour.cpp
entity.cpp
main.cpp
rectangle.cpp
vector2.cpp
window.cpp
cmake_minimum_required(VERSION 3.10)
project(cpp_game)

set(CMAKE_CXX_STANDARD 20)

# SDL2
set(SDL2_DIR "C:/libs/SDL2-2.24.2")
set(SDL2_INCLUDE_DIR "${SDL2_DIR}/include")
set(SDL2_LIB_DIR "${SDL2_DIR}/lib/x64")
# C:/libs/SDL2-2.24.2/include
# C:/libs/SDL2-2.24.2/lib/x64
# SDL2_ttf
set(SDL2_TTF_DIR "C:/libs/SDL2_ttf-2.22.0")
set(SDL2_TTF_INCLUDE_DIR "${SDL2_TTF_DIR}/include")
set(SDL2_TTF_LIB_DIR "${SDL2_TTF_DIR}/lib/x64")

# Include both SDL2 and SDL2_ttf headers
include_directories(${SDL2_INCLUDE_DIR} ${SDL2_TTF_INCLUDE_DIR})
link_directories(${SDL2_LIB_DIR} ${SDL2_TTF_LIB_DIR})

file(GLOB SOURCES
*.cpp
*.h
)

target_link_directories(cpp_game PRIVATE ${sdl_BINARY_DIR})
target_include_directories(cpp_game PRIVATE ${sdl_SOURCE_DIR}/include)
target_compile_features(cpp_game PRIVATE cxx_std_20)
add_executable(cpp_game ${SOURCES})

# Link against both SDL2 and SDL2_ttf libraries
target_link_libraries(cpp_game SDL2.lib SDL2main.lib SDL2_ttf.lib)

target_link_libraries(cpp_game SDL2::SDL2-static)
# Copy both SDL2 and SDL2_ttf DLLs after build
add_custom_command(TARGET cpp_game POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${SDL2_LIB_DIR}/SDL2.dll"
"${SDL2_TTF_LIB_DIR}/SDL2_ttf.dll"
$<TARGET_FILE_DIR:cpp_game>
)

# Create resources directory and copy font file
add_custom_command(TARGET cpp_game POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory
$<TARGET_FILE_DIR:cpp_game>/resources

)

# Copy font file to resources directory
add_custom_command(TARGET cpp_game POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/resources/MinecraftTen-VGORe.ttf"
$<TARGET_FILE_DIR:cpp_game>/resources/
)
185 changes: 185 additions & 0 deletions cpp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# 🎮 BreakOut Game

<div align="center">

[![C++](https://img.shields.io/badge/C%2B%2B-00599C?style=for-the-badge&logo=c%2B%2B&logoColor=white)](https://en.cppreference.com/)
[![SDL2](https://img.shields.io/badge/SDL2-FFD700?style=for-the-badge&logo=SDL&logoColor=black)](https://www.libsdl.org/)
[![CMake](https://img.shields.io/badge/CMake-064F8C?style=for-the-badge&logo=cmake&logoColor=white)](https://cmake.org/)
</div>

## 📝 Description

A classic arcade-style BreakOut game built with modern C++ and SDL2. Break all the bricks with your ball while controlling the paddle to prevent the ball from falling! Features multiple brick types, progressive difficulty, and high score tracking.

## 🖼️ Game Screens

<div align="center">

### 🎮 Start Screen
![Start Screen](./screenshots/start_screen.png)

### 🎲 Playing Screen
![Playing Screen](./screenshots/playing_screen.png)

### 🏆 Win Screen
![Win Screen](./screenshots/win_screen.png)

### ❌ Game Over Screen
![Game Over Screen](./screenshots/game_over_screen.png)

</div>

## 🎯 Game Features

- 🏓 Smooth paddle controls
- 🔴 Multiple brick types with different hit points
- ⚡ Dynamic ball physics with speed progression
- 🎨 Clean visual design with animations
- 🏆 Score system and high score tracking
- 🎮 Multiple game states (Title, Playing, Win, Game Over)
- 💾 Persistent high score storage

## 🎮 Controls

| Key | Action |
|-----|--------|
| ⬅️ Left Arrow | Move paddle left |
| ➡️ Right Arrow | Move paddle right |
| ⏎ Space | Start/Restart game |
| ❌ Escape | Exit game |

## 🧱 Brick Types

| Color | Hits Required | Points |
|-------|---------------|--------|
| 🟢 Green | 1 | 100 |
| 🟠 Orange | 2 | 200 |
| 🔴 Red | 3 | 300 |

## 🎯 Game Mechanics

- Ball speed increases as bricks are destroyed
- Different brick types require multiple hits
- Score based on brick type and destruction
- High score persistence between sessions
- Dynamic paddle collision angles

## 🔄 Game States

```mermaid
graph TD
Start[Start Game] -->|Initialize| Init[Initialize Game State]
Init -->|Enter Main Loop| Loop[Game Loop]
Loop -->|Process Input| Input[Handle Player Input]
Input -->|Update| Update[Update Game State]
Update -->|Render| Render[Render Graphics]
Render -->|Check| Check[Check Game State]
Check -->|Win Condition Met| Win[Display Win Screen]
Check -->|Game Over Condition Met| GameOver[Display Game Over Screen]
Check -->|Continue| Loop
Win -->|Restart| Start
GameOver -->|Restart| Start
```

## 📁 Project Structure

### 🎯 Core Files
- `main.cpp` - 🎮 Game loop and core logic
- `window.cpp/h` - 🖼️ SDL window management
- `entity.cpp/h` - 🎲 Game objects (paddle, ball, bricks)

### 🛠️ Support Files
- `vector2.cpp/h` - ➡️ 2D vector mathematics
- `rectangle.cpp/h` - 📦 Collision shapes
- `colour.cpp/h` - 🎨 Color management
- `key_event.h` - ⌨️ Input handling

## 🚀 Building the Game

### Prerequisites
- 📌 C++20 compiler
- 📌 SDL2 library
- 📌 CMake 3.10+

### Build Steps

```bash
# 1. Clone the repository
git clone https://github.com/Prince-Patel84/asm_c_cpp/tree/develop/cpp

# 2. Create build directory
mkdir build
cd build

# 3. Generate build files
cmake ..

# 4. Build the game
cmake --build .
```

## 🎮 How to Play

1. 🚀 Launch the game
2. 🏓 Use left and right arrows to move the paddle
3. 🎯 Bounce the ball to break all bricks
4. 🏆 Try to clear all bricks without losing the ball
5. 📊 Score points based on brick type
6. 💾 Beat your high score!

## 🔧 Technical Implementation

### Physics System 🎯
- Accurate ball bouncing mechanics
- Precise collision detection
- Dynamic paddle reflection angles
- Progressive ball speed system

### Rendering Engine 🎨
- Hardware-accelerated graphics
- Smooth animations
- Efficient frame rendering
- Dynamic color transitions

### Game State Management 🎮
- Title screen with animations
- Playing state with score display
- Win condition with final score
- Game over state with restart option

### Score System 📊
- Points based on brick type
- High score tracking
- Persistent storage
- Visual score display

## 🛠️ Future Enhancements

- [ ] 🔊 Sound effects
- [ ] 🎯 Multiple levels
- [ ] ⚡ Power-ups
- [ ] 💖 Lives system
- [ ] 🎨 Custom themes

## 👥 Team Motion Minds

<div align="center">

### 🎮 Game Development Team

| Name | Student ID |
|------|------------|
| Prince Patel | 202401151 |
| Vishwa Prajapati | 202401163 |
| Dhruv Patel | 202401142 |

Built with 💖 and lots of 🎮
</div>

---

<div align="center">

### 🌟 Star this repository if you find it helpful!

</div>
2 changes: 1 addition & 1 deletion cpp/colour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Colour::Colour(std::uint8_t r, std::uint8_t g, std::uint8_t b)
}

Colour::Colour(std::uint32_t colour)
: Colour((colour >> 16) & 0xff, (colour >> 7) & 0xff, colour & 0xff)
: Colour((colour >> 16) & 0xff, (colour >> 8) & 0xff, colour & 0xff)
{
}

Expand Down
1 change: 1 addition & 0 deletions cpp/key_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum class Key
ESCAPE,
LEFT,
RIGHT,
SPACE,
};

/**
Expand Down
Loading