Skip to content

Commit

Permalink
Fixed all issues
Browse files Browse the repository at this point in the history
  • Loading branch information
boruno committed Aug 12, 2024
1 parent e5783d7 commit 557d274
Show file tree
Hide file tree
Showing 118 changed files with 1,044 additions and 2,858 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "consumable.hpp"
#include "enemy.hpp"
#include "utils.hpp"
#include "textures.hpp"

const int MAX_DYNAMIC_OBJECTS_ON_SCENE = 10;
const int MAX_ENEMY_OBJECTS_ON_SCENE = 4;
Expand Down Expand Up @@ -66,7 +67,7 @@ void GameplayDynamicScene::updateObjectsList() {
return (object.getStatus() == GameObjectStatus::DESTROYED)
&& (object.getKind() != GameObjectKind::PLAYER);
});
// count the number of the different kinds of objects present on the dynamicScene
// count the number of the different kinds of objects present on the scene
int consumableCount = 0;
int enemyCount = 0;
objects.foreach([&] (const GameObject& object) {
Expand All @@ -81,7 +82,7 @@ void GameplayDynamicScene::updateObjectsList() {
break;
}
});
// add new objects of randomly chosen kind if there is enough room for them on the dynamicScene
// add new objects of randomly chosen kind if there is enough room for them on the scene
int dynamicObjectsCount = consumableCount + enemyCount;
if (dynamicObjectsCount < MAX_DYNAMIC_OBJECTS_ON_SCENE) {
int r = rand() % 100;
Expand Down Expand Up @@ -139,7 +140,7 @@ std::shared_ptr<GameObject> GameplayDynamicScene::addNewGameObject(GameObjectKin
void GameplayDynamicScene::draw(sf::RenderWindow &window, TextureManager& textureManager) {
// draw background
drawBackground(window, textureManager.getTexture(GameTextureID::SPACE));
// draw all objects on the dynamicScene
// draw all objects on the scene
objects.foreach([&] (const GameObject& object) {
object.draw(window, textureManager);
});
Expand All @@ -149,10 +150,7 @@ void GameplayDynamicScene::draw(sf::RenderWindow &window, TextureManager& textur

void GameplayDynamicScene::drawScore(sf::RenderWindow &window, unsigned int value) const {
sf::Text text;
sf::Font font;
if (!font.loadFromFile("resources/pixelLetters.ttf")) {
std::cerr << "Could not load font\n";
}
sf::Font font = TextureManager::getFont();
text.setFont(font);
text.setString("Score: " + std::to_string(value));
text.setCharacterSize(24);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,14 @@ void GameEngine::sceneTransition() {
if (scene->getID() == SceneID::DYNAMIC_GAME_FIELD && nextSceneID == SceneID::LEADERBOARD) {
GameplayDynamicScene* dynamicScene = dynamic_cast<GameplayDynamicScene*>(scene);
if (dynamicScene) {
unsigned int score = dynamicScene->getScore();
scene = sceneManager.transitionScene(nextSceneID, scene, score);
scene = sceneManager.transitionScene(nextSceneID);
}
} else {
scene = sceneManager.transitionScene(nextSceneID, scene);
scene = sceneManager.transitionScene(nextSceneID);
}
}
}


void GameEngine::resizeWindow() {
Rectangle sceneBox = scene->getBoundingBox();
sf::Vector2u sceneSize = sf::Vector2u(width(sceneBox), height(sceneBox));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
#include "operators.hpp"

LeaderboardScene::LeaderboardScene() : Scene(SCENE_WIDTH, SCENE_HEIGHT) {
state = LeaderboardState::INSERTNAME;
state = LeaderboardState::INSERT_NAME;
playerName = "";
playerScore = 0;
textureManager.initialize();
font = textureManager.getFont();
font = TextureManager::getFont();
}

void LeaderboardScene::activate() {
Expand All @@ -26,16 +25,27 @@ SceneID LeaderboardScene::getNextSceneID() const {
return SceneID::LEADERBOARD;
}

void LeaderboardScene::processText(const sf::Event &event) {
// TODO: Write your solution here
}

void LeaderboardScene::processBackspace() {
// TODO: Write your solution here
}

void LeaderboardScene::processEnter() {
// TODO: Write your solution here
}

void LeaderboardScene::processEvent(const sf::Event &event) {
if (state == LeaderboardState::INSERTNAME) {
if (state == LeaderboardState::INSERT_NAME) {
if (event.type == sf::Event::TextEntered) {
char character = event.text.unicode;
// TODO: Write your solution here
processText(event);
} else if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::BackSpace) {
// TODO: Write your solution here
processBackspace();
} else if (event.key.code == sf::Keyboard::Enter) {
// TODO: Write your solution here
processEnter();
}
}
}
Expand All @@ -47,9 +57,9 @@ void LeaderboardScene::update(sf::Time delta) {

void LeaderboardScene::draw(sf::RenderWindow &window, TextureManager &textureManager) {
window.clear(sf::Color::Black);
if (state == LeaderboardState::INSERTNAME) {
if (state == LeaderboardState::INSERT_NAME) {
drawInsertNameScreen(window);
} else if (state == LeaderboardState::SHOWLEADERBOARD) {
} else if (state == LeaderboardState::SHOW_LEADERBOARD) {
drawLeaderboard(window);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Scene* SceneManager::getCurrentScene() {
return &dynamicScene;
}

Scene* SceneManager::transitionScene(SceneID sceneID, Scene* currentScene, unsigned int score) {
Scene* SceneManager::transitionScene(SceneID sceneID) {
return nullptr;
// TODO: Implement your solution here.
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
type: edu
custom_name: Adding Score
files:
- name: src/player.cpp
visible: true
- name: CMakeLists.txt
visible: false
- name: test/test.cpp
visible: false
propagatable: false
- name: src/cgobject.cpp
visible: true
- name: src/collision.cpp
visible: true
- name: src/consumable.cpp
visible: true
- name: src/direction.cpp
visible: true
- name: src/dynscene.cpp
visible: true
- name: src/enemy.cpp
visible: true
- name: src/engine.cpp
visible: true
- name: src/gobject.cpp
visible: true
- name: src/gobjectlist.cpp
visible: true
- name: src/leaderboard.cpp
visible: true
- name: src/leaderboardscene.cpp
visible: true
- name: src/main.cpp
visible: true
- name: src/operators.cpp
visible: true
- name: src/point.cpp
visible: true
- name: src/rectangle.cpp
visible: true
- name: src/scene.cpp
visible: true
- name: src/scenes.cpp
visible: true
- name: src/statscene.cpp
visible: true
- name: src/textures.cpp
visible: true
- name: src/utils.cpp
visible: true
- name: src/player.cpp
visible: true
- name: CMakeLists.txt
visible: false
- name: test/test.cpp
visible: false
propagatable: false
- name: src/cgobject.cpp
visible: true
- name: src/collision.cpp
visible: true
- name: src/consumable.cpp
visible: true
- name: src/direction.cpp
visible: true
- name: src/dynscene.cpp
visible: true
- name: src/enemy.cpp
visible: true
- name: src/engine.cpp
visible: true
- name: src/gobject.cpp
visible: true
- name: src/gobjectlist.cpp
visible: true
- name: src/leaderboard.cpp
visible: true
- name: src/leaderboardscene.cpp
visible: true
- name: src/main.cpp
visible: true
- name: src/operators.cpp
visible: true
- name: src/point.cpp
visible: true
- name: src/rectangle.cpp
visible: true
- name: src/scene.cpp
visible: true
- name: src/scenes.cpp
visible: true
- name: src/statscene.cpp
visible: true
- name: src/textures.cpp
visible: true
- name: src/utils.cpp
visible: true
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "consumable.hpp"
#include "enemy.hpp"
#include "utils.hpp"
#include "textures.hpp"

const int MAX_DYNAMIC_OBJECTS_ON_SCENE = 10;
const int MAX_ENEMY_OBJECTS_ON_SCENE = 4;
Expand All @@ -26,11 +27,11 @@ void GameplayDynamicScene::deactivate() {
}

SceneID GameplayDynamicScene::getID() const {
return SceneID::STATIC_GAME_FIELD;
return SceneID::DYNAMIC_GAME_FIELD;
}

SceneID GameplayDynamicScene::getNextSceneID() const {
return SceneID::STATIC_GAME_FIELD;
return SceneID::DYNAMIC_GAME_FIELD;
// TODO: write your solution here
}

Expand Down Expand Up @@ -66,7 +67,7 @@ void GameplayDynamicScene::updateObjectsList() {
return (object.getStatus() == GameObjectStatus::DESTROYED)
&& (object.getKind() != GameObjectKind::PLAYER);
});
// count the number of the different kinds of objects present on the dynamicScene
// count the number of the different kinds of objects present on the scene
int consumableCount = 0;
int enemyCount = 0;
objects.foreach([&] (const GameObject& object) {
Expand All @@ -81,7 +82,7 @@ void GameplayDynamicScene::updateObjectsList() {
break;
}
});
// add new objects of randomly chosen kind if there is enough room for them on the dynamicScene
// add new objects of randomly chosen kind if there is enough room for them on the scene
int dynamicObjectsCount = consumableCount + enemyCount;
if (dynamicObjectsCount < MAX_DYNAMIC_OBJECTS_ON_SCENE) {
int r = rand() % 100;
Expand Down Expand Up @@ -139,7 +140,7 @@ std::shared_ptr<GameObject> GameplayDynamicScene::addNewGameObject(GameObjectKin
void GameplayDynamicScene::draw(sf::RenderWindow &window, TextureManager& textureManager) {
// draw background
drawBackground(window, textureManager.getTexture(GameTextureID::SPACE));
// draw all objects on the dynamicScene
// draw all objects on the scene
objects.foreach([&] (const GameObject& object) {
object.draw(window, textureManager);
});
Expand All @@ -149,10 +150,7 @@ void GameplayDynamicScene::draw(sf::RenderWindow &window, TextureManager& textur

void GameplayDynamicScene::drawScore(sf::RenderWindow &window, unsigned int value) const {
sf::Text text;
sf::Font font;
if (!font.loadFromFile("resources/pixelLetters.ttf")) {
std::cerr << "Could not load font\n";
}
sf::Font font = TextureManager::getFont();
text.setFont(font);
text.setString("Score: " + std::to_string(value));
text.setCharacterSize(24);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,16 @@ void GameEngine::render() {
}

void GameEngine::sceneTransition() {
if (scene->getNextSceneID() != scene->getID()) {
sceneManager.transitionScene(scene->getNextSceneID(), scene, 0);
scene = sceneManager.getCurrentScene();
resizeWindow();
SceneID nextSceneID = scene->getNextSceneID();
if (nextSceneID != scene->getID()) {
if (scene->getID() == SceneID::DYNAMIC_GAME_FIELD && nextSceneID == SceneID::LEADERBOARD) {
GameplayDynamicScene* dynamicScene = dynamic_cast<GameplayDynamicScene*>(scene);
if (dynamicScene) {
scene = sceneManager.transitionScene(nextSceneID);
}
} else {
scene = sceneManager.transitionScene(nextSceneID);
}
}
}

Expand Down

This file was deleted.

Loading

0 comments on commit 557d274

Please sign in to comment.