In this part of our Minesweeper tutorial, we'll build upon our previous code by adding the ability to track and display the count of bombs in adjacent cells.
This feature provides players with the information they need to make informed decisions during gameplay.
We’ll also allow cells to be cleared when there are no adjacent bombs, allowing players to clear large sections of the grid automatically.
In this part of our Minesweeper tutorial, we'll build upon our existing code to add a crucial element of the game:Â bombs.
We'll implement the ability to place bombs randomly within our grid and reveal them when cells containing bombs are cleared.
We'll start by updating our global configurations to include new variables for bomb-related events and settings. Then, we'll modify our grid and cell classes to handle bomb placement and rendering.
By the end of this section, you'll have a Minesweeper grid where bombs can be placed and revealed, setting the stage for implementing the game's core mechanics in future parts.
In this lesson, we'll focus on creating the foundational structure for our Minesweeper game. We'll implement the grid system and individual cells, setting the stage for bomb placement and game logic in future lessons.
We'll start by setting up the necessary parameters in our global configuration, then move on to creating the MinesweeperCell
and MinesweeperGrid
 classes.
Finally, we'll implement basic interaction functionality, allowing players to clear cells and prepare our system for future bomb placement.
In this series, we'll build a fully functional Minesweeper game from scratch, giving you hands-on experience with game development concepts and C++Â programming.
We'll separate our project into two main parts:
For example, we'll create a general Button
class in our engine that can be used across various projects. The cells of our Minesweeper grid will then inherit from this Button
class, expanding it with Minesweeper-specific logic such as whether the cell contains a bomb and counting the number of bombs in adjacent cells.
SDL_Image
SDL_Image
.In this lesson, we’ll start using the SDL_Image
extension we installed earlier. We’ll cover 3 main topics:
SDL_Image
IMG_Load()
function to load and render a wide variety of image types, rather than being restricted to the basic bitmap (.bmp
) format.IMG_SaveJPG()
and IMG_SavePNG()
We’ll be building upon the basic application loop and surface-blitting concepts we covered earlier in the course:
SDL_ttf
SDL_ttf
extensionIn this lesson, we’ll see how we can render text within our programs. We’ll use the official SDL_ttf extension we installed earlier in the course.
We’ll build upon the concepts we introduced in the previous chapters. Our main.cpp
looks like below.
The key thing to note is that we have created a Text
class, and instantiated an object from it called TextExample
. This object is being asked to Render()
onto the window surface every frame:
SDL_ttf
In this lesson, we’ll build on our text rendering capabilities with some new tools:
Our main.cpp
is below. Compared to the last lesson, we’ve added a GetWidth()
method to the Window
 class.
In this lesson, we’ll see how we can load images into SDL, and then display them in our window.
We’ll build upon the concepts we introduced in the previous chapters. Our main.cpp
looks like below.
For this lesson, the key thing to note is that we have an Image
object called Example
, which is being asked to Render()
onto the window surface every frame:
// main.cpp
#include <SDL.h>
#include "Image.h"
class Window {/*...*/};
int main(int argc, char** argv){
SDL_Init(SDL_INIT_VIDEO);
Window GameWindow;
Image Example;
SDL_Event Event;
bool shouldQuit{false};
while (!shouldQuit) {
while (SDL_PollEvent(&Event)) {
GameUI.HandleEvent(Event);
if (Event.type == SDL_QUIT) {
shouldQuit = true;
}
}
GameWindow.Render();
Example.Render(GameWindow.GetSurface());
GameWindow.Update();
}
SDL_Quit();
return 0;
}
We’ll build out this Image
class across the next two lessons. Our starting point is simply this:
In this lesson, we'll dive into image positioning and cropping techniques. Here's what we'll cover:
As a starting point, we’ll be building upon the basic application loop and surface-blitting concepts we covered in previous lessons:
In this lesson, we'll learn how to scale our images up and down during the blitting process. Here's what we'll cover:
SDL_BlitScaled()
function, and how it differs from SDL_BlitSurface()
.We’ll be building upon the basic application loop and surface-blitting concepts we covered earlier in the course:
In the previous section, we introduced the application loop and event loop, which sets the foundation of our program. As our program and interactions get more complex, we need to build additional systems on top of this foundation to help manage the complexity.
In this lesson, we'll dive deeper into managing complex user interfaces by implementing a modular UI system. We'll cover key topics such as:
By the end of this lesson, you'll have a solid foundation for building scalable and maintainable UIÂ systems.
Welcome to this lesson on building interactive UI components using SDL in C++. In this tutorial, we'll explore how to create dynamic buttons that respond to user input.
We'll cover topics such as event handling, creating custom button classes, and implementing hover and click behaviors.
As with any code, interacting with SDL can sometimes result in errors. For example, let’s imagine we’re trying to create a window that uses Metal, which is Apple’s API for creating high-performance graphics. To do this, we pass the SDL_WINDOW_METAL
flag to SDL_CreateWindow()
:
#include <SDL.h>
int main(int argc, char** argv) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* Window = SDL_CreateWindow(
"Hello World",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
1024, 768,
SDL_WINDOW_METAL
);
return 0;
}
If this program is run on a platform that doesn’t support Metal (such as a Windows machine), window creation will fail, and it might not be obvious why that is. In this lesson, we’ll introduce the ways we can detect and cover from errors coming from SDL.