naprawa pozycji + nowe rakiety
This commit is contained in:
BIN
assets/img/Rocket_111.png
Normal file
BIN
assets/img/Rocket_111.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 489 B |
BIN
assets/img/Rocket_115.png
Normal file
BIN
assets/img/Rocket_115.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 503 B |
BIN
assets/img/meteor-1.png
Normal file
BIN
assets/img/meteor-1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 563 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 563 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 4.0 KiB |
4
main.cpp
4
main.cpp
@@ -88,8 +88,8 @@ int main()
|
|||||||
for (auto& meteor : plansza.getMeteors()) {
|
for (auto& meteor : plansza.getMeteors()) {
|
||||||
if(ship.getSprite().getGlobalBounds().intersects(meteor.getSprite().getGlobalBounds())) {
|
if(ship.getSprite().getGlobalBounds().intersects(meteor.getSprite().getGlobalBounds())) {
|
||||||
std::cout << "You lost the game!\n";
|
std::cout << "You lost the game!\n";
|
||||||
window.close();
|
// window.close();
|
||||||
exit(-2); // Kod -2 oznacza uderzenie się w meteoryt
|
// exit(-2); // Kod -2 oznacza uderzenie się w meteoryt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Actor::Actor(int x, int y, std::string 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
|
||||||
actorSprite.setPosition(x, y);
|
actorSprite.setPosition(float(x), float(y));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actor::loadTexture(std::string path) {
|
void Actor::loadTexture(std::string path) {
|
||||||
@@ -13,7 +13,7 @@ void Actor::loadTexture(std::string path) {
|
|||||||
actorSprite.setTexture(actorTexture);
|
actorSprite.setTexture(actorTexture);
|
||||||
|
|
||||||
bulletTextureLeft.loadFromFile("../assets/img/bullet_left.png");
|
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() {
|
sf::Sprite &Actor::getSprite() {
|
||||||
@@ -25,7 +25,7 @@ Position Actor::getPosition() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Actor::shoot() {
|
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() {
|
std::vector<Bullet> &Actor::getBullets() {
|
||||||
|
|||||||
@@ -2,14 +2,14 @@
|
|||||||
#include "../headers/Bullet.h"
|
#include "../headers/Bullet.h"
|
||||||
|
|
||||||
Bullet::Bullet(float x, float y, sf::Texture &texture) {
|
Bullet::Bullet(float x, float y, sf::Texture &texture) {
|
||||||
|
bulletPosition.x = x;
|
||||||
|
bulletPosition.y = y;
|
||||||
outOfBounds = false;
|
outOfBounds = false;
|
||||||
bulletTexture = texture;
|
bulletTexture = texture;
|
||||||
bulletSprite.setTexture(texture);
|
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;
|
||||||
bulletPosition.x = x;
|
|
||||||
bulletPosition.y = y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bullet::setSpeed(float speed) {
|
void Bullet::setSpeed(float speed) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth) {
|
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth) {
|
||||||
size.height = windowHeight;
|
size.height = windowHeight;
|
||||||
size.width = windowWidth;
|
size.width = windowWidth;
|
||||||
meteorTexture.loadFromFile("../assets/img/meteor.png");
|
meteorTexture.loadFromFile("../assets/img/meteor-1.png");
|
||||||
spawnClock.restart();
|
spawnClock.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Player::Player(int x, int y, std::string path) : Actor(x, y, path) {};
|
|||||||
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(float(position.x) + actorSprite.getGlobalBounds().width / 2, position.y, bulletTextureLeft);
|
bullets.emplace_back(position.x, position.y, bulletTextureLeft);
|
||||||
lastShotTime = now;
|
lastShotTime = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,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(float(position.x) + actorSprite.getGlobalBounds().width / 2, position.y, bulletTextureRight);
|
bullets.emplace_back(position.x, position.y, bulletTextureRight).getSprite().scale(1.5f, 1.5f);
|
||||||
lastShotTime = now;
|
lastShotTime = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,20 +28,20 @@ void Player::move(float deltaX, float deltaY) {
|
|||||||
|
|
||||||
void Player::moveLeft() {
|
void Player::moveLeft() {
|
||||||
move(-moving_speed, 0.0f);
|
move(-moving_speed, 0.0f);
|
||||||
position.x -= moving_speed;
|
position.x -= static_cast<int>(moving_speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::moveRight() {
|
void Player::moveRight() {
|
||||||
move(moving_speed, 0.0f);
|
move(moving_speed, 0.0f);
|
||||||
position.x += moving_speed;
|
position.x += static_cast<int>(moving_speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::moveUp() {
|
void Player::moveUp() {
|
||||||
move(0.0f, -moving_speed);
|
move(0.0f, -moving_speed);
|
||||||
position.y -= moving_speed;
|
position.y -= static_cast<int>(moving_speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::moveDown() {
|
void Player::moveDown() {
|
||||||
move(0.0f, moving_speed);
|
move(0.0f, moving_speed);
|
||||||
position.y += moving_speed;
|
position.y += static_cast<int>(moving_speed);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user