here main.cpp:
#include <SFML/Graphics.hpp>
#include <iostream>
#include "Player.hpp"
struct Texture{
sf::Texture texture;
sf::Texture background_t_0;
sf::Texture background_t_1;
sf::Texture background_t_2;
sf::Texture background_t_3;
sf::Texture background_t_4;
sf::Texture background_t_5;
sf::Texture background_light_1;
sf::Texture background_t_6;
sf::Texture background_light_0;
sf::Texture background_t_7;
sf::Texture background_t_8;
sf::Texture background_t_9;
}t;
int main(){
sf::RenderWindow window(sf::VideoMode(640, 480), "Pixel game", sf::Style::Default);
sf::Event e;
sf::Sprite background_0;
sf::Sprite background_1;
sf::Sprite background_2;
sf::Sprite background_3;
sf::Sprite background_4;
sf::Sprite background_5;
sf::Sprite light_1;
sf::Sprite background_6;
sf::Sprite light_0;
sf::Sprite background_7;
sf::Sprite background_8;
sf::Sprite background_9;
sf::View view(sf::Vector2f(0.f, 0.f), sf::Vector2f(640.0f, 480.0f));
t.texture.loadFromFile("/home/webmaster/Documents/vscode-sfml/src/Assets/pixil-frame-0(1).png");
t.background_t_0.loadFromFile("/home/webmaster/Documents/vscode-sfml/src/Assets/Free Pixel Art Forest/PNG/Background layers/Layer_0011_0.png");
t.background_t_1.loadFromFile("/home/webmaster/Documents/vscode-sfml/src/Assets/Free Pixel Art Forest/PNG/Background layers/Layer_0010_1.png");
t.background_t_2.loadFromFile("/home/webmaster/Documents/vscode-sfml/src/Assets/Free Pixel Art Forest/PNG/Background layers/Layer_0009_2.png");
t.background_t_3.loadFromFile("/home/webmaster/Documents/vscode-sfml/src/Assets/Free Pixel Art Forest/PNG/Background layers/Layer_0008_3.png");
t.background_t_4.loadFromFile("/home/webmaster/Documents/vscode-sfml/src/Assets/Free Pixel Art Forest/PNG/Background layers/Layer_0006_4.png");
t.background_t_5.loadFromFile("/home/webmaster/Documents/vscode-sfml/src/Assets/Free Pixel Art Forest/PNG/Background layers/Layer_0005_5.png");
t.background_light_1.loadFromFile("/home/webmaster/Documents/vscode-sfml/src/Assets/Free Pixel Art Forest/PNG/Background layers/Layer_0004_Lights.png");
t.background_t_6.loadFromFile("/home/webmaster/Documents/vscode-sfml/src/Assets/Free Pixel Art Forest/PNG/Background layers/Layer_0003_6.png");
t.background_light_0.loadFromFile("/home/webmaster/Documents/vscode-sfml/src/Assets/Free Pixel Art Forest/PNG/Background layers/Layer_0007_Lights.png");
t.background_t_7.loadFromFile("/home/webmaster/Documents/vscode-sfml/src/Assets/Free Pixel Art Forest/PNG/Background layers/Layer_0002_7.png");
t.background_t_8.loadFromFile("/home/webmaster/Documents/vscode-sfml/src/Assets/Free Pixel Art Forest/PNG/Background layers/Layer_0001_8.png");
t.background_t_9.loadFromFile("/home/webmaster/Documents/vscode-sfml/src/Assets/Free Pixel Art Forest/PNG/Background layers/Layer_0000_9.png");
background_0.setTexture(t.background_t_0);
background_1.setTexture(t.background_t_1);
background_2.setTexture(t.background_t_2);
background_3.setTexture(t.background_t_3);
background_4.setTexture(t.background_t_4);
background_5.setTexture(t.background_t_5);
light_1.setTexture(t.background_light_1);
background_6.setTexture(t.background_t_6);
light_0.setTexture(t.background_light_0);
background_7.setTexture(t.background_t_7);
background_8.setTexture(t.background_t_8);
background_9.setTexture(t.background_t_9);
p_1::Player player_1(t.background_t_0, t.texture, sf::Vector2u(8, 8), 0.1f, 150.f);
float dt = 0.f;
sf::Clock clock;
while(window.isOpen()){
dt = clock.restart().asSeconds();
while(window.pollEvent(e)){
switch (e.type)
{
case sf::Event::Closed:
window.close();
break;
case sf::Event::KeyPressed:
switch (e.key.code)
{
case sf::Keyboard::Escape:
window.close();
break;
default:
break;
}
break;
default:
break;
}
}
player_1.update(dt);
view.setCenter(player_1.getPosition());
window.clear(sf::Color::White);
window.setView(view);
window.draw(background_0);
window.draw(background_1);
window.draw(background_2);
window.draw(background_3);
window.draw(background_4);
window.draw(background_5);
window.draw(light_1);
window.draw(background_6);
window.draw(light_0);
window.draw(background_7);
window.draw(background_8);
window.draw(background_9);
player_1.draw(window);
window.display();
}
return 0;
}