mirror of
https://github.com/dylanbenzi/pacmen-sfml.git
synced 2026-11-27 08:26:59 +00:00
add pacman life indicators
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <SFML/Audio.hpp>
|
#include <SFML/Audio.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
#include "MazeMap.h"
|
#include "MazeMap.h"
|
||||||
@@ -22,6 +23,8 @@ void Game::run() {
|
|||||||
// Pellet data: 0=none, 1=pellet, 2=power
|
// Pellet data: 0=none, 1=pellet, 2=power
|
||||||
resources.loadMap("pelletMap", "assets/game/pellets.txt");
|
resources.loadMap("pelletMap", "assets/game/pellets.txt");
|
||||||
|
|
||||||
|
resources.loadFont("bitFont", "assets/fonts/PressStart2P.ttf");
|
||||||
|
|
||||||
resources.loadSound("credit", "assets/sounds/credit.wav");
|
resources.loadSound("credit", "assets/sounds/credit.wav");
|
||||||
resources.loadSound("death_0", "assets/sounds/death_0.wav");
|
resources.loadSound("death_0", "assets/sounds/death_0.wav");
|
||||||
resources.loadSound("death_1", "assets/sounds/death_1.wav");
|
resources.loadSound("death_1", "assets/sounds/death_1.wav");
|
||||||
@@ -57,6 +60,7 @@ void Game::run() {
|
|||||||
{912, 0},
|
{912, 0},
|
||||||
{0, 0});
|
{0, 0});
|
||||||
|
|
||||||
|
|
||||||
Pacman pacman;
|
Pacman pacman;
|
||||||
|
|
||||||
Ghost blinky;
|
Ghost blinky;
|
||||||
@@ -114,6 +118,20 @@ void Game::run() {
|
|||||||
|
|
||||||
sf::Time initialGameplayPause;
|
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 (window.isOpen())
|
||||||
{
|
{
|
||||||
while (const std::optional event = window.pollEvent())
|
while (const std::optional event = window.pollEvent())
|
||||||
@@ -191,6 +209,8 @@ void Game::run() {
|
|||||||
|
|
||||||
if (map.hasPellet(currentPacmanTile.x, currentPacmanTile.y)) {
|
if (map.hasPellet(currentPacmanTile.x, currentPacmanTile.y)) {
|
||||||
map.eatPellet(currentPacmanTile.x, currentPacmanTile.y);
|
map.eatPellet(currentPacmanTile.x, currentPacmanTile.y);
|
||||||
|
score += 10;
|
||||||
|
scoreText.setString(std::to_string(score));
|
||||||
|
|
||||||
if (pelletSoundCount % 2) {
|
if (pelletSoundCount % 2) {
|
||||||
pellet1.play();
|
pellet1.play();
|
||||||
@@ -204,8 +224,13 @@ void Game::run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.clear();
|
window.clear();
|
||||||
|
|
||||||
window.draw(map);
|
window.draw(map);
|
||||||
window.draw(pacman);
|
window.draw(pacman);
|
||||||
|
window.draw(scoreText);
|
||||||
|
window.draw(pacmanLifeOne);
|
||||||
|
window.draw(pacmanLifeTwo);
|
||||||
|
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <SFML/Audio/SoundBuffer.hpp>
|
#include <SFML/Audio/SoundBuffer.hpp>
|
||||||
#include <SFML/Graphics/Font.hpp>
|
#include <SFML/Graphics/Font.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -43,6 +44,10 @@ public:
|
|||||||
return &sounds[soundName];
|
return &sounds[soundName];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
sf::Font& getFont(const std::string& fontName) {
|
||||||
|
return fonts[fontName];
|
||||||
|
};
|
||||||
|
|
||||||
//load gameplay info
|
//load gameplay info
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user