Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

// include sfml libraries

#include <SFML/Graphics.hpp>

// include standard libraries


#include <iostream>

// include header files


#include "background.hpp"
#include "player.hpp"
#include "config.hpp"

void def_direction(int direction[], int value, sf::Event event) {


switch (event.key.code) {
case sf::Keyboard::Z:
direction[0] = value;
break;
case sf::Keyboard::S:
direction[1] = value;
break;
case sf::Keyboard::Q:
direction[2] = value;
break;
case sf::Keyboard::D:
direction[3] = value;
break;
default:
break;
}
}

// Draw a sprite with a texture using SFML


int main() {
// create a window
sf::RenderWindow window(sf::VideoMode(1920, 1080), "LOL-Dodge de wish");

// create a background object


Background background;
background.create_background("sprites/background.png", 7, 5);
// background.setTexture("sprites/background.png");
// background.setScale(2.7, 2.8);

// create a player object


Player player;
player.createPlayer("sprites/player.png", 0.25, 0.25);

// create a clock object


Clock clock;
sf::Clock sfClock;

int direction[4] = {0, 0, 0, 0};

// main loop
while (window.isOpen()) {
// check all the window's events that were triggered since the last
iteration of the loop
sf::Event event;
while (window.pollEvent(event)) {
// "close requested" event: we close the window
if (event.type == sf::Event::Closed) {
window.close();
}
// "Escape key pressed" event: we close the window
if (event.type == sf::Event::KeyPressed && event.key.code ==
sf::Keyboard::Escape) {
window.close();
}
// Key pressed event
if (event.type == sf::Event::KeyPressed) {
sfClock.restart();
def_direction(direction, 1, event);
}
// Key released event
if (event.type == sf::Event::KeyReleased) {
def_direction(direction, 0, event);
}
}

if(std::find(std::begin(direction), std::end(direction), 1) !=
std::end(direction)) {
std::cout << direction[0] << direction[1] << direction[2] <<
direction[3] << std::endl;
std::cout << direction[3] - direction[2] << direction[1] - direction[0]
<< std::endl;
player.move(direction[3] - direction[2], direction[1] - direction[0],
sfClock);
}

// clear the window with black color


window.clear(sf::Color::Black);

// draw everything here...


background.draw(window);
player.draw(window);

// end the current frame


window.display();
}

return 0;
}

You might also like