Merge remote-tracking branch 'refs/remotes/origin/przeszkoda'
# Conflicts: # CMakeLists.txt # main.cpp
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#include "../headers/Actor.h"
|
||||
|
||||
// TODO: Naprawić krzywy sprite statku
|
||||
Actor::Actor(int x, int y, std::string path) {
|
||||
loadTexture(path);
|
||||
position.x = x;
|
||||
position.y = y;
|
||||
actorSprite.setPosition(x, y);
|
||||
actorSprite.setOrigin(actorSprite.getLocalBounds().width / 2, actorSprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
||||
actorSprite.setPosition(float(x), float(y));
|
||||
}
|
||||
|
||||
void Actor::loadTexture(std::string path) {
|
||||
@@ -13,7 +13,7 @@ void Actor::loadTexture(std::string path) {
|
||||
actorSprite.setTexture(actorTexture);
|
||||
|
||||
bulletTextureLeft.loadFromFile("../assets/img/bullet_left.png");
|
||||
bulletTextureRight.loadFromFile("../assets/img/bullet_right.png");
|
||||
bulletTextureRight.loadFromFile("../assets/img/Rocket_111.png");
|
||||
}
|
||||
|
||||
sf::Sprite &Actor::getSprite() {
|
||||
@@ -25,7 +25,7 @@ Position Actor::getPosition() {
|
||||
}
|
||||
|
||||
void Actor::shoot() {
|
||||
bullets.emplace_back(float(position.x) + actorSprite.getGlobalBounds().width / 2-62, position.y, bulletTextureLeft);
|
||||
bullets.emplace_back(float(position.x) + actorSprite.getGlobalBounds().width / 2, position.y, bulletTextureLeft);
|
||||
}
|
||||
|
||||
std::vector<Bullet> &Actor::getBullets() {
|
||||
@@ -39,3 +39,7 @@ void Actor::updateBullets() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Actor::setMovingSpeed(float speed) {
|
||||
moving_speed = speed;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
#include <iostream>
|
||||
#include "../headers/Bullet.h"
|
||||
|
||||
Bullet::Bullet(float x, float y, sf::Texture &bulletTexture) {
|
||||
outOfBounds = false;
|
||||
bulletSprite.setTexture(bulletTexture);
|
||||
bulletSprite.setPosition(x, y);
|
||||
bulletSpeed = -10.0f;
|
||||
Bullet::Bullet(float x, float y, sf::Texture &texture) {
|
||||
bulletPosition.x = x;
|
||||
bulletPosition.y = y;
|
||||
outOfBounds = false;
|
||||
bulletTexture = texture;
|
||||
bulletSprite.setTexture(texture);
|
||||
bulletSprite.setOrigin(bulletSprite.getLocalBounds().width/2, bulletSprite.getLocalBounds().height/2);
|
||||
bulletSprite.setPosition(x, y);
|
||||
bulletSpeed = -10.0f;
|
||||
}
|
||||
|
||||
void Bullet::setSpeed(float speed) {
|
||||
|
||||
43
sources/Meteor.cpp
Normal file
43
sources/Meteor.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <iostream>
|
||||
#include "../headers/Meteor.h"
|
||||
|
||||
Meteor::Meteor(float x, float y, sf::Texture &texture) {
|
||||
outOfBounds = false;
|
||||
meteorTexture = texture;
|
||||
meteorSprite.setTexture(texture);
|
||||
meteorSprite.setOrigin(meteorSprite.getLocalBounds().width / 2, meteorSprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
||||
meteorSprite.setPosition(x, y);
|
||||
meteorSpeed = 5.0f;
|
||||
meteorSprite.scale(0.05f, 0.05f);
|
||||
meteorPosition.x = x;
|
||||
meteorPosition.y = y;
|
||||
meteorRotationSpeed = static_cast<float>(rand() % 2 + 1) * (rand() % 2 == 0 ? 1 : -1);
|
||||
}
|
||||
|
||||
sf::Sprite &Meteor::getSprite() {
|
||||
return meteorSprite;
|
||||
}
|
||||
|
||||
void Meteor::update() {
|
||||
meteorSprite.move(0.0f, meteorSpeed); // przesunięcie sprajta
|
||||
meteorPosition.y += int(meteorSpeed); // przesunięcie pozycji
|
||||
meteorSprite.rotate(meteorRotationSpeed); // obracanie tym meteorkiem pięknym
|
||||
if(meteorPosition.y > 900) {
|
||||
outOfBounds = true; // jeżeli wyszedł poza granice ekranu ustaw tą zmienną
|
||||
}
|
||||
// std::cout << "x: " << meteorSprite.getPosition().x << std::endl;
|
||||
// std::cout << "y: " << meteorSprite.getPosition().y << std::endl;
|
||||
}
|
||||
|
||||
bool Meteor::getStatus() {
|
||||
return outOfBounds;
|
||||
}
|
||||
|
||||
unsigned int Meteor::counter = 0;
|
||||
|
||||
// było użyte do testowania czy meteoryt jest kasowany
|
||||
//Meteor::~Meteor() {
|
||||
// Meteor::counter++;
|
||||
// std::clog << Meteor::counter << " Meteor destroyed\n";
|
||||
//}
|
||||
|
||||
@@ -1 +1,41 @@
|
||||
#include <random>
|
||||
#include <iostream>
|
||||
#include "../headers/Plansza.h"
|
||||
|
||||
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth) {
|
||||
size.height = windowHeight;
|
||||
size.width = windowWidth;
|
||||
meteorTexture1.loadFromFile("../assets/img/meteor-1.png");
|
||||
meteorTexture2.loadFromFile("../assets/img/meteor-2.png");
|
||||
spawnClock.restart();
|
||||
}
|
||||
|
||||
void Plansza::spawn_meteor() {
|
||||
if (spawnClock.getElapsedTime().asSeconds() > rand() % 10 + 1) { // randomowy spawn meteorytów od 10 do 1 sekundy
|
||||
if (meteors.size() < 5) { // jeśli jest mniej niż 5 meteorów na planszy
|
||||
if(rand() % 2 == 1) {
|
||||
meteors.emplace_back(RandomNumberGenerator::getRandomNumber(0,499), -100, meteorTexture2);
|
||||
} else {
|
||||
meteors.emplace_back(RandomNumberGenerator::getRandomNumber(0,499), -100, meteorTexture1);
|
||||
}
|
||||
}
|
||||
spawnClock.restart();
|
||||
}
|
||||
}
|
||||
|
||||
Plansza::Size Plansza::getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
std::vector<Meteor> &Plansza::getMeteors() {
|
||||
return meteors;
|
||||
}
|
||||
|
||||
void Plansza::update_meteors() {
|
||||
// usuwanie meteorów które wyleciały poza ekran
|
||||
for (auto& meteor : meteors) {
|
||||
if(meteor.getStatus()) {
|
||||
meteors.erase(meteors.begin());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ Player::Player(int x, int y, std::string path) : Actor(x, y, path) {};
|
||||
void Player::shoot() {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - lastShotTime).count() >= firerate) {
|
||||
bullets.emplace_back(float(position.x) + actorSprite.getGlobalBounds().width / 2-62, position.y, bulletTextureLeft);
|
||||
bullets.emplace_back(position.x, position.y, bulletTextureLeft);
|
||||
lastShotTime = now;
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ void Player::shoot() {
|
||||
void Player::alternate_shoot() {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - lastShotTime).count() >= firerate) {
|
||||
bullets.emplace_back(float(position.x) + actorSprite.getGlobalBounds().width / 2-62, position.y, bulletTextureRight);
|
||||
bullets.emplace_back(position.x, position.y, bulletTextureRight).getSprite().scale(1.5f, 1.5f);
|
||||
lastShotTime = now;
|
||||
}
|
||||
}
|
||||
@@ -28,20 +28,20 @@ void Player::move(float deltaX, float deltaY) {
|
||||
|
||||
void Player::moveLeft() {
|
||||
move(-moving_speed, 0.0f);
|
||||
position.x -= moving_speed;
|
||||
position.x -= static_cast<int>(moving_speed);
|
||||
}
|
||||
|
||||
void Player::moveRight() {
|
||||
move(moving_speed, 0.0f);
|
||||
position.x += moving_speed;
|
||||
position.x += static_cast<int>(moving_speed);
|
||||
}
|
||||
|
||||
void Player::moveUp() {
|
||||
move(0.0f, -moving_speed);
|
||||
position.y -= moving_speed;
|
||||
position.y -= static_cast<int>(moving_speed);
|
||||
}
|
||||
|
||||
void Player::moveDown() {
|
||||
move(0.0f, moving_speed);
|
||||
position.y += moving_speed;
|
||||
position.y += static_cast<int>(moving_speed);
|
||||
}
|
||||
Reference in New Issue
Block a user