Bomberman Multiplayer
Authoritative multiplayer networking layer for Bomberman.
Loading...
Searching...
No Matches
SingleplayerLevelScene.h
1#ifndef BOMBERMAN_SCENES_SINGLEPLAYER_LEVEL_SCENE_H
2#define BOMBERMAN_SCENES_SINGLEPLAYER_LEVEL_SCENE_H
3
4#include <memory>
5#include <utility>
6#include <vector>
7
8#include "Entities/Enemy.h"
9#include "Entities/Sound.h"
10#include "Entities/Sprite.h"
11#include "Entities/Text.h"
12#include "Scenes/LevelScene.h"
13
14namespace bomberman
15{
16 enum class Texture : int;
17
22 {
23 public:
24 SingleplayerLevelScene(Game* game, unsigned int stage, unsigned int prevScore, std::optional<uint32_t> mapSeed = std::nullopt);
25
26 protected:
27 virtual void updateLevel(unsigned int delta) override;
28 virtual void onKeyPressed(SDL_Scancode scancode) override;
29
30 private:
31 void spawnTextObjects();
32 void updateScore();
33 void setTimerTextFromMilliseconds(int milliseconds);
34 void generateEnemies();
35 void spawnEnemy(Texture texture, AIType type, int positionX, int positionY);
36 void spawnBomb(Object* object);
37 void spawnBang(Object* object);
38 void spawnDoor(Object* object);
39
40 void finish() const;
41 void gameOver();
42
43 void updateTimers(unsigned int delta);
44 void updateBombTimer(unsigned int delta);
45 void updateBangTimer(unsigned int delta);
46 void updateGameOverTimer(unsigned int delta);
47
48 void updatePlayerCollision();
49 void updateEnemiesCollision();
50 void updateBangsCollision();
51 [[nodiscard]] bool isCollisionDetected(const SDL_FRect& rect1, const SDL_FRect& rect2) const;
52 void destroyBrick(std::shared_ptr<Object> brick);
53 void followToPlayer(Enemy* enemy);
54 virtual void onCollisionObjectSpawned(Tile tile, const std::shared_ptr<Object>& object) override;
55
56 static constexpr int kLevelTimerStart = 200500;
57 static constexpr int kLevelTimerUpdateText = 1000;
58 static constexpr int kBombTimerStart = 1500;
59 static constexpr int kBangTimerStart = 800;
60 static constexpr int kGameOverTimerStart = 1000;
61 static constexpr int kWinTimerStart = 200;
62
63 static constexpr unsigned int kScoreRewardForKill = 200;
64 static constexpr unsigned int kScoreRewardForStage = 1000;
65
66 std::shared_ptr<Sound> gameoverSound = nullptr;
67 std::shared_ptr<Sound> winSound = nullptr;
68 std::shared_ptr<Sound> explosionSound = nullptr;
69 std::shared_ptr<Text> timerLabel = nullptr;
70 std::shared_ptr<Text> timerNumber = nullptr;
71 std::shared_ptr<Text> scoreNumber = nullptr;
72 std::shared_ptr<Text> stageLabel = nullptr;
73 std::shared_ptr<Sprite> bomb = nullptr;
74 std::shared_ptr<Sprite> door = nullptr;
75 std::vector<std::shared_ptr<Enemy>> enemies;
76 std::vector<std::pair<Tile, std::shared_ptr<Object>>> collisions;
77 std::vector<std::shared_ptr<Object>> bangs;
78
79 unsigned int score = 0;
80 int levelTimer = kLevelTimerStart;
81 int levelTimerDelta = 0;
82 int bombTimer = 0;
83 int bangTimer = 0;
84 int gameOverTimer = 0;
85
86 bool isGameOver = false;
87 bool isWin = false;
88 };
89} // namespace bomberman
90
91#endif // BOMBERMAN_SCENES_SINGLEPLAYER_LEVEL_SCENE_H
92
93
94
Tile
Tile type identifiers used in the tile map.
Definition Const.h:13
Enemy class.
Definition Enemy.h:24
Definition Game.h:23
Shared level-scene scaffold used by both singleplayer and multiplayer.
Definition LevelScene.h:20
Base class for objects.
Definition Object.h:14
Offline/local gameplay implementation of the level scene.
Definition SingleplayerLevelScene.h:22
virtual void updateLevel(unsigned int delta) override
Per-mode update body executed when the scene is not paused.
Definition SingleplayerLevelScene.cpp:115
virtual void onKeyPressed(SDL_Scancode scancode) override
Optional per-mode key-down handling.
Definition SingleplayerLevelScene.cpp:126