This repository has been archived on 2025-06-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
LotoStatek/sources/Enemy.cpp
Kuba c655409596 Jakieś działające gówno
Ale nie strzela chujek
2024-12-09 16:48:31 +01:00

37 lines
1.0 KiB
C++

#include "../headers/Enemy.h"
#include "../headers/Bullet.h"
Enemy::Enemy(int x, int y, std::string path) : Actor(x, y, path) {
hp = 1; // Przeciwnik ma 1 punkt życia
firerate = 1000; // Strzela co 1 sekundę
moving_speed = 2.0f; // Prędkość ruchu przeciwnika
}
void Enemy::shoot() {
if (shootClock.getElapsedTime().asMilliseconds() >= firerate) {
bullets.emplace_back(position.x, position.y + 20, bulletTextureLeft); // Strzał w dół
shootClock.restart();
}
}
void Enemy::move(float deltaX, float deltaY) {
actorSprite.move(deltaX, deltaY);
position.x += static_cast<int>(deltaX);
position.y += static_cast<int>(deltaY);
}
void Enemy::moveLeft() { move(-moving_speed, 0.0f); }
void Enemy::moveRight() { move(moving_speed, 0.0f); }
void Enemy::moveUp() { move(0.0f, -moving_speed); }
void Enemy::moveDown() { move(0.0f, moving_speed); }
bool Enemy::isAlive() const {
return alive;
}
void Enemy::takeDamage() {
if (--hp <= 0) {
alive = false;
}
}