Restrukt classes WIP
This commit is contained in:
BIN
cmake-build-debug/LotoStatek.exe
Normal file
BIN
cmake-build-debug/LotoStatek.exe
Normal file
Binary file not shown.
@@ -5,11 +5,12 @@
|
|||||||
#include "SFML/Graphics/Texture.hpp"
|
#include "SFML/Graphics/Texture.hpp"
|
||||||
#include "Bullet.h"
|
#include "Bullet.h"
|
||||||
|
|
||||||
|
struct Position {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
};
|
||||||
|
|
||||||
class Actor {
|
class Actor {
|
||||||
struct Position {
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
};
|
|
||||||
public:
|
public:
|
||||||
Actor(int x, int y, std::string path);
|
Actor(int x, int y, std::string path);
|
||||||
|
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ class Bullet {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Bullet(float x, float y, sf::Texture &texture);
|
Bullet(float x, float y);
|
||||||
sf::Sprite &getSprite();
|
sf::Sprite &getSprite();
|
||||||
void setSpeed(float speed);
|
void setSpeed(float speed);
|
||||||
bool getStatus() const;
|
bool getStatus() const;
|
||||||
void update();
|
void update();
|
||||||
|
static sf::Texture bulletTexture;
|
||||||
private:
|
private:
|
||||||
sf::Sprite bulletSprite;
|
sf::Sprite bulletSprite;
|
||||||
sf::Texture bulletTexture;
|
|
||||||
Position bulletPosition;
|
Position bulletPosition;
|
||||||
float bulletSpeed;
|
float bulletSpeed;
|
||||||
bool outOfBounds;
|
bool outOfBounds;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ Position Actor::getPosition() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Actor::shoot() {
|
void Actor::shoot() {
|
||||||
bullets.emplace_back(float(position.x) + actorSprite.getGlobalBounds().width / 2, position.y, bulletTextureLeft);
|
// bullets.emplace_back(float(position.x) + actorSprite.getGlobalBounds().width / 2, position.y, bulletTextureLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Bullet> &Actor::getBullets() {
|
std::vector<Bullet> &Actor::getBullets() {
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "../headers/Bullet.h"
|
#include "../headers/Bullet.h"
|
||||||
|
|
||||||
Bullet::Bullet(float x, float y, sf::Texture &texture) {
|
Bullet::Bullet(float x, float y) {
|
||||||
bulletPosition.x = x;
|
bulletPosition.x = x;
|
||||||
bulletPosition.y = y;
|
bulletPosition.y = y;
|
||||||
outOfBounds = false;
|
outOfBounds = false;
|
||||||
bulletTexture = texture;
|
bulletSprite.setTexture(Bullet::bulletTexture);
|
||||||
bulletSprite.setTexture(texture);
|
|
||||||
bulletSprite.setOrigin(bulletSprite.getLocalBounds().width/2, bulletSprite.getLocalBounds().height/2);
|
bulletSprite.setOrigin(bulletSprite.getLocalBounds().width/2, bulletSprite.getLocalBounds().height/2);
|
||||||
bulletSprite.setPosition(x, y);
|
bulletSprite.setPosition(x, y);
|
||||||
bulletSpeed = -10.0f;
|
bulletSpeed = -10.0f;
|
||||||
@@ -31,3 +30,5 @@ void Bullet::update() {
|
|||||||
bool Bullet::getStatus() const {
|
bool Bullet::getStatus() const {
|
||||||
return outOfBounds;
|
return outOfBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sf::Texture Bullet::bulletTexture = sf::Texture(); // plain init of static field
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
#include "../headers/Player.h"
|
#include "../headers/Player.h"
|
||||||
|
#include "../headers/Bullet.h"
|
||||||
|
|
||||||
Player::Player(int x, int y, std::string path) : Actor(x, y, path) {};
|
// TODO: Podzielić na klasy Bullet i Rocket.
|
||||||
|
Player::Player(int x, int y, std::string path) : Actor(x, y, path) {
|
||||||
|
Bullet::bulletTexture.loadFromFile("../assets/img/bullet_left.png");
|
||||||
|
};
|
||||||
|
|
||||||
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) {
|
||||||
bullets.emplace_back(position.x, position.y, bulletTextureLeft);
|
bullets.emplace_back(position.x, position.y);
|
||||||
lastShotTime = now;
|
lastShotTime = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +18,7 @@ void Player::shoot() {
|
|||||||
void Player::alternate_shoot() {
|
void Player::alternate_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) {
|
||||||
bullets.emplace_back(position.x, position.y, bulletTextureRight).getSprite().scale(1.5f, 1.5f);
|
bullets.emplace_back(position.x, position.y).getSprite().scale(1.5f, 1.5f);
|
||||||
lastShotTime = now;
|
lastShotTime = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user