From 2952065133609ea35cb0cab366223e03ae96a090 Mon Sep 17 00:00:00 2001 From: dylanbenzi Date: Tue, 11 Nov 2025 01:14:29 -0500 Subject: [PATCH] add pacman life indicators --- src/Game.cpp | 25 +++++++++++++++++++++++++ src/ResourceManager.h | 5 +++++ 2 files changed, 30 insertions(+) diff --git a/src/Game.cpp b/src/Game.cpp index e3f092f..7fd7f46 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "Game.h" #include "MazeMap.h" @@ -22,6 +23,8 @@ void Game::run() { // Pellet data: 0=none, 1=pellet, 2=power resources.loadMap("pelletMap", "assets/game/pellets.txt"); + resources.loadFont("bitFont", "assets/fonts/PressStart2P.ttf"); + resources.loadSound("credit", "assets/sounds/credit.wav"); resources.loadSound("death_0", "assets/sounds/death_0.wav"); resources.loadSound("death_1", "assets/sounds/death_1.wav"); @@ -57,6 +60,7 @@ void Game::run() { {912, 0}, {0, 0}); + Pacman pacman; Ghost blinky; @@ -114,6 +118,20 @@ void Game::run() { sf::Time initialGameplayPause; + int score = 0; + sf::Font bitFont = resources.getFont("bitFont"); + sf::Text scoreText(bitFont); + scoreText.setString(std::to_string(score)); + scoreText.setPosition({16, 32 * 31 + 16}); + + sf::Sprite pacmanLifeOne(resources.getTexture("all_textures"), {{2340, 68}, {52, 52}}); + pacmanLifeOne.setOrigin({52, 0}); + pacmanLifeOne.setPosition({32 * 28, 32 * 31}); + + sf::Sprite pacmanLifeTwo(resources.getTexture("all_textures"), {{2340, 68}, {52, 52}}); + pacmanLifeTwo.setOrigin({52, 0}); + pacmanLifeTwo.setPosition({30 * 28, 32 * 31}); + while (window.isOpen()) { while (const std::optional event = window.pollEvent()) @@ -191,6 +209,8 @@ void Game::run() { if (map.hasPellet(currentPacmanTile.x, currentPacmanTile.y)) { map.eatPellet(currentPacmanTile.x, currentPacmanTile.y); + score += 10; + scoreText.setString(std::to_string(score)); if (pelletSoundCount % 2) { pellet1.play(); @@ -204,8 +224,13 @@ void Game::run() { } window.clear(); + window.draw(map); window.draw(pacman); + window.draw(scoreText); + window.draw(pacmanLifeOne); + window.draw(pacmanLifeTwo); + window.display(); } diff --git a/src/ResourceManager.h b/src/ResourceManager.h index d1d1b91..3263d3d 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,10 @@ public: return &sounds[soundName]; }; + sf::Font& getFont(const std::string& fontName) { + return fonts[fontName]; + }; + //load gameplay info private: