Skip to content
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

Dev #3

Merged
merged 12 commits into from
Jun 16, 2024
Prev Previous commit
Next Next commit
fix some bugs in zombies and gameEntity
  • Loading branch information
hamidreza2005 committed Jun 11, 2024
commit d6031ab05889d529e04351e2cd83ab0110e0b383
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ add_executable(PlanetVsZombies main.cpp
entities/zombie/RegularZombie.cpp
entities/zombie/RegularZombie.h
entities/GameEntity.cpp
entities/GameEntity.h)
entities/GameEntity.h
entities/plant/Plant.cpp
entities/plant/Plant.h
entities/plant/PeaShooter.cpp
entities/plant/PeaShooter.h)

target_link_libraries(PlanetVsZombies
Qt::Core
Expand Down
8 changes: 7 additions & 1 deletion entities/GameEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ int GameEntity::getHealth() const {

void GameEntity::setHealth(int newHealth) {
health = newHealth;
}
}

void GameEntity::setImage() {
QPixmap image_ground(getPicturePath());
QPixmap Scaled_image_ground = image_ground.scaled(75,75,Qt::KeepAspectRatio,Qt::SmoothTransformation);
setPixmap(Scaled_image_ground);
}
3 changes: 3 additions & 0 deletions entities/GameEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class GameEntity: public QObject,public QGraphicsPixmapItem{
Q_OBJECT
Q_PROPERTY(qreal x READ x WRITE setX)
public:
explicit GameEntity(int health);

Expand All @@ -19,6 +20,8 @@ class GameEntity: public QObject,public QGraphicsPixmapItem{

protected:
int health;

void setImage();
};


Expand Down
2 changes: 1 addition & 1 deletion entities/zombie/RegularZombie.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "RegularZombie.h"

RegularZombie::RegularZombie():
Zombie(INITIAL_HEALTH,INITIAL_MOVEMENT_DELAY,INITIAL_ATTACK_POWER,INITIAL_FIRING_RATE)\
Zombie(INITIAL_HEALTH,INITIAL_MOVEMENT_DELAY,INITIAL_ATTACK_POWER,INITIAL_FIRING_RATE,100)
{
this->setImage();
}
Expand Down
15 changes: 5 additions & 10 deletions entities/zombie/Zombie.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "Zombie.h"

Zombie::Zombie(int health, float movementDelay, int attackPower,float firingRate):
Zombie::Zombie(int health, float movementDelay, int attackPower,float firingRate,int brain):
GameEntity(health),
movementDelay(movementDelay),
attackPower(attackPower),
firingRate(firingRate)
firingRate(firingRate),
brain(brain)
{
this->setZValue(100);
this->setZValue(10);
this->setUpTimers();
this->setUpAnimations();
}
Expand Down Expand Up @@ -67,10 +68,4 @@ void Zombie::setUpTimers() {
void Zombie::setUpAnimations() {
this->movementAnimation = new QPropertyAnimation(this, "x");
this->movementAnimation->setDuration(1000);
}

void Zombie::setImage() {
QPixmap image_ground(getPicturePath());
QPixmap Scaled_image_ground = image_ground.scaled(75,75,Qt::KeepAspectRatio,Qt::SmoothTransformation);
setPixmap(Scaled_image_ground);
}
}
5 changes: 2 additions & 3 deletions entities/zombie/Zombie.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
#include "../GameEntity.h"

class Zombie : public GameEntity{
Q_PROPERTY(qreal x READ x WRITE setX)
public:
explicit Zombie(int health, float movementDelay, int attackPower, float firingRate);
explicit Zombie(int health, float movementDelay, int attackPower, float firingRate,int brain);

// Getters and Setters

Expand All @@ -21,7 +20,6 @@ class Zombie : public GameEntity{

void reduceHealth(int amount);

void setImage();
virtual ~Zombie();
protected slots:
void attack();
Expand All @@ -32,6 +30,7 @@ protected slots:
float movementDelay;
int attackPower;
float firingRate;
int brain;
QTimer *attackTimer;
QTimer *movementTimer;
QPropertyAnimation *movementAnimation;
Expand Down
11 changes: 8 additions & 3 deletions playground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cstdlib>
#include <ctime>
#include "entities/zombie/RegularZombie.h"
#include "entities/plant/PeaShooter.h"

PlayGround::PlayGround(QWidget *parent) : QWidget(parent) {
srand(static_cast<unsigned int>(time(0)));
Expand All @@ -28,9 +29,13 @@ PlayGround::PlayGround(QWidget *parent) : QWidget(parent) {

setupLayout();

// auto* z1 = new RegularZombie();
// z1->setPos(200, 158);
// scene->addItem(z1);
auto* z1 = new RegularZombie();
z1->setPos(200, 153);
scene->addItem(z1);

auto* p1 = new PeaShooter();
p1->setPos(50,158);
scene->addItem(p1);
}

void PlayGround::setupPlayerZombieInfo() {
Expand Down