Hello guys. I have again a problem. I created 2 rectangle shapes and one is the player who can be moved and one is the floor. When run the code in the place of player appear the floor. What is wrong?
//////////////////////////////
/// Moving System 0.1 ///
/// Created by AlexxanderX ///
/// Build 0001 ///
/// Version 0.1 ///
//////////////////////////////
///////////////
/// Headers ///
///////////////
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>
///////////////
////////////
/// Code ///
////////////
int main()
{
/////////////////////////
// Declarare variabile //
/////////////////////////
sf::Vector2f playersize(50,50); // Marimea jucatorului
sf::Vector2f floorsize(600,50); // Marimea platformei
bool isPlaying = false; // Variabila de verificare a desfasurarii jocului
/////////////////////////
//////////////////////
// Creare fereastra //
//////////////////////
sf::RenderWindow window(sf::VideoMode(800,600),"Moving System"); // Fereastra
window.setVerticalSyncEnabled(true); // OpenGL VerticalSync
//////////////////////
/////////////
// Fonturi //
/////////////
// Font general
sf::Font font;
if (!font.loadFromFile("resources/AGENTORANGE.ttf")) return -1;
/////////////
/////////////////////
// Muzica & Sunete //
/////////////////////
// Muzica
// Muzica de background
// Background Music 1
sf::Music bcgmsc1;
if(!bcgmsc1.openFromFile("resources/backgroundmusic.ogg")) return -1;
bcgmsc1.play();
// Sunete
/////////////////////
// Creare jucator
sf::RectangleShape player;
player.setSize(playersize);
player.setOutlineThickness(3);
player.setOutlineColor(sf::Color::Black);
player.setFillColor(sf::Color::Blue);
player.setOrigin(playersize / 2.f);
////////////
// Mesaje //
////////////
// Mesaj general
sf::Text message;
message.setCharacterSize(40);
message.setFont(font);
message.setPosition(100, 15);
message.setColor(sf::Color::Red);
message.setString("Moving System");
////////////
//////////////////////////////////////
// Viteza jucator si alte variabile //
//////////////////////////////////////
float playerSpeed = 100.f;
//////////////////////////////////////
///////////
// Level //
///////////
sf::RectangleShape floor1;
player.setSize(floorsize);
player.setOutlineThickness(2);
player.setOutlineColor(sf::Color::Green);
player.setFillColor(sf::Color::Black);
player.setOrigin(floorsize / 1.f);
///////////
/////////////
// Actiune //
/////////////
sf::Clock clock; // Crearea ceasului( clock)
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
// Metoda de inchidere
if ((event.type == sf::Event::Closed) ||
((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
{
window.close();
break;
}
if((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space))
{
if(!isPlaying)
{
isPlaying=true;
clock.restart();
// Resetare pozitii
player.setPosition(400,200);
floor1.setPosition(10,600);
}
}
}
if (isPlaying)
{
float deltaTime = clock.restart().asSeconds();
// Miscarea jucatorului
// Miscarea in Stanga
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
sf::Vector2f pos = player.getPosition();
player.move(-playerSpeed * deltaTime,0);
}
// Miscarea in Dreapta
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
sf::Vector2f pos = player.getPosition();
player.move(playerSpeed * deltaTime,0);
}
// Gravitatea
}
// Sterge fereastra
window.clear(sf::Color::Yellow);
// Afisare
if(isPlaying)
{
window.draw(player);
window.draw(floor1);
}
else
{
window.draw(message);
}
// Afisarea ecranul
window.display();
}
return 0;
}