Dodane regulacja prędkości i płynejsze poruszanie się
This commit is contained in:
57
main.cpp
57
main.cpp
@@ -1,7 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
|
||||
#include "SFML/Graphics.hpp"
|
||||
#include "headers/Actor.h"
|
||||
#include "headers/Player.h"
|
||||
#include "headers/Bullet.h"
|
||||
|
||||
@@ -17,6 +17,8 @@ int main()
|
||||
sf::Sprite backgroundSprite(backgroundTexture); // tworzenie tła
|
||||
|
||||
Player ship(240,650, "../assets/ship/Dreadnought-Base.png"); // tworzenie statku
|
||||
ship.setMovingSpeed(8);
|
||||
ship.setFirerate(200);
|
||||
|
||||
while (window.isOpen()) {
|
||||
window.clear();
|
||||
@@ -26,32 +28,39 @@ int main()
|
||||
// Tu są handlowane eventy
|
||||
sf::Event event{};
|
||||
while (window.pollEvent(event)) {
|
||||
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
|
||||
if(ship.getPosition().x > -10) {
|
||||
ship.moveLeft();
|
||||
}
|
||||
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
|
||||
if(ship.getPosition().x < 480) {
|
||||
ship.moveRight();
|
||||
}
|
||||
}
|
||||
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
|
||||
ship.shoot();
|
||||
}
|
||||
|
||||
if(event.type == sf::Event::MouseButtonPressed) {
|
||||
ship.shoot();
|
||||
}
|
||||
|
||||
if(event.type == sf::Event::Closed)
|
||||
window.close();
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
|
||||
window.close();
|
||||
}
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
|
||||
ship.shoot();
|
||||
}
|
||||
if(event.type == sf::Event::MouseButtonPressed) {
|
||||
ship.shoot();
|
||||
}
|
||||
}
|
||||
|
||||
if (event.type == sf::Event::Closed)
|
||||
window.close();
|
||||
|
||||
// Sprawdzanie stanu klawiszy w głównej pętli gry
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
|
||||
if(ship.getPosition().x > -10) {
|
||||
ship.moveLeft();
|
||||
}
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
|
||||
if(ship.getPosition().x < 480) {
|
||||
ship.moveRight();
|
||||
}
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
|
||||
if(ship.getPosition().y > 0) {
|
||||
ship.moveUp();
|
||||
}
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
|
||||
if(ship.getPosition().y < 700) {
|
||||
ship.moveDown();
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& bullet : ship.getBullets()) {
|
||||
@@ -65,4 +74,4 @@ int main()
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user