From 3923e9e85df0ef7fbfc6e73214430130cc82b322 Mon Sep 17 00:00:00 2001 From: Egor Date: Fri, 3 Jun 2022 16:17:06 +0300 Subject: [PATCH 1/4] created trap, bomb, coins --- CMakeLists.txt | 3 + GameObjects/Entities/Traps/bear_trap.cpp | 70 +++++++++++++ GameObjects/Entities/Traps/bear_trap.h | 27 +++++ GameObjects/Entities/Traps/bomb.cpp | 66 ++++++++++++ GameObjects/Entities/Traps/bomb.h | 26 +++++ GameObjects/Interface/coin.cpp | 56 ++++++++++ GameObjects/Interface/coin.h | 25 +++++ Resources/images/bear_trap.png | Bin 0 -> 825 bytes Resources/images/bomb0.png | Bin 0 -> 378 bytes Resources/images/bomb1.png | Bin 0 -> 393 bytes Resources/images/bomb2.png | Bin 0 -> 429 bytes Resources/images/bomb3.png | Bin 0 -> 393 bytes Resources/images/bomb4.png | Bin 0 -> 345 bytes Resources/images/bomb5.png | Bin 0 -> 333 bytes Resources/images/coin.png | Bin 0 -> 625 bytes Resources/resources.qrc | 9 +- Utilities/Resources/pixmap_loader.cpp | 125 +++++++++++++++++++++++ Utilities/Resources/pixmap_loader.h | 23 +++++ constants.cpp | 1 + constants.h | 1 + level.cpp | 12 +++ level.h | 4 + 22 files changed, 447 insertions(+), 1 deletion(-) create mode 100644 GameObjects/Entities/Traps/bear_trap.cpp create mode 100644 GameObjects/Entities/Traps/bear_trap.h create mode 100644 GameObjects/Entities/Traps/bomb.cpp create mode 100644 GameObjects/Entities/Traps/bomb.h create mode 100644 GameObjects/Interface/coin.cpp create mode 100644 GameObjects/Interface/coin.h create mode 100644 Resources/images/bear_trap.png create mode 100644 Resources/images/bomb0.png create mode 100644 Resources/images/bomb1.png create mode 100644 Resources/images/bomb2.png create mode 100644 Resources/images/bomb3.png create mode 100644 Resources/images/bomb4.png create mode 100644 Resources/images/bomb5.png create mode 100644 Resources/images/coin.png diff --git a/CMakeLists.txt b/CMakeLists.txt index 24d0d56..7dac5e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,9 @@ set(GAME_OBJECTS GameObjects/Entities/Mobs/hedgehog.cpp GameObjects/Entities/Mobs/dwarf.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) diff --git a/GameObjects/Entities/Traps/bear_trap.cpp b/GameObjects/Entities/Traps/bear_trap.cpp new file mode 100644 index 0000000..6749da8 --- /dev/null +++ b/GameObjects/Entities/Traps/bear_trap.cpp @@ -0,0 +1,70 @@ +#include "bear_trap.h" +#include "Utilities/Resources/pixmap_loader.h" +#include "GameObjects/Entities/Mobs/test_mob.h" +#include "constants.h" + + +#include +#include + +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 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_; +} + + diff --git a/GameObjects/Entities/Traps/bear_trap.h b/GameObjects/Entities/Traps/bear_trap.h new file mode 100644 index 0000000..752517b --- /dev/null +++ b/GameObjects/Entities/Traps/bear_trap.h @@ -0,0 +1,27 @@ +#pragma once + +#include "GameObjects/Interface/entity.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; +}; diff --git a/GameObjects/Entities/Traps/bomb.cpp b/GameObjects/Entities/Traps/bomb.cpp new file mode 100644 index 0000000..f7ad982 --- /dev/null +++ b/GameObjects/Entities/Traps/bomb.cpp @@ -0,0 +1,66 @@ +#include "bomb.h" +#include "Utilities/Resources/pixmap_loader.h" +#include "GameObjects/Entities/Mobs/test_mob.h" +#include "constants.h" + + +#include +#include + +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 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; +} + + diff --git a/GameObjects/Entities/Traps/bomb.h b/GameObjects/Entities/Traps/bomb.h new file mode 100644 index 0000000..5d32613 --- /dev/null +++ b/GameObjects/Entities/Traps/bomb.h @@ -0,0 +1,26 @@ +#pragma once + +#include "GameObjects/Interface/entity.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; +}; diff --git a/GameObjects/Interface/coin.cpp b/GameObjects/Interface/coin.cpp new file mode 100644 index 0000000..9c99221 --- /dev/null +++ b/GameObjects/Interface/coin.cpp @@ -0,0 +1,56 @@ +#include "coin.h" +#include "Utilities/Resources/pixmap_loader.h" +#include "GameObjects/Entities/Mobs/test_mob.h" +#include "constants.h" + + +#include +#include + +Coin::Coin(const VectorF& coordinates, QPixmap* pixmap) + : Coin(coordinates, new Animation(PixmapLoader::Pixmaps::kCoinIdle, 50_ms)) { + idle_animation_ = new Animation(PixmapLoader::Pixmaps::kCoinIdle, 50_ms); + collecting_route_ = nullptr; + speed_ = 300; + setFlag(QGraphicsItem::ItemIsFocusable, true); + setScale(2.5); +} + +Coin::Coin(const VectorF& coordinates, Animation* animation) + : Entity(coordinates, animation) {} + +void Coin::Tick(Time delta) { + if (animation_->WasEndedDuringPreviousUpdate()) { + animation_ = idle_animation_; + } + if (collecting_route_ != nullptr) { + collecting_route_->Move(this, delta.ms() * speed_); + } + Entity::Tick(delta); +} + +void Coin::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { + Entity::paint(painter, option, widget); +} + +void Coin::mousePressEvent(QGraphicsSceneMouseEvent* event) { +// delete this; + SetRoute(); + // add money + +} + + +Coin::~Coin() { + delete idle_animation_; +} + +void Coin::SetRoute() { + std::vector points; + points.emplace_back(pos().x(), pos().y()); + points.emplace_back(500, 500); + collecting_route_ = new Route(points); + collecting_route_->AddEntity(this); +} + + diff --git a/GameObjects/Interface/coin.h b/GameObjects/Interface/coin.h new file mode 100644 index 0000000..a180bd6 --- /dev/null +++ b/GameObjects/Interface/coin.h @@ -0,0 +1,25 @@ +#pragma once + +#include "GameObjects/Interface/entity.h" +#include "Utilities/route.h" + +class Coin : public Entity { + public: + Coin(const VectorF& coordinates, QPixmap* pixmap); + Coin(const VectorF& coordinates, Animation* animation); + ~Coin(); + + void paint(QPainter* painter, + const QStyleOptionGraphicsItem* option, + QWidget* widget); + void Tick(Time delta); + + void SetRoute(); + + void mousePressEvent(QGraphicsSceneMouseEvent* event) override; + + private: + Animation* idle_animation_; + Route* collecting_route_; + qreal speed_; +}; diff --git a/Resources/images/bear_trap.png b/Resources/images/bear_trap.png new file mode 100644 index 0000000000000000000000000000000000000000..11f3160205af0a900095e0b555a23c2c7dd2e62a GIT binary patch literal 825 zcmV-91IGM`P)U2qM^G4`LPXPeGtWSlliHPXcn|Hpxp#IPA zAE9YlVROiP{rB^lSlRHxYx@VK=n>J@jo+qEL{y{`#ObHuULKPv6562lxweDa{sC(H z2Usm;SS@C;_v|_cZ9|+skIPd(NZk6*Gd0&v|KvJ#9WH3ER}8pvrl?|Ph6zbNw756u9*^N|;U zY;?5^0DE;Edv)E{2V8ds^|#UxWw>AjWJ!O!P!;`92N?8+z7);^SC^K?A5KSVpE?$R z&vEjAGtpjM_i7+N0*3}Uj%vUhdRJvL-*1R|9BFC;JD{6PcY~Y)6Odq905@j z`8bwDzew`Xk39sQn&vgnYIVBQ>U4=6gb#!2n5#=mJ2g!V`om1=Davr1c{l>fPQO*s zk92^;hVCl`T+3bC@nr{<-uZ~8XGZ3_pN1+#;7#i%dK2i{j^_mG>HgF-aq;^PxZOJ+ z(V#!XMZ+L>llF^@4vql6E}JUoN7hF+dNA5K1#y3{&8P>*OtXvN!6So!|C=y8hW7CN z?vI^!O+T^(g#EkZ+72dT3;Zr%GPX)J{`Ac7wabpaD(NROj(Xq&*2aDOWIYMjc0$v9 zQIADUqfKhoSPx$G)Y83R9HvtmO&1|P!NWvCy=mZDQb{+hx6$Qt2ibY`2CLhE(m&J38_Fr zVAJSEnStL;OLqGMn}S3@1ShJVND*6*3I0WbZICOl62SW-nlIV-xdJOVr683sCEx^d zC4gJ8-fXySHcqNs0{6!aikJh|5|ZxOc<|4J#%r}w6TiPoyO#)HO)7yOOd<%zLlQl8 z!wn*;dy_Clkp(VIAeF!q+7eyj1<{9 literal 0 HcmV?d00001 diff --git a/Resources/images/bomb1.png b/Resources/images/bomb1.png new file mode 100644 index 0000000000000000000000000000000000000000..5c03b8b08a1acb8be2d46c6c0e2d4c2fbf5dec76 GIT binary patch literal 393 zcmV;40e1e0P)Px$K}keGR9HvtmO%=_Fc3v2ClGY&S`ZYitL|KQ3@@M;QV*cFP-st}3qf%0R>2cQ zCUi=al9{Bf-LxC4j`?q1(nJLfU#j7JXaQOSwHwd?8W*|(P-5HL*N@12nORNQSW;ienGfY_=HOhP@XvrX-aH}EY!CtQ_pS1Ma{bY4~W-E5Uuy< nf**t!5DY6XX#pBH@BwphU?ES5k*WXy002ovPDHLkV1fVu_WzrG literal 0 HcmV?d00001 diff --git a/Resources/images/bomb2.png b/Resources/images/bomb2.png new file mode 100644 index 0000000000000000000000000000000000000000..65af93cd1c5fb3e967d43d7d7282764279c39204 GIT binary patch literal 429 zcmV;e0aE^nP)Px$W=TXrR9HvtmO)MeF%*VhPhf&u-I8E53LDt5@EBe|FXVUtxrHXol9euuCT?M? zi6^LeFZ`1Z4()4)I-8jVfwc7h`n~dsp^hKZaX$3`*$u4Ur}p%0B{@y+vjcFjC9;N^ z%bgv7!x@4BToBm!7XX9<#Qo)E1;FkRh%&fmAqRjcXX{Yzs^2{iDF6s)GHLH_Z|J^w zBx7W0d2vnbT8IIV;OqHZf`_9M`uy0?({hP08eg5u*lc$B2V!5x)dE-q`&u`{OvV@0 zl$Y1H%0e3eRX74%BPf9nI%FU!ya6J#e(*9%0^sveJS>9xLlct1VL=PwQ`7^rGQg#H zF3V7vy@#+B!1vD=9ik5;Luhs%)WdBY?R9W;?CU4BG41X(0CJZAfPx$K}keGR9Hvtmc0_eKoH0GdX-AUs14(z;TbeW?FD!t@c^`p#yhAej5=sk8v2;M zv6=IAySa!oNkfu#|KI-Za-tyRL#3P#89-(raRaA)J1ADxUvvHjfFSt9y}~38z&++k z0O(EuK#_j)^VNb200o%M(Kx|qIDoM?1*P;Qc6_$LNYTOlQchngbbD}KEn$ARQW!KF zRei71slP$QT>}9H+vXHuTFqKmvf1uf3lamOa7s0e{9+0sg@1rx8{`U{0C0VHlNqa@ zD{u-Y3sMN1feav)0i24(@y1QFb*G92;OEQmi+#WuLef2}2LJ-vUdtDs`(q35OS_i< zU`+^tCpHia#zUf>Xt|Au>YgBMDx!o-4TKQ*g{H)Wc!Wl6O4mybn0dDM0r5IPx$5=lfsR9HvtmQ4_5H46{Bu)awE$${j+Upmka*#b2O6@7#i3;5H#PhXu5=6bsu zYu%K(zgpm_IN?WGx~WUsnsZT@ZC$gNS!J2~wmI%$2o#`aVJW%^W}W9_$+PQJ7Z3nQ zoK<~C<~V{N@gERsgIYlp0NoG7e(ijs#MuQDLUJGhOmcvZV%IdPx$2T4RhR9HvtmQ50aAPj|*J9I(se>h$A4(Ws%8WAC6w9HuD^iO%;dxWG2gD)Jc z5B~u`FCcuB&0af!nsceWpC^z*oen?%ga9b7`KdbTJnnHjuO@J7`O6%_xWDh_T7WJ8h<{5xU#MZwRAY?l{TRNmOeVoT@c~>=Q zNx&wa?0pl_Td+5CS^$0GTZq>B&0*vM;QDxSeW)VzB;XRy&V3W27SRoGClDK-sR0#A z+|q=a73u{z>KLlF()Zul>fVw-H$;zk4?r4(wOO2vW>aj literal 0 HcmV?d00001 diff --git a/Resources/images/coin.png b/Resources/images/coin.png new file mode 100644 index 0000000000000000000000000000000000000000..6bce34cf1521a056b7bfa342d8620e4f2666be37 GIT binary patch literal 625 zcmV-%0*?KOP)Px%D@jB_RA_$}vG2s$|Y_e}u+=s(_b*`PzpYgoei`$?>Yq*7s^|ubu(}wh6hqv>-~mua8XI?L zcpgi6X#+lAxj#A&Um|`!>j6+SKwU{3jzuw+HIVn-nGVYG`LM(D>~OIAryGTfF+BjF zuCVUz*d;dZVDJEKoJ2P2n7*HjcsG7sVZA83*f!5&UFNf%JD6#G0vV1=5*zjy|i2A47_WTtrIlRS4Nz1|Hi9^8pj`HPJ&W|Rl@uh5k zuy6-A)6qmUrb}I|=3c`p)=k5cy3>yTU$wu*5o|z<#j>BAP!7ckax-DCY{oS6R$K^Kw{H9^xn|w{x|7z8 zwstxFW7`mkJaa36@RDr=|4yo88$ruAcLPP+5Z-NkEr0CW5W$UjavR+XXA(mW4WFY3 z8$RdQnRwzjv=0Df?P(pX{;@~V()iquV%ei;NBSt5#bU8oET@@Y(|8%}c>P?900000 LNkvXXu0mjf;1w;1 literal 0 HcmV?d00001 diff --git a/Resources/resources.qrc b/Resources/resources.qrc index 7153579..c3666b2 100644 --- a/Resources/resources.qrc +++ b/Resources/resources.qrc @@ -25,7 +25,14 @@ images/explosion.png - + images/bear_trap.png + images/bomb0.png + images/bomb1.png + images/bomb2.png + images/bomb3.png + images/bomb4.png + images/bomb5.png + images/coin.png GUI/Textured boxes/Default/top_left_corner.png GUI/Textured boxes/Default/top_right_corner.png diff --git a/Utilities/Resources/pixmap_loader.cpp b/Utilities/Resources/pixmap_loader.cpp index 417d6ba..74076d3 100644 --- a/Utilities/Resources/pixmap_loader.cpp +++ b/Utilities/Resources/pixmap_loader.cpp @@ -14,6 +14,27 @@ QPixmap* P::kTestTowerSlot; std::vector P::kLevelMaps; QPixmap* P::kEmpty; +QPixmap* P::kBombIdleFrame; +QPixmap* P::kBomb0; +QPixmap* P::kBomb1; +QPixmap* P::kBomb2; +QPixmap* P::kBomb3; +QPixmap* P::kBomb4; +QPixmap* P::kBomb5; +std::vector P::kBombExplosion; +std::vector P::kBombIdle; + +QPixmap* P::kBearTrap; +QPixmap* P::kBearTrapAnimations; +std::vector P::kBearTrapIdle; +std::vector P::kBearTrapAttacking; +std::vector P::kBearTrapBroken; +std::vector P::kBearTrapRepairing; + +std::vector P::kCoinIdle; +QPixmap* P::kCoinAnimations; + + QPixmap* P::FireTotem::kAnimations; std::vector P::FireTotem::kIdle; std::vector P::FireTotem::kDisappear; @@ -49,6 +70,7 @@ void PixmapLoader::LoadPixmaps() { P::kTestMob = new QPixmap(":images/test_mob.png"); P::kTestTower = new QPixmap(":images/test_tower.png"); P::kTestTowerGun = new QPixmap(":images/test_tower_gun.png"); + P::kBearTrap = new QPixmap(":images/bear_trap.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" @@ -57,6 +79,9 @@ void PixmapLoader::LoadPixmaps() { } P::kEmpty = new QPixmap(); + LoadBearTrapAnimations(); + LoadBombAnimations(); + LoadCoinAnimations(); LoadFireTotemAnimations(); LoadSkeletonAnimations(); LoadCobraAnimations(); @@ -351,3 +376,103 @@ void PixmapLoader::LoadButtonTextureBox() { new QPixmap(":GUI/Textured boxes/Button/inside.png") }; } + +void PixmapLoader::LoadBearTrapAnimations() { + // file size - 128x32 + // 1 frame row, 4 frame columns + const int frame_width = 128 / 4; + const int frame_height = 32; + const int idle_animation_frames_count = 1; + const int attack_animation_frames_count = 3; + const int broken_animation_frames_count = 1; + const int repairing_animation_frames_count = 1; + // row and column start from 0 + const int idle_animation_row = 0; + const int idle_animation_column = 0; + const int attack_animation_row = 0; + const int attack_animation_column = 1; + const int broken_animation_row = 0; + const int broken_animation_column = 3; + const int repairing_animation_row = 0; + const int repairing_animation_column = 0; + + P::kBearTrapAnimations = new QPixmap(":images/bear_trap.png"); + + P::kBearTrapIdle = CreateHorizontalFramesVector( + P::kBearTrapAnimations, + frame_width, + frame_height, + idle_animation_frames_count, + idle_animation_column * frame_width, + idle_animation_row * frame_height); + + P::kBearTrapBroken = CreateHorizontalFramesVector( + P::kBearTrapAnimations, + frame_width, + frame_height, + broken_animation_frames_count, + broken_animation_column * frame_width, + broken_animation_row * frame_height); + + P::kBearTrapAttacking = CreateHorizontalFramesVector( + P::kBearTrapAnimations, + frame_width, + frame_height, + attack_animation_frames_count, + attack_animation_column * frame_width, + attack_animation_row * frame_height); + + P::kBearTrapAttacking = CreateHorizontalFramesVector( + P::kBearTrapAnimations, + frame_width, + frame_height, + attack_animation_frames_count, + attack_animation_column * frame_width, + attack_animation_row * frame_height); + + P::kBearTrapRepairing = CreateHorizontalFramesVector( + P::kBearTrapAnimations, + frame_width, + frame_height, + repairing_animation_frames_count, + repairing_animation_column * frame_width, + repairing_animation_row * frame_height); +} + +void PixmapLoader::LoadBombAnimations() { + P::kBombIdleFrame = new QPixmap(":images/bomb0.png"); + P::kBomb0 = new QPixmap(":images/bomb0.png"); + P::kBomb1 = new QPixmap(":images/bomb1.png"); + P::kBomb2 = new QPixmap(":images/bomb2.png"); + P::kBomb3 = new QPixmap(":images/bomb3.png"); + P::kBomb4 = new QPixmap(":images/bomb4.png"); + P::kBomb5 = new QPixmap(":images/bomb5.png"); + P::kBombExplosion.push_back(P::kBomb0); + P::kBombExplosion.push_back(P::kBomb1); + P::kBombExplosion.push_back(P::kBomb2); + P::kBombExplosion.push_back(P::kBomb3); + P::kBombExplosion.push_back(P::kBomb4); + P::kBombExplosion.push_back(P::kBomb5); + P::kBombIdle.push_back(P::kBombIdleFrame); +} + +void PixmapLoader::LoadCoinAnimations() { + // file size - 224x16 + // 1 frame rows, 14 frame columns + const int frame_width = 224 / 14; + const int frame_height = 16; + const int idle_animation_frames_count = 14; + // row and column start from 0 + const int idle_animation_row = 0; + const int idle_animation_column = 0; + + P::kCoinAnimations = new QPixmap(":images/coin.png"); + + P::kCoinIdle = CreateHorizontalFramesVector( + P::kCoinAnimations, + frame_width, + frame_height, + idle_animation_frames_count, + idle_animation_column * frame_width, + idle_animation_row * frame_height); +} \ No newline at end of file diff --git a/Utilities/Resources/pixmap_loader.h b/Utilities/Resources/pixmap_loader.h index 02228d4..2a6ac74 100644 --- a/Utilities/Resources/pixmap_loader.h +++ b/Utilities/Resources/pixmap_loader.h @@ -21,6 +21,26 @@ class PixmapLoader { static std::vector kLevelMaps; static QPixmap* kEmpty; + static QPixmap* kBearTrap; + static QPixmap* kBearTrapAnimations; + static std::vector kBearTrapIdle; + static std::vector kBearTrapAttacking; + static std::vector kBearTrapBroken; + static std::vector kBearTrapRepairing; + + static std::vector kCoinIdle; + static QPixmap* kCoinAnimations; + + static QPixmap* kBomb0; + static QPixmap* kBomb1; + static QPixmap* kBomb2; + static QPixmap* kBomb3; + static QPixmap* kBomb4; + static QPixmap* kBomb5; + static std::vector kBombExplosion; + static std::vector kBombIdle; + static QPixmap* kBombIdleFrame; + class FireTotem { public: static QPixmap* kAnimations; @@ -81,6 +101,9 @@ class PixmapLoader { static void LoadHedgehogAnimations(); static void LoadDwarfAnimations(); static void LoadExplosionAnimation(); + static void LoadBearTrapAnimations(); + static void LoadBombAnimations(); + static void LoadCoinAnimations(); static void LoadUI(); static void LoadDefaultTextureBox(); diff --git a/constants.cpp b/constants.cpp index 0b1c527..9428429 100644 --- a/constants.cpp +++ b/constants.cpp @@ -38,6 +38,7 @@ const QString kSkeletonId = "Skeleton"; const QString kCobraId = "Cobra"; const QString kHedgehogId = "Hedgehog"; const QString kDwarfId = "Dwarf"; +const int kCoinAppearChance = 3; namespace TestTower { const qreal kAttackRange = 300; diff --git a/constants.h b/constants.h index 613f92a..624fb56 100644 --- a/constants.h +++ b/constants.h @@ -39,6 +39,7 @@ extern const QString kSkeletonId; extern const QString kCobraId; extern const QString kHedgehogId; extern const QString kDwarfId; +extern const int kCoinAppearChance; namespace TestTower { extern const qreal kAttackRange; diff --git a/level.cpp b/level.cpp index 04627c0..56632a5 100644 --- a/level.cpp +++ b/level.cpp @@ -44,6 +44,12 @@ Level::Level(int level_number) : level_number_(level_number) { tower_slots_.push_back( new TestTowerSlot(VectorF(tower_slot_x, tower_slot_y))); } + { + bear_traps_.push_back(new BearTrap(VectorF(150, 150), PixmapLoader::Pixmaps::kTestTowerSlot)); // check + } + { + bombs_.push_back(new Bomb(VectorF(0, 150), PixmapLoader::Pixmaps::kTestTowerSlot)); // test + } QJsonArray routes = root.value("routes").toArray(); routes_.reserve(routes.size()); @@ -109,6 +115,12 @@ void Level::AddObjectsToScene(GameScene* scene) { for (auto tower_slot : tower_slots_) { scene->addItem(tower_slot); } + for (auto bear_trap : bear_traps_) { + scene->addItem(bear_trap); + } + for (auto bomb : bombs_) { + scene->addItem(bomb); + } } void Level::Tick(Time delta) { diff --git a/level.h b/level.h index ee099b7..c957ced 100644 --- a/level.h +++ b/level.h @@ -10,6 +10,8 @@ #include "GameObjects/Entities/Towers/TowerSlots/tower_slot.h" #include "Utilities/route.h" #include "Utilities/wave.h" +#include "GameObjects/Entities/Traps/bear_trap.h" +#include "GameObjects/Entities/Traps/bomb.h" class Level { public: @@ -41,6 +43,8 @@ class Level { int route_index_; }; + std::vector bear_traps_{}; + std::vector bombs_{}; std::vector tower_slots_{}; std::vector routes_{}; std::vector waves_{}; From e6906a808d608a9e2037929d4fbb09760321f61f Mon Sep 17 00:00:00 2001 From: Egor Date: Fri, 3 Jun 2022 21:29:22 +0300 Subject: [PATCH 2/4] fixed ci --- GameObjects/Entities/Mobs/Basis/mob.cpp | 3 +- GameObjects/Entities/Traps/bear_trap.cpp | 31 +++++++++++++------- GameObjects/Entities/Traps/bomb.cpp | 22 +++++++++----- GameObjects/Interface/coin.cpp | 16 ++++++---- Utilities/Resources/pixmap_loader.cpp | 2 +- constants.cpp | 2 +- game_scene.cpp | 10 +++---- level.cpp | 37 ++++++++++++------------ 8 files changed, 73 insertions(+), 50 deletions(-) diff --git a/GameObjects/Entities/Mobs/Basis/mob.cpp b/GameObjects/Entities/Mobs/Basis/mob.cpp index 972098f..9dfb225 100644 --- a/GameObjects/Entities/Mobs/Basis/mob.cpp +++ b/GameObjects/Entities/Mobs/Basis/mob.cpp @@ -62,7 +62,8 @@ Mob::~Mob() { route_->RemoveEntity(this); } if (rand() % Entities::kCoinAppearChance == 1) { - scene()->addItem(new Coin(VectorF(pos().x(), pos().y()), PixmapLoader::Pixmaps::kCoinAnimations)); + scene()->addItem(new Coin(VectorF(pos().x(), pos().y()), + PixmapLoader::Pixmaps::kCoinAnimations)); } } diff --git a/GameObjects/Entities/Traps/bear_trap.cpp b/GameObjects/Entities/Traps/bear_trap.cpp index 3530774..f1b5138 100644 --- a/GameObjects/Entities/Traps/bear_trap.cpp +++ b/GameObjects/Entities/Traps/bear_trap.cpp @@ -1,22 +1,31 @@ #include "bear_trap.h" #include "Utilities/Resources/pixmap_loader.h" -//#include "GameObjects/Entities/Mobs/Basis/mob.h" #include "constants.h" - #include #include QRectF BearTrap::boundingRect() const { - return QRectF(QPointF(-15,-15), QSize(30, 30)); + 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); + : 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); } @@ -34,7 +43,7 @@ void BearTrap::Tick(Time delta) { } Entity::Tick(delta); std::vector mobs = scene()->Mobs(); - for (auto mob : mobs) { + for (auto mob: mobs) { if (mob->sceneBoundingRect().intersects(this->sceneBoundingRect()) && !is_broken_) { mob->ApplyDamage(Damage(mob->GetHealth())); animation_ = attacking_animation_; @@ -43,7 +52,9 @@ void BearTrap::Tick(Time delta) { } } -void BearTrap::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { +void BearTrap::paint(QPainter* painter, + const QStyleOptionGraphicsItem* option, + QWidget* widget) { Entity::paint(painter, option, widget); } diff --git a/GameObjects/Entities/Traps/bomb.cpp b/GameObjects/Entities/Traps/bomb.cpp index d8f5f46..a7b35fd 100644 --- a/GameObjects/Entities/Traps/bomb.cpp +++ b/GameObjects/Entities/Traps/bomb.cpp @@ -3,18 +3,23 @@ #include "constants.h" - #include #include QRectF Bomb::boundingRect() const { - return QRectF(QPointF(-15,-15), QSize(30, 30)); + 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); + : 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); } @@ -32,7 +37,7 @@ void Bomb::Tick(Time delta) { Entity::Tick(delta); if (activated_ && animation_->WasEndedDuringPreviousUpdate()) { std::vector mobs = scene()->Mobs(); - for (auto mob : mobs) { + for (auto mob: mobs) { if (mob->sceneBoundingRect().intersects(this->sceneBoundingRect())) { mob->ApplyDamage(Damage(mob->GetHealth())); animation_ = explosion_animation_; @@ -42,7 +47,9 @@ void Bomb::Tick(Time delta) { } } -void Bomb::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { +void Bomb::paint(QPainter* painter, + const QStyleOptionGraphicsItem* option, + QWidget* widget) { Entity::paint(painter, option, widget); } @@ -53,7 +60,6 @@ void Bomb::mousePressEvent(QGraphicsSceneMouseEvent* event) { Explode(); } - Bomb::~Bomb() { delete idle_animation_; delete explosion_animation_; diff --git a/GameObjects/Interface/coin.cpp b/GameObjects/Interface/coin.cpp index 392c871..512b30a 100644 --- a/GameObjects/Interface/coin.cpp +++ b/GameObjects/Interface/coin.cpp @@ -3,13 +3,16 @@ //#include "GameObjects/Entities/Mobs/Basis/mob.h" #include "constants.h" - #include #include Coin::Coin(const VectorF& coordinates, QPixmap* pixmap) - : Coin(coordinates, new Animation(PixmapLoader::Pixmaps::kCoinIdle, 50_ms)) { - idle_animation_ = new Animation(PixmapLoader::Pixmaps::kCoinIdle, 50_ms); + : Coin(coordinates, new Animation( + PixmapLoader::Pixmaps::kCoinIdle, + 50_ms)) { + idle_animation_ = new Animation( + PixmapLoader::Pixmaps::kCoinIdle, + 50_ms); collecting_route_ = nullptr; speed_ = 300; setFlag(QGraphicsItem::ItemIsFocusable, true); @@ -29,7 +32,9 @@ void Coin::Tick(Time delta) { Entity::Tick(delta); } -void Coin::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { +void Coin::paint(QPainter* painter, + const QStyleOptionGraphicsItem* option, + QWidget* widget) { Entity::paint(painter, option, widget); } @@ -42,10 +47,9 @@ void Coin::mousePressEvent(QGraphicsSceneMouseEvent* event) { } - Coin::~Coin() { delete idle_animation_; -// scene()->DecCoinsCount(); +// scene()->DecCoinsCount(); } void Coin::SetRoute() { diff --git a/Utilities/Resources/pixmap_loader.cpp b/Utilities/Resources/pixmap_loader.cpp index 4c1ea6f..0e60df2 100644 --- a/Utilities/Resources/pixmap_loader.cpp +++ b/Utilities/Resources/pixmap_loader.cpp @@ -481,4 +481,4 @@ void PixmapLoader::LoadCoinAnimations() { idle_animation_frames_count, idle_animation_column * frame_width, idle_animation_row * frame_height); -} \ No newline at end of file +} diff --git a/constants.cpp b/constants.cpp index d705040..aaa7768 100644 --- a/constants.cpp +++ b/constants.cpp @@ -106,4 +106,4 @@ namespace Costs { const int kCoinCost = 50; const int kCannonTowerCost = 500; const int kMagicTowerCost = 500; -} \ No newline at end of file +} diff --git a/game_scene.cpp b/game_scene.cpp index d803049..75826ba 100644 --- a/game_scene.cpp +++ b/game_scene.cpp @@ -18,7 +18,7 @@ GameView* GameScene::view() { std::vector GameScene::Mobs() const { std::vector result; - for (auto item : items()) { + for (auto item: items()) { if (auto mob = dynamic_cast(item)) { result.push_back(mob); } @@ -28,7 +28,7 @@ std::vector GameScene::Mobs() const { std::vector GameScene::Towers() const { std::vector result; - for (auto item : items()) { + for (auto item: items()) { if (auto tower = dynamic_cast(item)) { result.push_back(tower); } @@ -38,7 +38,7 @@ std::vector GameScene::Towers() const { std::vector GameScene::TowerSlots() const { std::vector result; - for (auto item : items()) { + for (auto item: items()) { if (auto tower_slot = dynamic_cast(item)) { result.push_back(tower_slot); } @@ -48,7 +48,7 @@ std::vector GameScene::TowerSlots() const { std::vector GameScene::Projectiles() const { std::vector result; - for (auto item : items()) { + for (auto item: items()) { if (auto projectile = dynamic_cast(item)) { result.push_back(projectile); } @@ -72,7 +72,7 @@ void GameScene::IncCannonTowersCount() { void GameScene::DecCannonTowersCount() { if (cannon_tower_count_ > 0) { - -- cannon_tower_count_; + --cannon_tower_count_; } } diff --git a/level.cpp b/level.cpp index 91eb3d3..bce4ecb 100644 --- a/level.cpp +++ b/level.cpp @@ -15,7 +15,7 @@ Level::Level(int level_number) : level_number_(level_number) { QFile file(":Levels/Level" + - QString::fromStdString(std::to_string(level_number)) + "/level.json"); + QString::fromStdString(std::to_string(level_number)) + "/level.json"); if (!file.open(QIODevice::ReadOnly)) { throw std::invalid_argument("There is no such level"); @@ -34,7 +34,7 @@ Level::Level(int level_number) : level_number_(level_number) { QJsonArray tower_slot_positions = root.value("towerSlotPositions").toArray(); tower_slots_.reserve(tower_slot_positions.size()); - for (auto tower_slot_position : tower_slot_positions) { + for (auto tower_slot_position: tower_slot_positions) { int tower_slot_x; int tower_slot_y; QJsonObject tower_slot_pos_object = tower_slot_position.toObject(); @@ -45,19 +45,21 @@ Level::Level(int level_number) : level_number_(level_number) { new TowerSlot(VectorF(tower_slot_x, tower_slot_y))); } { - bear_traps_.push_back(new BearTrap(VectorF(150, 150), PixmapLoader::Pixmaps::kTowerSlot)); // check + bear_traps_.push_back(new BearTrap(VectorF(150, 150), + PixmapLoader::Pixmaps::kTowerSlot)); // test } { - bombs_.push_back(new Bomb(VectorF(0, 150), PixmapLoader::Pixmaps::kTowerSlot)); // test + bombs_.push_back(new Bomb(VectorF(0, 150), + PixmapLoader::Pixmaps::kTowerSlot)); // test } QJsonArray routes = root.value("routes").toArray(); routes_.reserve(routes.size()); - for (auto route : routes) { + for (auto route: routes) { QJsonArray points = route.toObject().value("points").toArray(); std::vector points_for_route; points_for_route.reserve(points.size()); - for (auto point : points) { + for (auto point: points) { QJsonObject point_object = point.toObject(); int x = point_object.value("x").toInt(); int y = point_object.value("y").toInt(); @@ -70,7 +72,7 @@ Level::Level(int level_number) : level_number_(level_number) { waves_.reserve(waves_.size()); Time previous_wave_end_time(0); - for (auto json_wave : waves) { + for (auto json_wave: waves) { QJsonObject wave_object = json_wave.toObject(); Time current_wave_start_time = previous_wave_end_time + Time(wave_object.value("startTimeRelativeToPrevWave").toInt()); @@ -78,7 +80,7 @@ Level::Level(int level_number) : level_number_(level_number) { QJsonArray spawn_entries = wave_object.value("spawnEntries").toArray(); Time wave_duration(0); std::map mobs; - for (auto json_spawn_entry : spawn_entries) { + for (auto json_spawn_entry: spawn_entries) { QJsonObject object = json_spawn_entry.toObject(); SpawnEntry spawn_entry(&object); wave_duration = Time(std::max( @@ -112,19 +114,19 @@ void Level::AddObjectsToScene(GameScene* scene) { map_pixmap_item->setPos(pixmap_rect.topLeft()); map_pixmap_item->setTransform(transform); - for (auto tower_slot : tower_slots_) { + for (auto tower_slot: tower_slots_) { scene->addItem(tower_slot); } - for (auto bear_trap : bear_traps_) { + for (auto bear_trap: bear_traps_) { scene->addItem(bear_trap); } - for (auto bomb : bombs_) { + for (auto bomb: bombs_) { scene->addItem(bomb); } } void Level::Tick(Time delta) { - for (auto wave : waves_) { + for (auto wave: waves_) { wave->Tick(delta); } } @@ -146,12 +148,11 @@ int Level::GetStartMoney() const { } Level::SpawnEntry::SpawnEntry(QJsonObject* spawn_root_object) - : start_time_(Time(spawn_root_object->value("startTime").toInt())), - mob_type_(spawn_root_object->value("mobType").toString()), - count_(spawn_root_object->value("count").toInt()), - entry_duration_(Time(spawn_root_object->value("entryDuration").toInt())), - route_index_(spawn_root_object->value("routeIndex").toInt()) - {} + : start_time_(Time(spawn_root_object->value("startTime").toInt())), + mob_type_(spawn_root_object->value("mobType").toString()), + count_(spawn_root_object->value("count").toInt()), + entry_duration_(Time(spawn_root_object->value("entryDuration").toInt())), + route_index_(spawn_root_object->value("routeIndex").toInt()) {} void Level::SpawnEntry::AddMobsToWave( std::map* mobs, From 9af4219aca6087ec7cc6f7ba456f50988fbfe1ef Mon Sep 17 00:00:00 2001 From: Egor Date: Fri, 3 Jun 2022 21:37:24 +0300 Subject: [PATCH 3/4] fixed ci try2 --- GameObjects/Entities/Traps/bear_trap.cpp | 6 ++++-- GameObjects/Entities/Traps/bear_trap.h | 1 - GameObjects/Entities/Traps/bomb.cpp | 3 ++- GameObjects/Entities/Traps/bomb.h | 1 - GameObjects/Interface/coin.cpp | 4 +--- GameObjects/Interface/coin.h | 2 -- game_scene.cpp | 8 ++++---- level.cpp | 20 ++++++++++---------- 8 files changed, 21 insertions(+), 24 deletions(-) diff --git a/GameObjects/Entities/Traps/bear_trap.cpp b/GameObjects/Entities/Traps/bear_trap.cpp index f1b5138..688cd99 100644 --- a/GameObjects/Entities/Traps/bear_trap.cpp +++ b/GameObjects/Entities/Traps/bear_trap.cpp @@ -4,6 +4,7 @@ #include #include +#include QRectF BearTrap::boundingRect() const { return QRectF(QPointF(-15, -15), QSize(30, 30)); @@ -43,8 +44,9 @@ void BearTrap::Tick(Time delta) { } Entity::Tick(delta); std::vector mobs = scene()->Mobs(); - for (auto mob: mobs) { - if (mob->sceneBoundingRect().intersects(this->sceneBoundingRect()) && !is_broken_) { + for (auto mob : mobs) { + if (mob->sceneBoundingRect().intersects(this->sceneBoundingRect()) + && !is_broken_) { mob->ApplyDamage(Damage(mob->GetHealth())); animation_ = attacking_animation_; is_broken_ = true; diff --git a/GameObjects/Entities/Traps/bear_trap.h b/GameObjects/Entities/Traps/bear_trap.h index 32110ed..7788ada 100644 --- a/GameObjects/Entities/Traps/bear_trap.h +++ b/GameObjects/Entities/Traps/bear_trap.h @@ -1,6 +1,5 @@ #pragma once -//#include "GameObjects/Interface/entity.h" #include "GameObjects/Entities/Mobs/Basis/mob.h" class BearTrap : public Entity { diff --git a/GameObjects/Entities/Traps/bomb.cpp b/GameObjects/Entities/Traps/bomb.cpp index a7b35fd..7c33d62 100644 --- a/GameObjects/Entities/Traps/bomb.cpp +++ b/GameObjects/Entities/Traps/bomb.cpp @@ -5,6 +5,7 @@ #include #include +#include QRectF Bomb::boundingRect() const { return QRectF(QPointF(-15, -15), QSize(30, 30)); @@ -37,7 +38,7 @@ void Bomb::Tick(Time delta) { Entity::Tick(delta); if (activated_ && animation_->WasEndedDuringPreviousUpdate()) { std::vector mobs = scene()->Mobs(); - for (auto mob: mobs) { + for (auto mob : mobs) { if (mob->sceneBoundingRect().intersects(this->sceneBoundingRect())) { mob->ApplyDamage(Damage(mob->GetHealth())); animation_ = explosion_animation_; diff --git a/GameObjects/Entities/Traps/bomb.h b/GameObjects/Entities/Traps/bomb.h index a61ef3c..a27c370 100644 --- a/GameObjects/Entities/Traps/bomb.h +++ b/GameObjects/Entities/Traps/bomb.h @@ -1,6 +1,5 @@ #pragma once -//#include "GameObjects/Interface/entity.h" #include "GameObjects/Entities/Mobs/Basis/mob.h" class Bomb : public Entity { diff --git a/GameObjects/Interface/coin.cpp b/GameObjects/Interface/coin.cpp index 512b30a..f01bbb6 100644 --- a/GameObjects/Interface/coin.cpp +++ b/GameObjects/Interface/coin.cpp @@ -1,10 +1,10 @@ #include "coin.h" #include "Utilities/Resources/pixmap_loader.h" -//#include "GameObjects/Entities/Mobs/Basis/mob.h" #include "constants.h" #include #include +#include Coin::Coin(const VectorF& coordinates, QPixmap* pixmap) : Coin(coordinates, new Animation( @@ -43,8 +43,6 @@ void Coin::mousePressEvent(QGraphicsSceneMouseEvent* event) { update(); SetRoute(); delete this; - // add money - } Coin::~Coin() { diff --git a/GameObjects/Interface/coin.h b/GameObjects/Interface/coin.h index ac01eae..c413fd3 100644 --- a/GameObjects/Interface/coin.h +++ b/GameObjects/Interface/coin.h @@ -1,8 +1,6 @@ #pragma once -//#include "GameObjects/Interface/entity.h" #include "GameObjects/Entities/Mobs/Basis/mob.h" -//#include "Utilities/route.h" class Coin : public Entity { public: diff --git a/game_scene.cpp b/game_scene.cpp index 75826ba..c34f8ec 100644 --- a/game_scene.cpp +++ b/game_scene.cpp @@ -18,7 +18,7 @@ GameView* GameScene::view() { std::vector GameScene::Mobs() const { std::vector result; - for (auto item: items()) { + for (auto item : items()) { if (auto mob = dynamic_cast(item)) { result.push_back(mob); } @@ -28,7 +28,7 @@ std::vector GameScene::Mobs() const { std::vector GameScene::Towers() const { std::vector result; - for (auto item: items()) { + for (auto item : items()) { if (auto tower = dynamic_cast(item)) { result.push_back(tower); } @@ -38,7 +38,7 @@ std::vector GameScene::Towers() const { std::vector GameScene::TowerSlots() const { std::vector result; - for (auto item: items()) { + for (auto item : items()) { if (auto tower_slot = dynamic_cast(item)) { result.push_back(tower_slot); } @@ -48,7 +48,7 @@ std::vector GameScene::TowerSlots() const { std::vector GameScene::Projectiles() const { std::vector result; - for (auto item: items()) { + for (auto item : items()) { if (auto projectile = dynamic_cast(item)) { result.push_back(projectile); } diff --git a/level.cpp b/level.cpp index bce4ecb..a912eef 100644 --- a/level.cpp +++ b/level.cpp @@ -34,7 +34,7 @@ Level::Level(int level_number) : level_number_(level_number) { QJsonArray tower_slot_positions = root.value("towerSlotPositions").toArray(); tower_slots_.reserve(tower_slot_positions.size()); - for (auto tower_slot_position: tower_slot_positions) { + for (auto tower_slot_position : tower_slot_positions) { int tower_slot_x; int tower_slot_y; QJsonObject tower_slot_pos_object = tower_slot_position.toObject(); @@ -46,7 +46,7 @@ Level::Level(int level_number) : level_number_(level_number) { } { bear_traps_.push_back(new BearTrap(VectorF(150, 150), - PixmapLoader::Pixmaps::kTowerSlot)); // test + PixmapLoader::Pixmaps::kTowerSlot)); } { bombs_.push_back(new Bomb(VectorF(0, 150), @@ -55,11 +55,11 @@ Level::Level(int level_number) : level_number_(level_number) { QJsonArray routes = root.value("routes").toArray(); routes_.reserve(routes.size()); - for (auto route: routes) { + for (auto route : routes) { QJsonArray points = route.toObject().value("points").toArray(); std::vector points_for_route; points_for_route.reserve(points.size()); - for (auto point: points) { + for (auto point : points) { QJsonObject point_object = point.toObject(); int x = point_object.value("x").toInt(); int y = point_object.value("y").toInt(); @@ -72,7 +72,7 @@ Level::Level(int level_number) : level_number_(level_number) { waves_.reserve(waves_.size()); Time previous_wave_end_time(0); - for (auto json_wave: waves) { + for (auto json_wave : waves) { QJsonObject wave_object = json_wave.toObject(); Time current_wave_start_time = previous_wave_end_time + Time(wave_object.value("startTimeRelativeToPrevWave").toInt()); @@ -80,7 +80,7 @@ Level::Level(int level_number) : level_number_(level_number) { QJsonArray spawn_entries = wave_object.value("spawnEntries").toArray(); Time wave_duration(0); std::map mobs; - for (auto json_spawn_entry: spawn_entries) { + for (auto json_spawn_entry : spawn_entries) { QJsonObject object = json_spawn_entry.toObject(); SpawnEntry spawn_entry(&object); wave_duration = Time(std::max( @@ -114,19 +114,19 @@ void Level::AddObjectsToScene(GameScene* scene) { map_pixmap_item->setPos(pixmap_rect.topLeft()); map_pixmap_item->setTransform(transform); - for (auto tower_slot: tower_slots_) { + for (auto tower_slot : tower_slots_) { scene->addItem(tower_slot); } - for (auto bear_trap: bear_traps_) { + for (auto bear_trap : bear_traps_) { scene->addItem(bear_trap); } - for (auto bomb: bombs_) { + for (auto bomb : bombs_) { scene->addItem(bomb); } } void Level::Tick(Time delta) { - for (auto wave: waves_) { + for (auto wave : waves_) { wave->Tick(delta); } } From 6bacda50370aa4270b3922a3da521eab9e235d05 Mon Sep 17 00:00:00 2001 From: Egor Date: Fri, 3 Jun 2022 21:42:34 +0300 Subject: [PATCH 4/4] added nolint --- GameObjects/Entities/Mobs/Basis/mob.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GameObjects/Entities/Mobs/Basis/mob.cpp b/GameObjects/Entities/Mobs/Basis/mob.cpp index 9dfb225..36aa6cd 100644 --- a/GameObjects/Entities/Mobs/Basis/mob.cpp +++ b/GameObjects/Entities/Mobs/Basis/mob.cpp @@ -61,7 +61,7 @@ Mob::~Mob() { if (route_ != nullptr) { route_->RemoveEntity(this); } - if (rand() % Entities::kCoinAppearChance == 1) { + if (rand() % Entities::kCoinAppearChance == 1) { //NOLINT scene()->addItem(new Coin(VectorF(pos().x(), pos().y()), PixmapLoader::Pixmaps::kCoinAnimations)); }