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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ set(GAME_OBJECTS
GameObjects/Entities/Towers/magic_tower.cpp
GameObjects/Entities/Towers/cannon_tower.cpp
GameObjects/explosion.cpp
GameObjects/Entities/Traps/bear_trap.cpp
GameObjects/Entities/Traps/bomb.cpp
GameObjects/Interface/coin.cpp
GameObjects/Entities/Projectiles/linear_autoguided_projectile.cpp
GameObjects/Entities/Projectiles/linear_test_projectile.cpp)

Expand Down
18 changes: 18 additions & 0 deletions Controller/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QApplication>
#include <QTimer>
#include <QTextDocument>
#include <iostream>

#include "GameObjects/Entities/Mobs/skeleton.h"
#include "GameObjects/Entities/Mobs/hedgehog.h"
Expand Down Expand Up @@ -99,8 +100,25 @@ void Controller::TickAllTickables() {
base_hp_ = 0;
emit GameOver();
}
RegulateMoney();
std::cout << balance_ << '\n';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Грррррр

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

упс

}

void Controller::DealDamageToBase(int damage) {
// damage_per_current_tick_ += damage;
}

void Controller::RegulateMoney() {
if (scene_->GetCoinsCount() > coins_count_) {
balance_ += Costs::kCoinCost;
}
coins_count_ = scene_->GetCoinsCount();
if (scene_->GetCannonTowersCount() > cannon_tower_count_) {
balance_ -= Costs::kCannonTowerCost;
}
cannon_tower_count_ = scene_->GetCannonTowersCount();
if (scene_->GetMagicTowersCount() > magic_tower_count_) {
balance_ -= Costs::kMagicTowerCost;
}
magic_tower_count_ = scene_->GetMagicTowersCount();
}
9 changes: 9 additions & 0 deletions Controller/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#include <QGraphicsView>

#include "GameObjects/Interface/entity.h"
#include "GameObjects/Interface/coin.h"
#include "game_view.h"
#include "game_scene.h"
#include "level.h"
#include "constants.h"

class Controller : public QObject {
Q_OBJECT
Expand Down Expand Up @@ -35,11 +37,18 @@ class Controller : public QObject {
void SetupScene();
void LaunchTickTimer();

void RegulateMoney();

GameScene* scene_;
GameView* view_;
QTimer* tick_timer_;
Level* level_;
int balance_ = kStartBalance;

int base_hp_;
int damage_per_current_tick_;

int coins_count_ = 0;
int cannon_tower_count_ = 0;
int magic_tower_count_ = 0;
};
7 changes: 7 additions & 0 deletions GameObjects/Entities/Mobs/Basis/mob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <vector>

#include "Controller/controller.h"
#include "GameObjects/Interface/coin.h"
#include "Utilities/Resources/pixmap_loader.h"
#include "constants.h"

Mob::Mob(const VectorF& coordinates,
Animation* animation,
Expand Down Expand Up @@ -58,6 +61,10 @@ Mob::~Mob() {
if (route_ != nullptr) {
route_->RemoveEntity(this);
}
if (rand() % Entities::kCoinAppearChance == 1) { //NOLINT
scene()->addItem(new Coin(VectorF(pos().x(), pos().y()),
PixmapLoader::Pixmaps::kCoinAnimations));
}
}

QRectF Mob::boundingRect() const {
Expand Down
2 changes: 2 additions & 0 deletions GameObjects/Entities/Towers/TowerSlots/tower_slot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ bool TowerSlot::IsTakenUp() const {

void TowerSlot::TakeUpArea(Tower* tower) {
tower_ = tower;
scene()->IncMagicTowersCount();
}

void TowerSlot::ClearArea() {
tower_ = nullptr;
// scene()->DecCannonTowersCount();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Гррррррр

}

TowerSlot::TowerSlot(const VectorF& coordinates)
Expand Down
2 changes: 1 addition & 1 deletion GameObjects/Entities/Towers/cannon_tower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ CannonTower::CannonTower(const VectorF& coordinates) :

void CannonTower::Upgrade() {
Tower::Upgrade();

++Tower::current_level_;
if (current_level_ == 2) {
Tower::cooldown_ = Entities::CannonTower::kAttackCooldownLevel2;
Expand All @@ -37,3 +36,4 @@ void CannonTower::Upgrade() {
void CannonTower::mousePressEvent(QGraphicsSceneMouseEvent* event) {
Upgrade();
}

3 changes: 2 additions & 1 deletion GameObjects/Entities/Towers/magic_tower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ MagicTower::MagicTower(const VectorF& coordinates) :
Entities::MagicTower::kAttackCooldownLevel1,
Entities::MagicTower::kAttackRangeLevel1,
Entities::MagicTower::kMaxLevel,
Entities::MagicTower::kPrice) {}
Entities::MagicTower::kPrice) {
}

void MagicTower::Upgrade() {
Tower::Upgrade();
Expand Down
83 changes: 83 additions & 0 deletions GameObjects/Entities/Traps/bear_trap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "bear_trap.h"
#include "Utilities/Resources/pixmap_loader.h"
#include "constants.h"

#include <iostream>
#include <game_scene.h>
#include <vector>

QRectF BearTrap::boundingRect() const {
return QRectF(QPointF(-15, -15), QSize(30, 30));
}

BearTrap::BearTrap(const VectorF& coordinates, QPixmap* pixmap)
: BearTrap(coordinates,
new Animation(
PixmapLoader::Pixmaps::kBearTrapIdle,
50_ms)) {
attacking_animation_ = new Animation(
PixmapLoader::Pixmaps::kBearTrapAttacking,
50_ms);;
idle_animation_ = new Animation(
PixmapLoader::Pixmaps::kBearTrapIdle,
50_ms);
broken_animation_ = new Animation(
PixmapLoader::Pixmaps::kBearTrapBroken,
50_ms);
repairing_animation_ = new Animation(
PixmapLoader::Pixmaps::kBearTrapBroken,
50_ms);
setFlag(QGraphicsItem::ItemIsFocusable, true);
setScale(2.5);
}

BearTrap::BearTrap(const VectorF& coordinates, Animation* animation)
: Entity(coordinates, animation) {}

void BearTrap::Tick(Time delta) {
if (animation_->WasEndedDuringPreviousUpdate()) {
if (is_broken_) {
animation_ = repairing_animation_;
} else {
animation_ = idle_animation_;
}
}
Entity::Tick(delta);
std::vector<Mob*> mobs = scene()->Mobs();
for (auto mob : mobs) {
if (mob->sceneBoundingRect().intersects(this->sceneBoundingRect())
&& !is_broken_) {
mob->ApplyDamage(Damage(mob->GetHealth()));
animation_ = attacking_animation_;
is_broken_ = true;
}
}
}

void BearTrap::paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget) {
Entity::paint(painter, option, widget);
}

void BearTrap::mousePressEvent(QGraphicsSceneMouseEvent* event) {
if (event->button() != Qt::LeftButton) {
return;
}
RepairTrap();
}

void BearTrap::RepairTrap() {
is_broken_ = false;
animation_ = repairing_animation_;
update();
}

BearTrap::~BearTrap() {
delete idle_animation_;
delete broken_animation_;
delete attacking_animation_;
delete repairing_animation_;
}


27 changes: 27 additions & 0 deletions GameObjects/Entities/Traps/bear_trap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include "GameObjects/Entities/Mobs/Basis/mob.h"

class BearTrap : public Entity {
public:
BearTrap(const VectorF& coordinates, QPixmap* pixmap);
BearTrap(const VectorF& coordinates, Animation* animation);
~BearTrap();

[[nodiscard]] QRectF boundingRect() const;
void paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget);
void Tick(Time delta);
void RepairTrap();

void mousePressEvent(QGraphicsSceneMouseEvent* event) override;

private:
Animation* idle_animation_;
Animation* attacking_animation_;
Animation* broken_animation_;
Animation* repairing_animation_;

bool is_broken_ = false;
};
73 changes: 73 additions & 0 deletions GameObjects/Entities/Traps/bomb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "bomb.h"
#include "Utilities/Resources/pixmap_loader.h"

#include "constants.h"

#include <iostream>
#include <game_scene.h>
#include <vector>

QRectF Bomb::boundingRect() const {
return QRectF(QPointF(-15, -15), QSize(30, 30));
}

Bomb::Bomb(const VectorF& coordinates, QPixmap* pixmap)
: Bomb(coordinates, new Animation(
PixmapLoader::Pixmaps::kBombIdle,
50_ms)) {
idle_animation_ = new Animation(
PixmapLoader::Pixmaps::kBombIdle,
50_ms);
explosion_animation_ = new Animation(
PixmapLoader::Pixmaps::kBombExplosion,
50_ms);
setFlag(QGraphicsItem::ItemIsFocusable, true);
setScale(2.5);
}

Bomb::Bomb(const VectorF& coordinates, Animation* animation)
: Entity(coordinates, animation) {}

void Bomb::Tick(Time delta) {
if (animation_->WasEndedDuringPreviousUpdate()) {
if (activated_) {
animation_ = explosion_animation_;
}
}

Entity::Tick(delta);
if (activated_ && animation_->WasEndedDuringPreviousUpdate()) {
std::vector<Mob*> mobs = scene()->Mobs();
for (auto mob : mobs) {
if (mob->sceneBoundingRect().intersects(this->sceneBoundingRect())) {
mob->ApplyDamage(Damage(mob->GetHealth()));
animation_ = explosion_animation_;
}
}
delete this;
}
}

void Bomb::paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget) {
Entity::paint(painter, option, widget);
}

void Bomb::mousePressEvent(QGraphicsSceneMouseEvent* event) {
if (event->button() != Qt::LeftButton) {
return;
}
Explode();
}

Bomb::~Bomb() {
delete idle_animation_;
delete explosion_animation_;
}

void Bomb::Explode() {
activated_ = true;
}


26 changes: 26 additions & 0 deletions GameObjects/Entities/Traps/bomb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include "GameObjects/Entities/Mobs/Basis/mob.h"

class Bomb : public Entity {
public:
Bomb(const VectorF& coordinates, QPixmap* pixmap);
Bomb(const VectorF& coordinates, Animation* animation);
~Bomb();

[[nodiscard]] QRectF boundingRect() const;
void paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget);
void Tick(Time delta);

void Explode();

void mousePressEvent(QGraphicsSceneMouseEvent* event) override;

private:
Animation* idle_animation_;
Animation* explosion_animation_;

bool activated_ = false;
};
Loading