diff options
author | Nikolas <nikolas@boutalas.com> | 2024-10-27 12:52:55 +0200 |
---|---|---|
committer | Nikolas <nikolas@boutalas.com> | 2024-10-27 12:52:55 +0200 |
commit | 43394c8a8908442982e3a7e25975c31b3c952923 (patch) | |
tree | 2facd563e29f48fe3b0653ac5c113998940b4d5e /src/enemy.cpp |
Diffstat (limited to 'src/enemy.cpp')
-rw-r--r-- | src/enemy.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/enemy.cpp b/src/enemy.cpp new file mode 100644 index 0000000..6f2fc91 --- /dev/null +++ b/src/enemy.cpp @@ -0,0 +1,62 @@ +#include "enemy.h" +#include "config.h" +#include "graphics.h" +#include "shot.h" +#include "game.h" +#include <random> +#include <ctime> +using namespace std; + +Enemy::Enemy(float pos_x, float pos_y, float size_x, float size_y, float orientation, string texture, float speed) : MovingGameObject(pos_x, pos_y, size_x, size_y, orientation, texture, speed){ + + last_time_shot = graphics::getGlobalTime(); + + srand((unsigned int)time(NULL)); + final_pos = rand() % 100; + +} + +Enemy::~Enemy(){ + +} + +void Enemy::update(){ + + MovingGameObject::update(); + + float pos_y = this -> getPosY(); + float pos_x = this -> getPosX(); + float speed = this -> getSpeed(); + + if(pos_y < 50 + final_pos){ + pos_y += speed * graphics::getDeltaTime(); + this -> setPosY(pos_y); + } + + if(graphics::getGlobalTime() > last_time_shot + 2000){ + + Game * game = reinterpret_cast<Game *>(graphics::getUserData()); + game -> addObject(new Shot(pos_x , pos_y + 40, 80, 80, this -> getOrientation(), "enemy_shot", -0.5f)); + last_time_shot = graphics::getGlobalTime(); + + } + +} + +void Enemy::draw(){ + + MovingGameObject::draw(); + + float pos_y = this -> getPosY(); + float pos_x = this -> getPosX(); + + graphics::Brush br; + br.outline_opacity = 0.0f; + int exhaust_number = (int)(graphics::getGlobalTime()/100) % 4 + 1; + br.texture = string(ASSET_PATH) + this -> getTexture() + "_exhaust" + to_string(exhaust_number) + ".png"; + + graphics::setOrientation(this -> getOrientation()); + graphics::drawRect(pos_x+2, pos_y-50, 30, 30, br); + graphics::resetPose(); + +}
\ No newline at end of file |