Dziuala 3 strzlowiec

This commit is contained in:
2024-12-11 00:05:53 +01:00
parent 81b04bae0f
commit 2bffc2de0c
11 changed files with 25 additions and 52 deletions

View File

@@ -2,8 +2,8 @@
#include <iostream>
Actor::Actor(int x, int y, const sf::Texture& texture) {
actorSprite.setTexture(texture);
Actor::Actor(int x, int y, std::string path) {
loadTexture(path);
position.x = x;
position.y = y;
actorSprite.setOrigin(actorSprite.getLocalBounds().width / 2, actorSprite.getLocalBounds().height / 2); // wycentrowanie sprite
@@ -16,12 +16,11 @@ void Actor::loadTexture(std::string path) {
bulletTextureLeft.loadFromFile("../assets/img/bullets/bullet_pink.png");
bulletTextureRight.loadFromFile("../assets/img/rockets/Rocket_111.png");
enemyTexture.loadFromFile("../assets/img/enemy/enemy.png");
advancedEnemyTexture.loadFromFile("../assets/img/enemy/advanced_enemy.png");
}
sf::Sprite &Actor::getSprite() {
if (!actorSprite.getTexture()) {
std::cerr << "actorSprite has no texture set!" << std::endl;
}
return actorSprite;
}

View File

@@ -1,9 +1,7 @@
#include "../headers/AdvancedEnemy.h"
#include "../headers/Bullet.h"
AdvancedEnemy::AdvancedEnemy(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture) : Actor(x, y, texture) {
actorSprite.setTexture(texture);
enemyBulletTexture = bulletTexture;
AdvancedEnemy::AdvancedEnemy(int x, int y, std::string path) : Actor(x, y, path) {
hp = 2; // 2 punkty życia
firerate = 2000; // Strzela co 2
moving_speed = 2.0f; // Prędkość

View File

@@ -1,11 +1,11 @@
#include "../headers/Enemy.h"
#include "../headers/Bullet.h"
Enemy::Enemy(int x, int y, const sf::Texture& texture) : Actor(x, y, texture) {
actorSprite.setTexture(texture);
Enemy::Enemy(int x, int y, std::string path) : Actor(x, y, path) {
hp = 1; // Przeciwnik ma 1 punkt życia
firerate = 2000; // Strzela co 2
moving_speed = 2.0f; // Prędkość
actorSprite.setTexture(enemyTexture);
enemyBulletTexture.loadFromFile("../assets/img/bullets/enemy_bullet.png");
}

View File

@@ -3,12 +3,9 @@
#include "../headers/Plansza.h"
#include "../headers/ObjectItem.hpp"
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow,
const sf::Texture& playerTexture,
const sf::Texture& playerBulletTexture,
const sf::Texture& playerRocketTexture)
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow)
: background("../assets/img/background/background.png", 2.0f),
ship(static_cast<int>(mainWindow->getSize().x) / 2, static_cast<int>(mainWindow->getSize().y) - 100, playerTexture, playerBulletTexture, playerRocketTexture)
ship(static_cast<int>(mainWindow->getSize().x) / 2, static_cast<int>(mainWindow->getSize().y) - 100, "../assets/ship/Dreadnought-Base.png")
{
window = mainWindow;
@@ -32,15 +29,7 @@ ship(static_cast<int>(mainWindow->getSize().x) / 2, static_cast<int>(mainWindow-
meteorTexture1.loadFromFile("../assets/img/meteors/meteor-1.png");
meteorTexture2.loadFromFile("../assets/img/meteors/meteor-2.png");
// Ładowanie tekstur wrogów
if (!enemyTexture.loadFromFile("../assets/img/enemy/enemy.png")) {
std::cerr << "Failed to load enemy texture!" << std::endl;
exit(-1);
}
if (!advancedEnemyTexture.loadFromFile("../assets/img/enemy/advanced_enemy.png")) {
std::cerr << "Failed to load advanced enemy texture!" << std::endl;
exit(-1);
}
spawnClock.restart();
}
@@ -400,7 +389,7 @@ void Plansza::update_meteors() {
void Plansza::spawn_enemy() {
if (enemySpawnClock.getElapsedTime().asSeconds() >= 6) { // Spawn co 10 sekund
int spawnX = RandomNumberGenerator::getRandomNumber(50, size.width - 50);
enemies.emplace_back(spawnX, -50, enemyTexture);
enemies.emplace_back(spawnX, -50, "../assets/img/enemy/enemy.png");
enemySpawnClock.restart();
@@ -410,7 +399,7 @@ void Plansza::spawn_enemy() {
void Plansza::spawn_advanced_enemy() {
if (AenemySpawnClock.getElapsedTime().asSeconds() >= 5) { // Spawn co 10 sekund
int spawnX = RandomNumberGenerator::getRandomNumber(50, size.width - 50);
AEnemies.emplace_back(spawnX, 50, advancedEnemyTexture, enemyBulletTexture);
AEnemies.emplace_back(spawnX, 50, "../assets/img/enemy/advanced_enemy.png");
std::cout << "Spawned Advanced Enemy at X: " << spawnX << std::endl;
AenemySpawnClock.restart();
}

View File

@@ -7,16 +7,11 @@
#include "../headers/Bullet.h"
Player::Player(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture, const sf::Texture& rocketTexture) : Actor(x, y, texture), bulletTexture(bulletTexture), rocketTexture(rocketTexture) {
Player::Player(int x, int y, std::string path) : Actor(x, y, path) {
bulletTexture.loadFromFile("../assets/img/bullets/bullet_pink.png");
rocketTexture.loadFromFile("../assets/img/rockets/Rocket_111.png");
};
void Player::setTextures(const sf::Texture& shipTexture, const sf::Texture& bulletTexture, const sf::Texture& rocketTexture) {
this->actorSprite.setTexture(shipTexture); // Poprawiona nazwa - actorSprite zamiast shipSprite
this->bulletTexture = bulletTexture;
this->rocketTexture = rocketTexture;
}
void Player::shoot() {
auto now = std::chrono::steady_clock::now();
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - lastShotTime).count() >= firerate) {