You are on page 1of 7

#include <iostream> #include <SFML/Graphics.hpp> #include <string> int main() { sf::VideoMode desktop = sf::VideoMode::getDesktopMode(); sf::RenderWindow window(sf::VideoMode(desktop.width, desktop.

height, des ktop.bitsPerPixel), "SFML works!", sf::Style::Fullscreen); /*sf::Vector2i fensterposition = sf::Vector2i(0, 0); window.setPosition(fensterposition);*/ window.setFramerateLimit(75); //maus ausblenden bool mouse = false; window.setMouseCursorVisible(false); bool fullscreen = true; //Hintergrund bool blue = false; bool red = false; bool yellow = false; //Dreieck wandert sf::ConvexShape polygon; polygon.setPointCount(3); polygon.setPoint(0, sf::Vector2f(0, 0)); polygon.setPoint(1, sf::Vector2f(0, 10)); polygon.setPoint(2, sf::Vector2f(25, 5)); polygon.setOutlineColor(sf::Color::Red); polygon.setOutlineThickness(5); polygon.setPosition(10, 20); //Dreieck dreht bool zeichnen = false; sf::ConvexShape polygon1; polygon1.setPointCount(3); polygon1.setPoint(0, sf::Vector2f(20, 55)); polygon1.setPoint(1, sf::Vector2f(8, 23)); polygon1.setPoint(2, sf::Vector2f(50, 30)); polygon1.setOutlineColor(sf::Color::Blue); polygon1.setOutlineThickness(5); polygon1.setPosition(100, 100); polygon1.setOrigin(sf::Vector2f(8, 23)); polygon.setRotation(10); //Kreis farbe unsigned int R = 152, G = 48, B = 268; sf::CircleShape kreis; kreis.setPosition(50, 60); kreis.setRadius(20); kreis.setFillColor(sf::Color(R, G, B)); //Viereck gr e sf::RectangleShape recht; recht.setFillColor(sf::Color::Green);

recht.setSize(sf::Vector2f(30.f, 40.f)); recht.setPosition(107, 77); //Text sf::Font font; font.loadFromFile("sansation.ttf"); std::string belegung = "ESC - Schlie en\n" "Q - Drehendes Polygon einblenden\n" "R - Reset\n" "C - Auflsungen\n" "E - Bewegen\n" "T - Test\n" "1-4 - Hintergrundfarbe\n" "M - Maus ein/ausblenden\n" "F - Fenstermodus wechseln"; sf::Text text("FARBWECHSEL!!!", font, 20); text.setColor(sf::Color::Green); text.setPosition(1.f, -3.f); text.setStyle(sf::Text::Bold); sf::Text text1(belegung, font, 20); text1.setColor(sf::Color::Blue); text1.setPosition(1.f, 170.f); text1.setStyle(sf::Text::Bold); //Zeit berechnung sf::Clock clock; clock.restart(); sf::Time time = sf::Time::Zero; float sek; //Start while(window.isOpen()) { sf::Event event; time = clock.getElapsedTime(); sek = time.asSeconds(); sf::Vector2u fenster = sf::Vector2u(window.getSize()); //Farbe von text ndern if(sek >= 1) text.setColor(sf::Color::Blue); if(sek >= 2) text.setColor(sf::Color::Red); if(sek >= 3) text.setColor(sf::Color::Cyan); if(sek >= 4) text.setColor(sf::Color::Yellow); if(sek >= 5) { clock.restart(); text.setColor(sf::Color::Green); } while(window.pollEvent(event)) { if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape) || (

event.type == sf::Event::Closed)) { window.close(); }

if(sf::Keyboard::isKeyPressed(sf::Keyboard::Q) && (event .type == sf::Event::KeyPressed)) { //EINBLENDEN drehendes dreieck if(!zeichnen) zeichnen = true; else if(zeichnen) zeichnen = false; }

if(sf::Keyboard::isKeyPressed(sf::Keyboard::R) && (event .type == sf::Event::KeyPressed)) { //RESET polygon.setPosition(10, 20); polygon1.setRotation(10); float rota1 = polygon1.getRotation(); sf::Vector2f pos = polygon .getPosition(); R = 152; G = 48; B = 268; kreis.setFillColor(sf::Color(R, G, B)); sf::Vector2f scale = recht.getScale(); recht.setScale(0.1f, 0.1f); zeichnen blue red yellow "\tRota: " << rota1 << "\tR:"<< R << " G:" << G < < " B" << B << "\tScale: " << scale.x << "/" << scale.y << "\tRESET" << std::endl; } = = = = false; false; false; false;

std::cout << "X:" << pos.x << "/Y:" << pos.y <<

if(sf::Keyboard::isKeyPressed(sf::Keyboard::C) && (event .type == sf::Event::KeyPressed)) { //Fensterauflsungen std::vector<sf::VideoMode> modes = sf::VideoMode ::getFullscreenModes(); for (std::size_t i = 0; i < modes.size(); ++i) { sf::VideoMode mode = modes[i];

std::cout << "Mode #" << i << ": " << mode.width << "x" < < mode.height << " - " << mode.bitsPerPixel < < " bpp" << std::endl; } }

if(sf::Keyboard::isKeyPressed(sf::Keyboard::E)) { //RUN //Polygon1 rotation float rota1 = polygon1.getRotation(); polygon1.setRotation(rota1 +10); if(rota1 < 10) rota1 = 10;

//Polygon position sf::Vector2f pos = polygon.getPosition(); polygon.setPosition(pos.x + 5, pos.y); sf::Vector2u fenster = sf::Vector2u(window.getSi ze()); if(pos.x >= fenster.x + 5) { pos.y += 20; pos.x = -46; polygon.setPosition(pos.x, pos.y); }

//Kreisfarbe R += 1; G += 1; B += 1; kreis.setFillColor(sf::Color(R, B, G));

//Viereck gr e sf::Vector2f scale = recht.getScale(); if(scale.x < 3 && scale.y < 3) { recht.setScale(scale.x + 0.1f, scale.y + 0.1f); } if(scale.x >= 3 && scale.y >= 3) {

recht.setScale(0.1f, 0.1f); }

//Ausgabe std::cout << "X:" << pos.x << "/Y:" << pos.y << "\tRota: " << rota1 << "\tR:"<< R << " G :" << G << " B" << B << "\tScale: " << scale.x << " /" << scale.y << std::endl; }

if(sf::Keyboard::isKeyPressed(sf::Keyboard::T)) { //TEST std::cout << desktop.height << std::endl; }

if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num1) && (ev ent.type == sf::Event::KeyPressed)) { //blauer hintergrund blue = true; red = false; yellow = false; std::cout << "BLAU" << std::endl; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num2) && (ev ent.type == sf::Event::KeyPressed)) { //roter hintergrund blue = false; red = true; yellow = false; std::cout << "ROT" << std::endl; }

if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num3) && (ev ent.type == sf::Event::KeyPressed)) { //gelber hintergrund blue = false; red = false; yellow = true; std::cout << "GELB" << std::endl; }

if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num4) && (ev ent.type == sf::Event::KeyPressed)) { //Schwarzer hintergrund blue = false; red = false; yellow = false; std::cout << "SCHWARZ" << std::endl; }

if(sf::Keyboard::isKeyPressed(sf::Keyboard::M) && (event .type == sf::Event::KeyPressed)) { //maus anzeigen/ausblenden if(!mouse) { window.setMouseCursorVisible(true); mouse = true; } else if(mouse) { window.setMouseCursorVisible(false); mouse = false; } }

if(sf::Keyboard::isKeyPressed(sf::Keyboard::F) && (event .type == sf::Event::KeyPressed)) { //Fullscreen aus if(fullscreen) { window.create(sf::VideoMode(800, 600, de sktop.bitsPerPixel), "SFML works", sf::Style::Default); fullscreen = false; } //fullscreen an else if(!fullscreen) { window.create(sf::VideoMode(desktop.widt h, desktop.height, desktop.bitsPerPixel),"test", sf::Style::Fullscreen); fullscreen = true; } } } //standart hintergrundfarbe schwarz if(!blue && !red && !yellow) window.clear(); else if(blue) window.clear(sf::Color(sf::Color::Blue));

else if(red) window.clear(sf::Color(sf::Color::Red)); else if(yellow) window.clear(sf::Color(sf::Color::Yellow)); if(zeichnen) window.draw(polygon1); window.draw(polygon); window.draw(kreis); window.draw(recht); window.draw(text); window.draw(text1); window.display(); } return 0; }

You might also like