Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ set(UTILITIES
Utilities/route.cpp
Utilities/wave.cpp
wave_manager.cpp
Utilities/animation.cpp)

Utilities/animation.cpp
Utilities/utility.cpp)

add_executable(Game
${RESOURCES}
${GAME_OBJECTS}
Expand All @@ -51,6 +52,7 @@ add_executable(Game
Controller/controller.cpp
game_view.cpp
constants.cpp
game_scene.cpp)
game_scene.cpp
level.cpp)

target_link_libraries(Game Qt::Core Qt::Gui Qt::Widgets)
54 changes: 50 additions & 4 deletions Controller/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
Controller* Controller::instance;

Controller::Controller() :
scene_(new GameScene(kSceneRect)),
scene_(new GameScene(Scene::kRect)),
view_(new GameView(scene_)),
tick_timer_(new QTimer(this)) {
tick_timer_(new QTimer(this)),
level_(new Level(1)) {
SetupScene();
LaunchTickTimer();
}
Expand All @@ -27,8 +28,12 @@ GameScene* Controller::GetScene() const {
return scene_;
}

Level* Controller::GetLevel() const {
return level_;
}

void Controller::SetupScene() {
{ // temporary code
/*{ // temporary code
QPushButton* close_button = new QPushButton();
QGraphicsProxyWidget* close_button_proxy = scene_->addWidget(close_button);
close_button_proxy->setGeometry(QRectF(
Expand All @@ -51,6 +56,45 @@ void Controller::SetupScene() {
qreal width = sceneRect.width();
qreal height = sceneRect.height();

scene_->addLine(
x + width / 2,
y,
x + width / 2,
y + height,
QPen(Qt::blue));

scene_->addLine(
x,
y + 1,
x + width,
y + 1,
QPen(Qt::blue));

scene_->addLine(
x,
y + height / 2,
x + width,
y + height / 2,
QPen(Qt::blue));
} // temporary code end*/
{ // temporary code
QPushButton* close_button = new QPushButton();
QGraphicsProxyWidget* close_button_proxy = scene_->addWidget(close_button);
close_button_proxy->setGeometry(QRectF(
scene_->sceneRect().topRight() - VectorF{100, 0},
scene_->sceneRect().topRight() + VectorF{0, 100}));

close_button->setText("Close");
QObject::connect(close_button, &QPushButton::clicked, &QApplication::exit);

level_->AddObjectsToScene(scene_);

QRectF sceneRect = scene_->sceneRect();
qreal x = sceneRect.x();
qreal y = sceneRect.y();
qreal width = sceneRect.width();
qreal height = sceneRect.height();

scene_->addLine(
x + width / 2,
y,
Expand Down Expand Up @@ -88,11 +132,13 @@ Controller* Controller::Instance() {
}

void Controller::TickAllTickables() {
Time delta = Time(1000 / 30);
for (QGraphicsItem* graphics_item : scene_->items()) {
if (Tickable* tickable = dynamic_cast<Tickable*>(graphics_item)) {
// TODO(jansenin): make time dependency(it
// could have been more than 1000/30 ms)
tickable->Tick(Time(1000 / 30));
tickable->Tick(delta);
}
}
level_->Tick(delta);
}
5 changes: 5 additions & 0 deletions Controller/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
#include "GameObjects/BasicObjects/Interface/entity.h"
#include "game_view.h"
#include "game_scene.h"
#include "level.h"

class Controller : public QObject {
Q_OBJECT

public:
static Controller* Instance();

[[nodiscard]] GameView* GetView() const;
[[nodiscard]] GameScene* GetScene() const;
[[nodiscard]] Level* GetLevel() const;


public slots:
void TickAllTickables();
Expand All @@ -30,4 +34,5 @@ class Controller : public QObject {
GameScene* scene_;
GameView* view_;
QTimer* tick_timer_;
Level* level_;
};
25 changes: 15 additions & 10 deletions GameObjects/BasicObjects/Entities/Mobs/Basis/mob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@

#include <vector>

std::vector<Route> routes{Route({
QPointF(50, 50),
QPointF(300, 400),
QPointF(-100, -50)})}; // TODO(parfen01): move in level

Mob::Mob(const VectorF& coordinates,
Animation* animation,
int health,
qreal speed)
: Entity(coordinates, animation, health),
speed_(speed) {
route_ = &routes[0];
route_->AddEntity(this);
Entity::setPos(route_->GetStart());
}
speed_(speed) {}

Mob::Mob(const VectorF& coordinates,
QPixmap* pixmap,
Expand All @@ -31,3 +22,17 @@ qreal Mob::GetSpeed() const {
void Mob::SetSpeed(qreal speed) {
speed_ = speed;
}

void Mob::SetRoute(Route* route) {
if (route == nullptr && route_ != nullptr) {
route_->RemoveEntity(this);
}
route_ = route;
if (route_ != nullptr) {
route_->AddEntity(this);
}
}

void Mob::MoveToRouteStart() {
Entity::setPos(route_->GetStart());
}
2 changes: 2 additions & 0 deletions GameObjects/BasicObjects/Entities/Mobs/Basis/mob.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Mob : public Entity {
int health,
qreal speed = 0);

virtual void SetRoute(Route* route);
void MoveToRouteStart();
[[nodiscard]] qreal GetSpeed() const;
void SetSpeed(qreal speed);

Expand Down
14 changes: 10 additions & 4 deletions GameObjects/BasicObjects/Entities/Mobs/test_mob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ void TestMob::Tick(Time delta) {
animation_->SetIndex(animation_->FrameCount() - 1);
deleteLater();
}

if (!is_creating_ && !Mob::route_->isEnd(this)) {
Mob::route_->Move(this, Mob::speed_ * delta.seconds());
if (route_ != nullptr) {
if (!is_creating_ && !route_->isEnd(this)) {
route_->Move(this, speed_ * delta.seconds());
}
}
}

Expand Down Expand Up @@ -50,7 +51,7 @@ TestMob::TestMob(const VectorF& coordinates)
// от моба
new Animation(PixmapLoader::Pixmaps::kFireTotemAppearing, 50_ms),
Entities::TestMob::kHealth,
100),
300),
is_destroying_(false),
idle_animation_(
new Animation(PixmapLoader::Pixmaps::kFireTotemIdle, 50_ms)),
Expand All @@ -77,3 +78,8 @@ void TestMob::ApplyDamage(Damage damage) {
animation_ = disappearing_animation_;
}
}

void TestMob::SetRoute(Route* route) {
Mob::SetRoute(route);
MoveToRouteStart();
}
1 change: 1 addition & 0 deletions GameObjects/BasicObjects/Entities/Mobs/test_mob.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class TestMob : public Mob {

void Tick(Time delta) override;
void ApplyDamage(Damage damage) override;
void SetRoute(Route* route) override;

~TestMob() override;

Expand Down
107 changes: 107 additions & 0 deletions Resources/Levels/Level1/level.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"startMoney": 100,
"towerSlotPositions": [
{
"x": -495,
"y": -160
},
{
"x": -140,
"y": 60
}
],
"routes": [
{
"points": [
{
"x": -200,
"y": -200
},
{
"x": 600,
"y": 0
},
{
"x": 100,
"y": 100
}
]
},
{
"points": [
{
"x": -1000,
"y": -10
},
{
"x": -640,
"y": -10
},
{
"x": -640,
"y": -300
},
{
"x": -260,
"y": -310
},
{
"x": -260,
"y": 110
},
{
"x": 250,
"y": 110
},
{
"x": 250,
"y": -80
},
{
"x": 1000,
"y": -80
}
]
}
],
"waves": [
{
"startTimeRelativeToPrevWave": 0,
"spawnEntries": [
{
"mobType": "TestMob",
"count": 4,
"startTime": 0,
"entryDuration": 1000,
"routeIndex": 1
},
{
"mobType": "TestMob",
"count": 4,
"startTime": 2000,
"entryDuration": 1000,
"routeIndex": 1
},
{
"mobType": "TestMob",
"count": 4,
"startTime": 4000,
"entryDuration": 1000,
"routeIndex": 1
}
]
},
{
"startTimeRelativeToPrevWave": 5000,
"spawnEntries": [
{
"mobType": "TestMob",
"count": 30,
"startTime": 0,
"entryDuration": 2000,
"routeIndex": 0
}
]
}
]
}
Binary file added Resources/Levels/Level1/map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Resources/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
<file>images/test_tower_gun.png</file>
<file>images/test_tower_slot.png</file>
<file>images/fire_totem.png</file>
<file>Levels/Level1/map.png</file>
<file>Levels/Level1/level.json</file>
</qresource>
</RCC>
12 changes: 9 additions & 3 deletions Utilities/Resources/pixmap_loader.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "pixmap_loader.h"

#include <utility>

#include "constants.h"
#include "pixmap_loader.h"

using P = PixmapLoader::Pixmaps;

QPixmap* P::kBackground;
Expand All @@ -10,6 +11,7 @@ QPixmap* P::kTestMob;
QPixmap* P::kTestTower;
QPixmap* P::kTestTowerGun;
QPixmap* P::kTestTowerSlot;
std::vector<QPixmap*> P::kLevelMaps;

QPixmap* P::kFireTotemAnimations;
std::vector<QPixmap*> P::kFireTotemIdle;
Expand All @@ -23,7 +25,11 @@ void PixmapLoader::LoadPixmaps() {
P::kTestTower = new QPixmap(":images/test_tower.png");
P::kTestTowerGun = new QPixmap(":images/test_tower_gun.png");
P::kTestTowerSlot = new QPixmap(":images/test_tower_slot.png");

for (int i = 1; i <= LevelData::kLevelsCount; ++i) {
P::kLevelMaps.push_back(new QPixmap(":Levels/Level"
+ QString::number(i)
+ "/map.png"));
}
LoadFireTotemAnimations();
}

Expand Down
1 change: 1 addition & 0 deletions Utilities/Resources/pixmap_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class PixmapLoader {
static QPixmap* kTestTower;
static QPixmap* kTestTowerGun;
static QPixmap* kTestTowerSlot;
static std::vector<QPixmap*> kLevelMaps;

// For animations test
static QPixmap* kFireTotemAnimations;
Expand Down
1 change: 0 additions & 1 deletion Utilities/route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ VectorF Route::GetStart() const {
void Route::RemoveEntity(Entity* entity) {
entity_indexes_.erase(entity);
}

Loading