forked from jansenin/Game
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_scene.cpp
More file actions
98 lines (81 loc) · 2.11 KB
/
game_scene.cpp
File metadata and controls
98 lines (81 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "game_scene.h"
#include "GameObjects/Interface/graphics_object.h"
#include "game_view.h"
#include "GameObjects/Entities/Mobs/Basis/mob.h"
#include "GameObjects/Entities/Towers/tower.h"
#include "GameObjects/Entities/Towers/TowerSlots/tower_slot.h"
#include "GameObjects/Entities/Projectiles/projectile.h"
GameScene::GameScene(const QRectF& scene_rect, QObject* parent)
: QGraphicsScene(scene_rect, parent) {}
GameView* GameScene::view() {
auto result = dynamic_cast<GameView*>(QGraphicsScene::views().at(0));
assert(result != nullptr);
return result;
}
std::vector<Mob*> GameScene::Mobs() const {
std::vector<Mob*> result;
for (auto item : items()) {
if (auto mob = dynamic_cast<Mob*>(item)) {
result.push_back(mob);
}
}
return result;
}
std::vector<Tower*> GameScene::Towers() const {
std::vector<Tower*> result;
for (auto item : items()) {
if (auto tower = dynamic_cast<Tower*>(item)) {
result.push_back(tower);
}
}
return result;
}
std::vector<TowerSlot*> GameScene::TowerSlots() const {
std::vector<TowerSlot*> result;
for (auto item : items()) {
if (auto tower_slot = dynamic_cast<TowerSlot*>(item)) {
result.push_back(tower_slot);
}
}
return result;
}
std::vector<Projectile*> GameScene::Projectiles() const {
std::vector<Projectile*> result;
for (auto item : items()) {
if (auto projectile = dynamic_cast<Projectile*>(item)) {
result.push_back(projectile);
}
}
return result;
}
void GameScene::IncCoinsCount() {
++coins_count_;
}
void GameScene::DecCoinsCount() {
if (coins_count_ > 0) {
--coins_count_;
}
}
void GameScene::IncCannonTowersCount() {
++cannon_tower_count_;
}
void GameScene::DecCannonTowersCount() {
if (cannon_tower_count_ > 0) {
--cannon_tower_count_;
}
}
int GameScene::GetCoinsCount() {
return coins_count_;
}
int GameScene::GetCannonTowersCount() {
return cannon_tower_count_;
}
void GameScene::IncMagicTowersCount() {
++magic_tower_count_;
}
void GameScene::DecMagicTowersCount() {
--magic_tower_count_;
}
int GameScene::GetMagicTowersCount() {
return magic_tower_count_;
}