Refactor of structs

Refactored Size and Position
Placed them in different .h files
This commit is contained in:
2024-12-04 14:47:50 +01:00
parent 7ecb90af1f
commit 72e2116dc7
9 changed files with 35 additions and 28 deletions

View File

@@ -23,7 +23,9 @@ add_executable(LotoStatek main.cpp
headers/Projectile.h
sources/Projectile.cpp
headers/Rocket.h
sources/Rocket.cpp)
sources/Rocket.cpp
headers/Size.h
headers/Position.h)
if(WIN32)
set(SFML_ROOT "${CMAKE_SOURCE_DIR}/lib/SFML")

View File

@@ -4,11 +4,8 @@
#include "SFML/Graphics/Sprite.hpp"
#include "SFML/Graphics/Texture.hpp"
#include "Bullet.h"
#include "Position.h"
struct Position {
int x;
int y;
};
class Actor {
public:

View File

@@ -3,13 +3,9 @@
#include "SFML/Graphics/Texture.hpp"
#include "SFML/Graphics/Sprite.hpp"
#include "Position.h"
class Meteor {
struct Position {
int x;
int y;
};
public:
Meteor(float x, float y, sf::Texture &texture);
sf::Sprite &getSprite();

View File

@@ -1,28 +1,24 @@
#ifndef PLANSZA_H
#define PLANSZA_H
#include "Meteor.h"
#include "RandomNumberGenerator.h"
#include "SFML/System/Clock.hpp"
#include "Size.h"
class Plansza {
struct Size {
int height;
int width;
};
public:
Plansza(unsigned int windowHeight, unsigned int windowWidth);
void spawn_meteor();
Size getSize();
std::vector<Meteor> &getMeteors();
void spawn_meteor();
void update_meteors();
private:
std::vector<Meteor> meteors;
Size size;
sf::Texture meteorTexture1;
sf::Texture meteorTexture2;
sf::Clock spawnClock;
std::vector<Meteor> meteors;
};
#endif //PLANSZA_H

9
headers/Position.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef LOTOSTATEK_POSITION_H
#define LOTOSTATEK_POSITION_H
struct Position {
int x;
int y;
};
#endif //LOTOSTATEK_POSITION_H

View File

@@ -2,13 +2,9 @@
#define PROJECTILE_H
#include <SFML/Graphics/Sprite.hpp>
#include "Position.h"
class Projectile {
struct Position {
int x;
int y;
};
public:
Projectile(float x, float y, sf::Texture &texture);
sf::Sprite &getSprite();
@@ -18,7 +14,7 @@ public:
protected:
static sf::Texture texture;
sf::Sprite sprite;
Position position{};
Position position;
float speed;
bool outOfBounds;
~Projectile() = default;

9
headers/Size.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef LOTOSTATEK_SIZE_H
#define LOTOSTATEK_SIZE_H
struct Size {
int height;
int width;
};
#endif //LOTOSTATEK_SIZE_H

View File

@@ -14,8 +14,10 @@ int main()
sf::RenderWindow mainWindow(sf::VideoMode(600, 800), "LotoStatek");
mainWindow.setVerticalSyncEnabled(true);
mainWindow.setFramerateLimit(60);
sf::Image icon;
icon.loadFromFile("../assets/img/icon/ikonka.png");
mainWindow.setIcon(128, 128, icon.getPixelsPtr());
Plansza plansza(mainWindow.getSize().y, mainWindow.getSize().x);
@@ -40,10 +42,6 @@ int main()
while (mainWindow.isOpen()) {
mainWindow.clear();
// tło
background.update();
background.draw(mainWindow);
// Tu są handlowane eventy
sf::Event event{};
while (mainWindow.pollEvent(event)) {
@@ -51,6 +49,10 @@ int main()
mainWindow.close();
}
// tło
background.update();
background.draw(mainWindow);
// poruszanie się statkiem
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
if(ship.getPosition().x > 50) {

View File

@@ -23,7 +23,7 @@ void Plansza::spawn_meteor() {
}
}
Plansza::Size Plansza::getSize() {
Size Plansza::getSize() {
return size;
}