#include <SFML/Window.hpp>
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <vector>
#include <cstdlib>
#include <time.h>
#include <sstream>
#include "Gracz.h"
#include "Sound.h"
#include "Timer.h"
#include "Item.h"
#include "Text.h"
#include "Interface.h"
using namespace std;
int main()
{
srand(time(NULL));
vector<Item> items;
vector<Text> texts;
ostringstream ss1;
ostringstream ss2;
Interface interfejs;
for(int i = 0; i < 2; i++)
{
items.push_back(Item(1, interfejs.getRandom(15, 1265), interfejs.getRandom(15, 985)));
items[items.size()].setskin();
}
texts.push_back(Text("arial", 330, 770, 50, "black", 0));
texts.push_back(Text("arial", 400, 1, 30, "black", 0));
texts[0].setFont("arial");
texts[0].setText("To jest tekst");
texts[1].setVisible(1);
texts[1].setFont("arial");
Gracz gracz1;
gracz1.setskin("skin.png");
sf::RenderWindow window(sf::VideoMode(1280, 1000), "Title");
window.setPosition(sf::Vector2i(320, 0));
window.setVerticalSyncEnabled(true); // call it once, after creating the window
while (window.isOpen())
{
ss1.str("");
ss1 << gracz1.getX();
ss2.str("");
ss2 << gracz1.getY();
texts[1].setText("X: "+ss1.str()+" Y: "+ss2.str());
if(interfejs.getItemsonmap() < 2)
{
items.push_back(Item(1, interfejs.getRandom(15, 1265), interfejs.getRandom(15, 985)));
items[items.size()].setskin();
interfejs.setItemsonmap(interfejs.getItemsonmap()+1);
cout << "ITEM: Spawnuje item w x: " << x << " y: " << y << " \n";
}
sf::Event event;
while (window.pollEvent(event))
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
{
gracz1.go(1, items, texts);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
{
gracz1.go(3, items, texts);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
{
gracz1.go(4, items, texts);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
{
gracz1.go(2, items, texts);
}
if (event.type == sf::Event::KeyPressed)
{
if (event.key.code == sf::Keyboard::E)
{
if(gracz1.getinItemrange() >= 0)
{
items.erase(items.begin()+gracz1.getinItemrange());
texts[0].setVisible(0);
gracz1.itempickup();
gracz1.setinItemrange(-1);
interfejs.setItemsonmap(interfejs.getItemsonmap()-1);
}
}
}
if (event.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color::White);
gracz1.render(window);
for(int i = 0; items.size() > i; i++)
items[i].render(window);
for(int i = 0; texts.size() > i; i++)
texts[i].render(window);
//window.draw(text2);
window.display();
}
return 0;
}