Dziuala 3 strzlowiec
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
class Actor {
|
class Actor {
|
||||||
public:
|
public:
|
||||||
Actor(int x, int y, const sf::Texture& texture);
|
Actor(int x, int y, std::string path);
|
||||||
|
|
||||||
void loadTexture(std::string path);
|
void loadTexture(std::string path);
|
||||||
|
|
||||||
@@ -35,6 +35,8 @@ protected:
|
|||||||
sf::Texture actorTexture;
|
sf::Texture actorTexture;
|
||||||
sf::Texture bulletTextureLeft;
|
sf::Texture bulletTextureLeft;
|
||||||
sf::Texture bulletTextureRight;
|
sf::Texture bulletTextureRight;
|
||||||
|
sf::Texture enemyTexture;
|
||||||
|
sf::Texture advancedEnemyTexture;
|
||||||
Position position;
|
Position position;
|
||||||
unsigned int hp;
|
unsigned int hp;
|
||||||
unsigned int damage;
|
unsigned int damage;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ enum class DirectionA {
|
|||||||
|
|
||||||
class AdvancedEnemy : public Actor {
|
class AdvancedEnemy : public Actor {
|
||||||
public:
|
public:
|
||||||
AdvancedEnemy(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture);
|
AdvancedEnemy(int x, int y, std::string path);
|
||||||
|
|
||||||
void shoot() override;
|
void shoot() override;
|
||||||
void move(float deltaX, float deltaY) override;
|
void move(float deltaX, float deltaY) override;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ enum class Direction {
|
|||||||
|
|
||||||
class Enemy : public Actor {
|
class Enemy : public Actor {
|
||||||
public:
|
public:
|
||||||
Enemy(int x, int y, const sf::Texture& texture) ;
|
Enemy(int x, int y, std::string path);
|
||||||
|
|
||||||
void shoot() override;
|
void shoot() override;
|
||||||
void move(float deltaX, float deltaY) override;
|
void move(float deltaX, float deltaY) override;
|
||||||
|
|||||||
@@ -18,8 +18,7 @@
|
|||||||
|
|
||||||
class Plansza {
|
class Plansza {
|
||||||
public:
|
public:
|
||||||
Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow,
|
Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow);
|
||||||
const sf::Texture& playerTexture, const sf::Texture& playerBulletTexture, const sf::Texture& playerRocketTexture);
|
|
||||||
Size getSize();
|
Size getSize();
|
||||||
std::vector<Meteor> &getMeteors();
|
std::vector<Meteor> &getMeteors();
|
||||||
|
|
||||||
@@ -43,8 +42,6 @@ private:
|
|||||||
sf::Texture playerTexture;
|
sf::Texture playerTexture;
|
||||||
sf::Texture playerBulletTexture;
|
sf::Texture playerBulletTexture;
|
||||||
sf::Texture playerRocketTexture;
|
sf::Texture playerRocketTexture;
|
||||||
sf::Texture enemyTexture;
|
|
||||||
sf::Texture advancedEnemyTexture;
|
|
||||||
sf::Clock spawnClock;
|
sf::Clock spawnClock;
|
||||||
sf::Clock shooterSpawnClock;
|
sf::Clock shooterSpawnClock;
|
||||||
std::vector<Enemy> enemies;
|
std::vector<Enemy> enemies;
|
||||||
|
|||||||
@@ -8,8 +8,7 @@
|
|||||||
|
|
||||||
class Player : public Actor {
|
class Player : public Actor {
|
||||||
public:
|
public:
|
||||||
Player(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture, const sf::Texture& rocketTexture);
|
Player(int x, int y, std::string path);
|
||||||
void setTextures(const sf::Texture& shipTexture, const sf::Texture& bulletTexture, const sf::Texture& rocketTexture);
|
|
||||||
void shoot() override;
|
void shoot() override;
|
||||||
void alternate_shoot();
|
void alternate_shoot();
|
||||||
void setFirerate(unsigned int firerate);
|
void setFirerate(unsigned int firerate);
|
||||||
@@ -25,6 +24,7 @@ private:
|
|||||||
std::chrono::steady_clock::time_point lastShotTime = std::chrono::steady_clock::now();
|
std::chrono::steady_clock::time_point lastShotTime = std::chrono::steady_clock::now();
|
||||||
std::vector<Rocket> rockets;
|
std::vector<Rocket> rockets;
|
||||||
sf::Texture rocketTexture;
|
sf::Texture rocketTexture;
|
||||||
|
|
||||||
int health = 3; // Liczba punktów życia gracza
|
int health = 3; // Liczba punktów życia gracza
|
||||||
sf::Texture bulletTexture;
|
sf::Texture bulletTexture;
|
||||||
};
|
};
|
||||||
|
|||||||
11
main.cpp
11
main.cpp
@@ -5,14 +5,7 @@
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::clog << "Game started\n";
|
|
||||||
sf::Texture playerTexture, playerBulletTexture, playerRocketTexture;
|
|
||||||
if (!playerTexture.loadFromFile("../assets/ship/Dreadnought-Base.png") ||
|
|
||||||
!playerBulletTexture.loadFromFile("../assets/img/bullets/bullet_pink.png") ||
|
|
||||||
!playerRocketTexture.loadFromFile("../assets/img/rockets/Rocket_111.png")) {
|
|
||||||
std::cerr << "Failed to load player textures!" << std::endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
sf::RenderWindow mainWindow(sf::VideoMode(600, 800), "LotoStatek");
|
sf::RenderWindow mainWindow(sf::VideoMode(600, 800), "LotoStatek");
|
||||||
mainWindow.setVerticalSyncEnabled(true);
|
mainWindow.setVerticalSyncEnabled(true);
|
||||||
mainWindow.setFramerateLimit(60);
|
mainWindow.setFramerateLimit(60);
|
||||||
@@ -23,7 +16,7 @@ int main()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Plansza plansza(mainWindow.getSize().y, mainWindow.getSize().x, &mainWindow,playerTexture, playerBulletTexture, playerRocketTexture);
|
Plansza plansza(mainWindow.getSize().y, mainWindow.getSize().x, &mainWindow);
|
||||||
|
|
||||||
while (mainWindow.isOpen()) {
|
while (mainWindow.isOpen()) {
|
||||||
mainWindow.clear();
|
mainWindow.clear();
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Actor::Actor(int x, int y, const sf::Texture& texture) {
|
Actor::Actor(int x, int y, std::string path) {
|
||||||
actorSprite.setTexture(texture);
|
loadTexture(path);
|
||||||
position.x = x;
|
position.x = x;
|
||||||
position.y = y;
|
position.y = y;
|
||||||
actorSprite.setOrigin(actorSprite.getLocalBounds().width / 2, actorSprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
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");
|
bulletTextureLeft.loadFromFile("../assets/img/bullets/bullet_pink.png");
|
||||||
bulletTextureRight.loadFromFile("../assets/img/rockets/Rocket_111.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() {
|
sf::Sprite &Actor::getSprite() {
|
||||||
if (!actorSprite.getTexture()) {
|
|
||||||
std::cerr << "actorSprite has no texture set!" << std::endl;
|
|
||||||
}
|
|
||||||
return actorSprite;
|
return actorSprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
#include "../headers/AdvancedEnemy.h"
|
#include "../headers/AdvancedEnemy.h"
|
||||||
#include "../headers/Bullet.h"
|
#include "../headers/Bullet.h"
|
||||||
|
|
||||||
AdvancedEnemy::AdvancedEnemy(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture) : Actor(x, y, texture) {
|
AdvancedEnemy::AdvancedEnemy(int x, int y, std::string path) : Actor(x, y, path) {
|
||||||
actorSprite.setTexture(texture);
|
|
||||||
enemyBulletTexture = bulletTexture;
|
|
||||||
hp = 2; // 2 punkty życia
|
hp = 2; // 2 punkty życia
|
||||||
firerate = 2000; // Strzela co 2
|
firerate = 2000; // Strzela co 2
|
||||||
moving_speed = 2.0f; // Prędkość
|
moving_speed = 2.0f; // Prędkość
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#include "../headers/Enemy.h"
|
#include "../headers/Enemy.h"
|
||||||
#include "../headers/Bullet.h"
|
#include "../headers/Bullet.h"
|
||||||
|
|
||||||
Enemy::Enemy(int x, int y, const sf::Texture& texture) : Actor(x, y, texture) {
|
Enemy::Enemy(int x, int y, std::string path) : Actor(x, y, path) {
|
||||||
actorSprite.setTexture(texture);
|
|
||||||
hp = 1; // Przeciwnik ma 1 punkt życia
|
hp = 1; // Przeciwnik ma 1 punkt życia
|
||||||
firerate = 2000; // Strzela co 2
|
firerate = 2000; // Strzela co 2
|
||||||
moving_speed = 2.0f; // Prędkość
|
moving_speed = 2.0f; // Prędkość
|
||||||
|
actorSprite.setTexture(enemyTexture);
|
||||||
enemyBulletTexture.loadFromFile("../assets/img/bullets/enemy_bullet.png");
|
enemyBulletTexture.loadFromFile("../assets/img/bullets/enemy_bullet.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,9 @@
|
|||||||
#include "../headers/Plansza.h"
|
#include "../headers/Plansza.h"
|
||||||
#include "../headers/ObjectItem.hpp"
|
#include "../headers/ObjectItem.hpp"
|
||||||
|
|
||||||
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow,
|
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow)
|
||||||
const sf::Texture& playerTexture,
|
|
||||||
const sf::Texture& playerBulletTexture,
|
|
||||||
const sf::Texture& playerRocketTexture)
|
|
||||||
: background("../assets/img/background/background.png", 2.0f),
|
: 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;
|
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");
|
meteorTexture1.loadFromFile("../assets/img/meteors/meteor-1.png");
|
||||||
meteorTexture2.loadFromFile("../assets/img/meteors/meteor-2.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();
|
spawnClock.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,7 +389,7 @@ void Plansza::update_meteors() {
|
|||||||
void Plansza::spawn_enemy() {
|
void Plansza::spawn_enemy() {
|
||||||
if (enemySpawnClock.getElapsedTime().asSeconds() >= 6) { // Spawn co 10 sekund
|
if (enemySpawnClock.getElapsedTime().asSeconds() >= 6) { // Spawn co 10 sekund
|
||||||
int spawnX = RandomNumberGenerator::getRandomNumber(50, size.width - 50);
|
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();
|
enemySpawnClock.restart();
|
||||||
|
|
||||||
@@ -410,7 +399,7 @@ void Plansza::spawn_enemy() {
|
|||||||
void Plansza::spawn_advanced_enemy() {
|
void Plansza::spawn_advanced_enemy() {
|
||||||
if (AenemySpawnClock.getElapsedTime().asSeconds() >= 5) { // Spawn co 10 sekund
|
if (AenemySpawnClock.getElapsedTime().asSeconds() >= 5) { // Spawn co 10 sekund
|
||||||
int spawnX = RandomNumberGenerator::getRandomNumber(50, size.width - 50);
|
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;
|
std::cout << "Spawned Advanced Enemy at X: " << spawnX << std::endl;
|
||||||
AenemySpawnClock.restart();
|
AenemySpawnClock.restart();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,16 +7,11 @@
|
|||||||
|
|
||||||
#include "../headers/Bullet.h"
|
#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() {
|
void Player::shoot() {
|
||||||
auto now = std::chrono::steady_clock::now();
|
auto now = std::chrono::steady_clock::now();
|
||||||
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - lastShotTime).count() >= firerate) {
|
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - lastShotTime).count() >= firerate) {
|
||||||
|
|||||||
Reference in New Issue
Block a user