-
Notifications
You must be signed in to change notification settings - Fork 1
make customizable base classes #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
GameObjects/BasicObjects/Entities/Projectiles/autoguided_projectile.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #include "projectile.h" | ||
|
|
||
| Projectile::Projectile(const VectorF& coordinates, QPixmap* pixmap) | ||
| : Entity(coordinates, pixmap) {} |
10 changes: 10 additions & 0 deletions
10
GameObjects/BasicObjects/Entities/Projectiles/projectile.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #pragma once | ||
|
|
||
| #include "GameObjects/BasicObjects/Interface/entity.h" | ||
|
|
||
| class Projectile : public Entity { | ||
| public: | ||
| Projectile(const VectorF& coordinates, QPixmap* pixmap); | ||
| }; | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #include "graphics_item.h" | ||
|
|
||
| GraphicsItem::GraphicsItem(QGraphicsItem* parent) : QGraphicsItem(parent) {} | ||
|
|
||
| GameScene* GraphicsItem::scene() { | ||
| auto result = dynamic_cast<GameScene*>(QGraphicsItem::scene()); | ||
| assert(result != nullptr); | ||
| return result; | ||
| } | ||
|
|
||
| GameView* GraphicsItem::view() { | ||
| return scene()->view(); | ||
| } | ||
|
|
||
| void GraphicsItem::MoveBy(const VectorF& delta) { | ||
| setPos(pos() + delta); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #pragma once | ||
|
|
||
| #include "QGraphicsItem" | ||
|
|
||
| #include "Utilities/vector_f.h" | ||
| #include "game_scene.h" | ||
| #include "game_view.h" | ||
|
|
||
| class GraphicsItem : public QGraphicsItem { | ||
| public: | ||
| explicit GraphicsItem(QGraphicsItem* parent = nullptr); | ||
|
|
||
| GameScene* scene(); | ||
| GameView* view(); | ||
|
|
||
| void MoveBy(const VectorF& delta); | ||
| }; | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| #include "game_scene.h" | ||
|
|
||
| #include "GameObjects/BasicObjects/Interface/graphics_item.h" | ||
| #include "game_view.h" | ||
| #include "GameObjects/BasicObjects/Entities/Mobs/Basis/mob.h" | ||
| #include "GameObjects/BasicObjects/Entities/Towers/tower.h" | ||
| #include "GameObjects/BasicObjects/Entities/Towers/TowerSlots/tower_slot.h" | ||
| #include "GameObjects/BasicObjects/Entities/Projectiles/projectile.h" | ||
|
|
||
| GameScene::GameScene(const QRectF& scene_rect, QObject* parent) | ||
| : QGraphicsScene(scene_rect, parent), | ||
| mobs_(std::set<Mob*>()), | ||
| towers_(std::set<Tower*>()), | ||
| tower_slots_(std::set<TowerSlot*>()), | ||
| projectiles_(std::set<Projectile*>()) {} | ||
|
|
||
| GameView* GameScene::view() { | ||
| auto result = dynamic_cast<GameView*>(QGraphicsScene::views().at(0)); | ||
| assert(result != nullptr); | ||
| return result; | ||
| } | ||
|
|
||
| void GameScene::removeItem(GraphicsItem* item) { | ||
| auto mob = dynamic_cast<Mob*>(item); | ||
| if (mob != nullptr) { | ||
| mobs_.erase(mob); | ||
| } | ||
|
|
||
| auto tower = dynamic_cast<Tower*>(item); | ||
| if (tower != nullptr) { | ||
| towers_.erase(tower); | ||
| } | ||
|
|
||
| auto tower_slot = dynamic_cast<TowerSlot*>(item); | ||
| if (tower_slot != nullptr) { | ||
| tower_slots_.erase(tower_slot); | ||
| } | ||
|
|
||
| auto projectile = dynamic_cast<Projectile*>(item); | ||
| if (projectile != nullptr) { | ||
| projectiles_.erase(projectile); | ||
| } | ||
|
|
||
| QGraphicsScene::removeItem(item); | ||
| } | ||
|
|
||
| void GameScene::clear() { | ||
| mobs_.clear(); | ||
| towers_.clear(); | ||
| tower_slots_.clear(); | ||
| projectiles_.clear(); | ||
|
|
||
| QGraphicsScene::clear(); | ||
| } | ||
|
|
||
| void GameScene::addItem(GraphicsItem* item) { | ||
| auto mob = dynamic_cast<Mob*>(item); | ||
| if (mob != nullptr) { | ||
| mobs_.erase(mob); | ||
| } | ||
|
|
||
| auto tower = dynamic_cast<Tower*>(item); | ||
| if (tower != nullptr) { | ||
| towers_.erase(tower); | ||
| } | ||
|
|
||
| auto tower_slot = dynamic_cast<TowerSlot*>(item); | ||
| if (tower_slot != nullptr) { | ||
| tower_slots_.erase(tower_slot); | ||
| } | ||
|
|
||
| auto projectile = dynamic_cast<Projectile*>(item); | ||
| if (projectile != nullptr) { | ||
| projectiles_.erase(projectile); | ||
| } | ||
|
|
||
| QGraphicsScene::addItem(item); | ||
| } | ||
|
|
||
| const std::set<Mob*>& GameScene::Mobs() const { | ||
| return mobs_; | ||
| } | ||
|
|
||
| const std::set<Tower*>& GameScene::Towers() const { | ||
| return towers_; | ||
| } | ||
|
|
||
| const std::set<TowerSlot*>& GameScene::TowerSlots() const { | ||
| return tower_slots_; | ||
| } | ||
|
|
||
| const std::set<Projectile*>& GameScene::Projectiles() const { | ||
| return projectiles_; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #pragma once | ||
|
|
||
| #include <set> | ||
|
|
||
| #include <QGraphicsScene> | ||
| #include <QList> | ||
|
|
||
| class GraphicsItem; | ||
| class GameView; | ||
| class Mob; | ||
| class Tower; | ||
| class TowerSlot; | ||
| class Projectile; | ||
|
|
||
| class GameScene : public QGraphicsScene { | ||
| public: | ||
| explicit GameScene(const QRectF& scene_rect, QObject* parent = nullptr); | ||
|
|
||
| GameView* view(); | ||
|
|
||
| void removeItem(GraphicsItem* item); | ||
| void clear(); | ||
| void addItem(GraphicsItem* item); | ||
|
|
||
| [[nodiscard]] const std::set<Mob*>& Mobs() const; | ||
| [[nodiscard]] const std::set<Tower*>& Towers() const; | ||
| [[nodiscard]] const std::set<TowerSlot*>& TowerSlots() const; | ||
| [[nodiscard]] const std::set<Projectile*>& Projectiles() const; | ||
|
|
||
| private: | ||
| std::set<Mob*> mobs_; | ||
| std::set<Tower*> towers_; | ||
| std::set<TowerSlot*> tower_slots_; | ||
| std::set<Projectile*> projectiles_; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.