#include "engine.h"
#include <stdlib.h>
#include <iostream>
#include <SFML/System.hpp>
#include "personnage.h"
using namespace std;
using namespace sf;
Engine::Engine() : r_window(sf::VideoMode(800,600),"Test by Marcel")
{
marcel = new Personnage;
}
void Engine::run()
{
while(r_window.isOpen())
{
processEvents();
update();
render();
p_move();
}
}
void Engine::render()
{
r_window.clear();
r_window.draw(marcel->get_perso());
r_window.display();
}
void Engine::update()
{
}
void Engine::processEvents()
{
sf::Event event;
while(r_window.pollEvent(event))
{
if((event.type == sf::Event::Closed) or (event.type == sf::Event::KeyPressed) and (event.key.code == sf::Keyboard::Escape))
{
r_window.close();
}
}
}
void Engine::p_move()
{
system("cls");
marcel->set_p_pos(marcel->get_perso().getPosition().x+5, marcel->get_perso().getPosition().y+5 );
cout << "X" << marcel->get_p_pos().x << "Y" << marcel->get_p_pos().y << endl;
cout << "Inertie" << marcel->get_inertie() << endl;
if(Keyboard::isKeyPressed(Keyboard::Z))
{
marcel->get_perso().move(0,-2*marcel->get_inertie());
marcel->set_inertie(0.01);
}
if(Keyboard::isKeyPressed(Keyboard::S))
{
marcel->get_perso().move(0,2*marcel->get_inertie());
marcel->set_inertie(0.01);
}
if(Keyboard::isKeyPressed(Keyboard::Q))
{
marcel->get_perso().move(-2*marcel->get_inertie(),0);
marcel->set_inertie(0.01);
}
if(Keyboard::isKeyPressed(Keyboard:
))
{
marcel->get_perso().move(2*marcel->get_inertie(),0);
marcel->set_inertie(0.01);
}
marcel->set_inertie(-0.01);
}