refactor
This commit is contained in:
@@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
#include "Enemy.h"
|
#include "Enemy.h"
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
enum class DirectionA {
|
enum class DirectionA {
|
||||||
Up,
|
Up,
|
||||||
Down,
|
Down,
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#define LOTOSTATEK_BEAM_H
|
#define LOTOSTATEK_BEAM_H
|
||||||
|
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include "Position.h"
|
|
||||||
|
|
||||||
class Beam {
|
class Beam {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -2,14 +2,11 @@
|
|||||||
#define LOTOSTATEK_BULLET_H
|
#define LOTOSTATEK_BULLET_H
|
||||||
|
|
||||||
#include "Projectile.h"
|
#include "Projectile.h"
|
||||||
#include "SFML/Graphics/Texture.hpp"
|
|
||||||
|
|
||||||
class Bullet : public Projectile {
|
class Bullet : public Projectile {
|
||||||
public:
|
public:
|
||||||
Bullet(float x, float y, sf::Texture &texture) : Projectile(x,y, texture) {};
|
Bullet(float x, float y, sf::Texture &texture) : Projectile(x,y, texture) {};
|
||||||
void update() override;
|
void update() override;
|
||||||
private:
|
|
||||||
float directionY;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,12 @@
|
|||||||
#define LOTOSTATEK_HEART_HPP
|
#define LOTOSTATEK_HEART_HPP
|
||||||
|
|
||||||
#include "SFML/Graphics/Texture.hpp"
|
#include "SFML/Graphics/Texture.hpp"
|
||||||
#include "SFML/Graphics/Sprite.hpp"
|
|
||||||
#include "ObjectItem.hpp"
|
#include "ObjectItem.hpp"
|
||||||
|
|
||||||
class Heart : public ObjectItem {
|
class Heart : public ObjectItem {
|
||||||
public:
|
public:
|
||||||
Heart(float x, float y, sf::Texture &texture);
|
Heart(float x, float y, sf::Texture &texture);
|
||||||
void update();
|
void update() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //LOTOSTATEK_HEART_HPP
|
#endif //LOTOSTATEK_HEART_HPP
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
class Meteor : public ObjectItem {
|
class Meteor : public ObjectItem {
|
||||||
public:
|
public:
|
||||||
Meteor(float x, float y, sf::Texture &texture);
|
Meteor(float x, float y, sf::Texture &texture_);
|
||||||
void update();
|
void update();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public:
|
|||||||
bool getStatus();
|
bool getStatus();
|
||||||
virtual void update() = 0;
|
virtual void update() = 0;
|
||||||
protected:
|
protected:
|
||||||
sf::Texture texture;
|
sf::Texture texture_;
|
||||||
sf::Sprite sprite;
|
sf::Sprite sprite;
|
||||||
Position position;
|
Position position;
|
||||||
float rotationSpeed;
|
float rotationSpeed;
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ public:
|
|||||||
bool isShooting() const;
|
bool isShooting() const;
|
||||||
const Beam* getBeam() const;
|
const Beam* getBeam() const;
|
||||||
void setPlanszaHeight(float height, float width);
|
void setPlanszaHeight(float height, float width);
|
||||||
void setMapBounds(float width, float height);
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float planszaHeight = 800.f;
|
float planszaHeight = 800.f;
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
#include "../headers/Bullet.h"
|
#include "../headers/Bullet.h"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <ostream>
|
|
||||||
|
|
||||||
void Bullet::update() {
|
void Bullet::update() {
|
||||||
//std::cout << "Start update: speed = " << speed << ", position.y = " << position.y << std::endl;
|
//std::cout << "Start update: speed = " << speed << ", position.y = " << position.y << std::endl;
|
||||||
sprite.move(0.0f, speed);
|
sprite.move(0.0f, speed);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Meteor::Meteor(float x, float y, sf::Texture &texture) : ObjectItem(x, y, texture) {
|
Meteor::Meteor(float x, float y, sf::Texture &texture) : ObjectItem(x, y, texture) {
|
||||||
outOfBounds = false;
|
outOfBounds = false;
|
||||||
texture = texture;
|
texture_ = texture;
|
||||||
sprite.setTexture(texture);
|
sprite.setTexture(texture);
|
||||||
sprite.setOrigin(sprite.getLocalBounds().width / 2, sprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
sprite.setOrigin(sprite.getLocalBounds().width / 2, sprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
||||||
sprite.setPosition(x, y);
|
sprite.setPosition(x, y);
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#include "../headers/ObjectItem.hpp"
|
#include "../headers/ObjectItem.hpp"
|
||||||
|
|
||||||
ObjectItem::ObjectItem(float x, float y, sf::Texture &texture) {
|
ObjectItem::ObjectItem(float x, float y, sf::Texture &texture) {
|
||||||
Position position_;
|
Position position_ = {0,0};
|
||||||
position_.x = x;
|
position_.x = static_cast<int>(x);
|
||||||
position_.y = y;
|
position_.y = static_cast<int>(y);
|
||||||
position = position_;
|
position = position_;
|
||||||
this->texture = texture;
|
this->texture_ = texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ObjectItem::getStatus() {
|
bool ObjectItem::getStatus() {
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ void Plansza::update() {
|
|||||||
window->draw(rocket.getSprite());
|
window->draw(rocket.getSprite());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sprawdzenie czy meteory i pociski są poza granicami ekranu
|
// Sprawdzenie, czy meteory i pociski są poza granicami ekranu
|
||||||
update_meteors();
|
update_meteors();
|
||||||
update_hearts();
|
update_hearts();
|
||||||
ship->updateBullets();
|
ship->updateBullets();
|
||||||
@@ -406,7 +406,7 @@ void Plansza::update() {
|
|||||||
if (playerBulletIt->getSprite().getGlobalBounds().intersects(it->getSprite().getGlobalBounds())) {
|
if (playerBulletIt->getSprite().getGlobalBounds().intersects(it->getSprite().getGlobalBounds())) {
|
||||||
// Usuń pocisk Bombera i pocisk gracza
|
// Usuń pocisk Bombera i pocisk gracza
|
||||||
it = bomberEnemy.getBullets().erase(it);
|
it = bomberEnemy.getBullets().erase(it);
|
||||||
playerBulletIt = ship->getBullets().erase(playerBulletIt);
|
ship->getBullets().erase(playerBulletIt);
|
||||||
bulletDestroyed = true;
|
bulletDestroyed = true;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@@ -420,7 +420,7 @@ void Plansza::update() {
|
|||||||
if (rocketIt->getSprite().getGlobalBounds().intersects(it->getSprite().getGlobalBounds())) {
|
if (rocketIt->getSprite().getGlobalBounds().intersects(it->getSprite().getGlobalBounds())) {
|
||||||
// Usuń pocisk Bombera i rakietę gracza
|
// Usuń pocisk Bombera i rakietę gracza
|
||||||
it = bomberEnemy.getBullets().erase(it);
|
it = bomberEnemy.getBullets().erase(it);
|
||||||
rocketIt = ship->getRockets().erase(rocketIt);
|
ship->getRockets().erase(rocketIt);
|
||||||
bulletDestroyed = true;
|
bulletDestroyed = true;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@@ -474,7 +474,7 @@ void Plansza::update() {
|
|||||||
bool hit = false;
|
bool hit = false;
|
||||||
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
||||||
if (enemyIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
if (enemyIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
||||||
bulletIt = ship->getBullets().erase(bulletIt);
|
ship->getBullets().erase(bulletIt);
|
||||||
enemyIt->takeDamage();
|
enemyIt->takeDamage();
|
||||||
hit = true;
|
hit = true;
|
||||||
break;
|
break;
|
||||||
@@ -493,7 +493,7 @@ void Plansza::update() {
|
|||||||
bool hit = false;
|
bool hit = false;
|
||||||
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
||||||
if (advancedIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
if (advancedIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
||||||
bulletIt = ship->getBullets().erase(bulletIt);
|
ship->getBullets().erase(bulletIt);
|
||||||
advancedIt->takeDamage();
|
advancedIt->takeDamage();
|
||||||
hit = true;
|
hit = true;
|
||||||
break;
|
break;
|
||||||
@@ -512,7 +512,7 @@ void Plansza::update() {
|
|||||||
bool hit = false;
|
bool hit = false;
|
||||||
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
||||||
if (bomberIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
if (bomberIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
||||||
bulletIt = ship->getBullets().erase(bulletIt);
|
ship->getBullets().erase(bulletIt);
|
||||||
bomberIt->takeDamage();
|
bomberIt->takeDamage();
|
||||||
hit = true;
|
hit = true;
|
||||||
break;
|
break;
|
||||||
@@ -531,7 +531,7 @@ void Plansza::update() {
|
|||||||
bool hit = false;
|
bool hit = false;
|
||||||
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
||||||
if (kamikadzeIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
if (kamikadzeIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
||||||
bulletIt = ship->getBullets().erase(bulletIt);
|
ship->getBullets().erase(bulletIt);
|
||||||
kamikadzeIt->takeDamage();
|
kamikadzeIt->takeDamage();
|
||||||
hit = true;
|
hit = true;
|
||||||
break;
|
break;
|
||||||
@@ -550,7 +550,7 @@ void Plansza::update() {
|
|||||||
bool hit = false;
|
bool hit = false;
|
||||||
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
||||||
if (wiazkowiecIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
if (wiazkowiecIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
||||||
bulletIt = ship->getBullets().erase(bulletIt);
|
ship->getBullets().erase(bulletIt);
|
||||||
wiazkowiecIt->takeDamage();
|
wiazkowiecIt->takeDamage();
|
||||||
hit = true;
|
hit = true;
|
||||||
break;
|
break;
|
||||||
@@ -572,7 +572,7 @@ void Plansza::update() {
|
|||||||
bool hit = false;
|
bool hit = false;
|
||||||
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
||||||
if (enemyIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
if (enemyIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
||||||
rocketIt = ship->getRockets().erase(rocketIt);
|
ship->getRockets().erase(rocketIt);
|
||||||
enemyIt->takeDamage();
|
enemyIt->takeDamage();
|
||||||
hit = true;
|
hit = true;
|
||||||
break;
|
break;
|
||||||
@@ -591,7 +591,7 @@ void Plansza::update() {
|
|||||||
bool hit = false;
|
bool hit = false;
|
||||||
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
||||||
if (advancedIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
if (advancedIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
||||||
rocketIt = ship->getRockets().erase(rocketIt);
|
ship->getRockets().erase(rocketIt);
|
||||||
advancedIt->takeDamage();
|
advancedIt->takeDamage();
|
||||||
hit = true;
|
hit = true;
|
||||||
break;
|
break;
|
||||||
@@ -610,7 +610,7 @@ void Plansza::update() {
|
|||||||
bool hit = false;
|
bool hit = false;
|
||||||
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
||||||
if (bomberIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
if (bomberIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
||||||
rocketIt = ship->getRockets().erase(rocketIt);
|
ship->getRockets().erase(rocketIt);
|
||||||
bomberIt->takeDamage();
|
bomberIt->takeDamage();
|
||||||
hit = true;
|
hit = true;
|
||||||
break;
|
break;
|
||||||
@@ -629,7 +629,7 @@ void Plansza::update() {
|
|||||||
bool hit = false;
|
bool hit = false;
|
||||||
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
||||||
if (kamikadzeIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
if (kamikadzeIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
||||||
rocketIt = ship->getRockets().erase(rocketIt);
|
ship->getRockets().erase(rocketIt);
|
||||||
kamikadzeIt->takeDamage();
|
kamikadzeIt->takeDamage();
|
||||||
hit = true;
|
hit = true;
|
||||||
break;
|
break;
|
||||||
@@ -648,7 +648,7 @@ void Plansza::update() {
|
|||||||
bool hit = false;
|
bool hit = false;
|
||||||
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
||||||
if (wiazkowiecIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
if (wiazkowiecIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
||||||
rocketIt = ship->getRockets().erase(rocketIt);
|
ship->getRockets().erase(rocketIt);
|
||||||
wiazkowiecIt->takeDamage();
|
wiazkowiecIt->takeDamage();
|
||||||
hit = true;
|
hit = true;
|
||||||
break;
|
break;
|
||||||
@@ -687,6 +687,8 @@ void Plansza::update() {
|
|||||||
heartStats[1].setTexture(heartTexture);
|
heartStats[1].setTexture(heartTexture);
|
||||||
heartStats[2].setTexture(heartTexture);
|
heartStats[2].setTexture(heartTexture);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -698,7 +700,7 @@ void Plansza::update() {
|
|||||||
|
|
||||||
|
|
||||||
void Plansza::update_meteors() {
|
void Plansza::update_meteors() {
|
||||||
// usuwanie meteorów które wyleciały poza ekran
|
// usuwanie meteorów, które wyleciały poza ekran
|
||||||
for (auto &meteor: meteors) {
|
for (auto &meteor: meteors) {
|
||||||
if (meteor.getStatus()) {
|
if (meteor.getStatus()) {
|
||||||
meteors.erase(meteors.begin());
|
meteors.erase(meteors.begin());
|
||||||
@@ -787,7 +789,7 @@ void Plansza::spawn_wiazkowiec() {
|
|||||||
|
|
||||||
|
|
||||||
void Plansza::update_hearts() {
|
void Plansza::update_hearts() {
|
||||||
// usuwanie serduszek które wyleciały poza ekran
|
// usuwanie serduszek, które wyleciały poza ekran
|
||||||
for (auto& heart : hearts) {
|
for (auto& heart : hearts) {
|
||||||
if(heart.getStatus()) {
|
if(heart.getStatus()) {
|
||||||
hearts.erase(hearts.begin());
|
hearts.erase(hearts.begin());
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "../headers/Player.h"
|
#include "../headers/Player.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <SFML/Graphics/Font.hpp>
|
#include <SFML/Graphics/Font.hpp>
|
||||||
#include <SFML/Graphics/RenderWindow.hpp>
|
|
||||||
#include <SFML/Graphics/Text.hpp>
|
#include <SFML/Graphics/Text.hpp>
|
||||||
|
|
||||||
#include "../headers/Plansza.h"
|
#include "../headers/Plansza.h"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
void Rocket::update() {
|
void Rocket::update() {
|
||||||
sprite.move(0.0f, speed);
|
sprite.move(0.0f, speed);
|
||||||
position.y += int(speed);
|
position.y += static_cast<int>(speed);
|
||||||
if(position.y < -100) {
|
if(position.y < -100) {
|
||||||
outOfBounds = true;
|
outOfBounds = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
#include "../headers/Plansza.h"
|
#include "../headers/Plansza.h"
|
||||||
|
|
||||||
|
|
||||||
Wiazkowiec::Wiazkowiec(int x, int y, const sf::Texture& texture) : Actor(x, y, texture), beam(new Beam(0, 0, 50.f, 50.f)) {
|
Wiazkowiec::Wiazkowiec(int x, int y, const sf::Texture &texture) : Actor(x, y, texture),
|
||||||
|
beam(new Beam(0, 0, 50.f, 50.f)) {
|
||||||
actorSprite.setTexture(texture);
|
actorSprite.setTexture(texture);
|
||||||
hp = 2; // 2 punkty życia
|
hp = 2; // 2 punkty życia
|
||||||
firerate = 5000; // Strzela co 10
|
firerate = 5000; // Strzela co 10
|
||||||
@@ -26,29 +27,29 @@ void Wiazkowiec::spawnBeam() {
|
|||||||
switch (direction) {
|
switch (direction) {
|
||||||
case DirectionW::Up:
|
case DirectionW::Up:
|
||||||
beamHeight = position.y;
|
beamHeight = position.y;
|
||||||
beamY -= beamHeight;
|
beamY -= beamHeight;
|
||||||
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
|
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
|
||||||
break;
|
break;
|
||||||
case DirectionW::Down:
|
case DirectionW::Down:
|
||||||
beamHeight = planszaHeight - position.y;
|
beamHeight = planszaHeight - position.y;
|
||||||
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
|
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
|
||||||
break;
|
break;
|
||||||
case DirectionW::Left:
|
case DirectionW::Left:
|
||||||
beamHeight = 50.f;
|
beamHeight = 50.f;
|
||||||
beamWidth = position.x;
|
beamWidth = position.x;
|
||||||
beamX -= beamWidth;
|
beamX -= beamWidth;
|
||||||
beamY = position.y + (actorSprite.getGlobalBounds().height / 2) - 25.f;
|
beamY = position.y + (actorSprite.getGlobalBounds().height / 2) - 25.f;
|
||||||
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
|
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
|
||||||
break;
|
break;
|
||||||
case DirectionW::Right:
|
case DirectionW::Right:
|
||||||
beamHeight = 50.f;
|
beamHeight = 50.f;
|
||||||
beamWidth = 800 - position.x;
|
beamWidth = 800 - position.x;
|
||||||
beamY = position.y + (actorSprite.getGlobalBounds().height / 2) - 25.f;
|
beamY = position.y + (actorSprite.getGlobalBounds().height / 2) - 25.f;
|
||||||
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
|
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
// beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||||
beam->setVisible(true);
|
beam->setVisible(true);
|
||||||
|
|
||||||
shooting = true;
|
shooting = true;
|
||||||
@@ -65,21 +66,22 @@ void Wiazkowiec::shoot() {
|
|||||||
|
|
||||||
void Wiazkowiec::setRandomDirection() {
|
void Wiazkowiec::setRandomDirection() {
|
||||||
// Losowanie kierunku: 0 = Up, 1 = Down, 2 = Left, 3 = Right
|
// Losowanie kierunku: 0 = Up, 1 = Down, 2 = Left, 3 = Right
|
||||||
int directionIndex = std::rand() % 4;
|
|
||||||
|
|
||||||
switch (directionIndex) {
|
switch (std::rand() % 4) {
|
||||||
case 0:
|
case 0:
|
||||||
direction = DirectionW::Up;
|
direction = DirectionW::Up;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
direction = DirectionW::Down;
|
direction = DirectionW::Down;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
direction = DirectionW::Left;
|
direction = DirectionW::Left;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
direction = DirectionW::Right;
|
direction = DirectionW::Right;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,19 +145,20 @@ void Wiazkowiec::update() {
|
|||||||
switch (direction) {
|
switch (direction) {
|
||||||
case DirectionW::Up:
|
case DirectionW::Up:
|
||||||
moveUp();
|
moveUp();
|
||||||
break;
|
break;
|
||||||
case DirectionW::Down:
|
case DirectionW::Down:
|
||||||
moveDown();
|
moveDown();
|
||||||
break;
|
break;
|
||||||
case DirectionW::Left:
|
case DirectionW::Left:
|
||||||
moveLeft();
|
moveLeft();
|
||||||
break;
|
break;
|
||||||
case DirectionW::Right:
|
case DirectionW::Right:
|
||||||
moveRight();
|
moveRight();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shootClock.getElapsedTime().asSeconds() >= 3.0f) { // Co 3 sekundy
|
if (shootClock.getElapsedTime().asSeconds() >= 3.0f) {
|
||||||
|
// Co 3 sekundy
|
||||||
shoot();
|
shoot();
|
||||||
shootClock.restart();
|
shootClock.restart();
|
||||||
}
|
}
|
||||||
@@ -163,7 +166,7 @@ void Wiazkowiec::update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ustawianie widoczności wiązki podczas renderowania
|
// Ustawianie widoczności wiązki podczas renderowania
|
||||||
void Wiazkowiec::render(sf::RenderWindow& window) {
|
void Wiazkowiec::render(sf::RenderWindow &window) {
|
||||||
if (beam->isVisible()) {
|
if (beam->isVisible()) {
|
||||||
beam->render(window);
|
beam->render(window);
|
||||||
}
|
}
|
||||||
@@ -184,6 +187,6 @@ bool Wiazkowiec::isShooting() const {
|
|||||||
return shooting;
|
return shooting;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Beam* Wiazkowiec::getBeam() const {
|
const Beam *Wiazkowiec::getBeam() const {
|
||||||
return beam;
|
return beam;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user