Naprawiono białe kwadraty i zmieniono tło
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 98 KiB |
BIN
assets/img/space.jpg
Normal file
BIN
assets/img/space.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 169 KiB |
@@ -41,6 +41,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
sf::Sprite actorSprite;
|
sf::Sprite actorSprite;
|
||||||
sf::Texture actorTexture;
|
sf::Texture actorTexture;
|
||||||
|
sf::Texture bulletTexture;
|
||||||
Position position;
|
Position position;
|
||||||
unsigned int hp;
|
unsigned int hp;
|
||||||
unsigned int damage;
|
unsigned int damage;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class Bullet {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Bullet(float x, float y);
|
Bullet(float x, float y, sf::Texture &bulletTexture);
|
||||||
void update();
|
void update();
|
||||||
sf::Sprite& getSprite();
|
sf::Sprite& getSprite();
|
||||||
void setSpeed(float speed);
|
void setSpeed(float speed);
|
||||||
|
|||||||
6
main.cpp
6
main.cpp
@@ -13,7 +13,7 @@ int main()
|
|||||||
window.setFramerateLimit(60);
|
window.setFramerateLimit(60);
|
||||||
|
|
||||||
sf::Texture backgroundTexture;
|
sf::Texture backgroundTexture;
|
||||||
backgroundTexture.loadFromFile("../assets/img/background.jpg"); // wczytywanie tła
|
backgroundTexture.loadFromFile("../assets/img/space.jpg"); // wczytywanie tła
|
||||||
sf::Sprite backgroundSprite(backgroundTexture); // tworzenie tła
|
sf::Sprite backgroundSprite(backgroundTexture); // tworzenie tła
|
||||||
|
|
||||||
Player ship(240,650, "../assets/ship/Dreadnought-Base.png"); // tworzenie statku
|
Player ship(240,650, "../assets/ship/Dreadnought-Base.png"); // tworzenie statku
|
||||||
@@ -41,6 +41,10 @@ int main()
|
|||||||
ship.shoot();
|
ship.shoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(event.type == sf::Event::MouseButtonPressed) {
|
||||||
|
ship.shoot();
|
||||||
|
}
|
||||||
|
|
||||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
|
||||||
window.close();
|
window.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ Actor::Actor(int x, int y, std::string path) {
|
|||||||
void Actor::loadTexture(std::string path) {
|
void Actor::loadTexture(std::string path) {
|
||||||
actorTexture.loadFromFile(path);
|
actorTexture.loadFromFile(path);
|
||||||
actorSprite.setTexture(actorTexture);
|
actorSprite.setTexture(actorTexture);
|
||||||
|
|
||||||
|
bulletTexture.loadFromFile("../assets/img/bullet.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::Sprite &Actor::getSprite() {
|
sf::Sprite &Actor::getSprite() {
|
||||||
@@ -35,10 +37,9 @@ Position Actor::getPosition() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Actor::shoot() {
|
void Actor::shoot() {
|
||||||
bullets.emplace_back(position.x + actorSprite.getGlobalBounds().width / 2-62, position.y);
|
bullets.emplace_back(float(position.x) + actorSprite.getGlobalBounds().width / 2-62, position.y, bulletTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Bullet> &Actor::getBullets() {
|
std::vector<Bullet> &Actor::getBullets() {
|
||||||
return bullets;
|
return bullets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "../headers/Bullet.h"
|
#include "../headers/Bullet.h"
|
||||||
|
|
||||||
Bullet::Bullet(float x, float y) {
|
Bullet::Bullet(float x, float y, sf::Texture &bulletTexture) {
|
||||||
outOfBounds = false;
|
outOfBounds = false;
|
||||||
bulletTexture.loadFromFile("../assets/img/bullet.png");
|
// bulletTexture.loadFromFile("../assets/img/bullet.png");
|
||||||
bulletSprite.setTexture(bulletTexture);
|
bulletSprite.setTexture(bulletTexture);
|
||||||
bulletSprite.setPosition(x, y);
|
bulletSprite.setPosition(x, y);
|
||||||
bulletSpeed = -10.0f;
|
bulletSpeed = -10.0f;
|
||||||
@@ -24,6 +24,6 @@ void Bullet::update() {
|
|||||||
bulletPosition.y += bulletSpeed;
|
bulletPosition.y += bulletSpeed;
|
||||||
if(bulletPosition.y < -100) {
|
if(bulletPosition.y < -100) {
|
||||||
outOfBounds = true;
|
outOfBounds = true;
|
||||||
std::cout << "Bullet out of bounds\n";
|
// std::cout << "Bullet out of bounds\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user