2016-04-03 19:05:27 +00:00
|
|
|
#include "constants.hpp"
|
2016-04-09 03:43:40 +00:00
|
|
|
#include "level.hpp"
|
2016-04-03 19:05:27 +00:00
|
|
|
#include "player.hpp"
|
2016-04-09 03:43:40 +00:00
|
|
|
#include "block.hpp"
|
|
|
|
#include "gravity_block.hpp"
|
2016-04-11 00:20:40 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2016-04-03 19:05:27 +00:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <cstring>
|
|
|
|
#include <queue>
|
|
|
|
|
2016-04-09 14:31:09 +00:00
|
|
|
/**
|
|
|
|
* Constante de gravité
|
|
|
|
*/
|
2016-04-09 02:58:46 +00:00
|
|
|
const float GRAVITY = 235;
|
2016-04-09 14:31:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constante de déplacement des objets à déplacement manuel
|
|
|
|
*/
|
2016-04-09 14:12:18 +00:00
|
|
|
const float MOVE = 200;
|
2016-04-09 02:58:46 +00:00
|
|
|
|
2016-04-10 04:53:45 +00:00
|
|
|
/**
|
|
|
|
* Numéro actuel de version du format de fichier
|
|
|
|
*/
|
|
|
|
const unsigned int VERSION_NUMBER = 0;
|
|
|
|
|
2016-04-03 19:05:27 +00:00
|
|
|
/**
|
|
|
|
* Dictionnaire associant les types d'objets
|
|
|
|
* à des instances qui seront utilisées pour la
|
|
|
|
* construction d'autres objets de ces types
|
|
|
|
*/
|
2016-04-10 05:37:09 +00:00
|
|
|
std::map<unsigned int, std::function<Object::Ptr(std::ifstream&)>> object_type_map = {
|
2016-04-03 19:05:27 +00:00
|
|
|
{Player::TYPE_ID, Player::load},
|
2016-04-09 03:43:40 +00:00
|
|
|
{Block::TYPE_ID, Block::load},
|
|
|
|
{GravityBlock::TYPE_ID, GravityBlock::load}
|
2016-04-03 19:05:27 +00:00
|
|
|
};
|
|
|
|
|
2016-04-11 00:20:40 +00:00
|
|
|
Level::Level(Manager& manager) : State(manager) {
|
|
|
|
camera.setCenter(0, 0);
|
|
|
|
}
|
|
|
|
|
2016-04-09 00:32:11 +00:00
|
|
|
Level::~Level() {}
|
2016-04-03 19:05:27 +00:00
|
|
|
|
2016-04-11 00:20:40 +00:00
|
|
|
void Level::load() {
|
|
|
|
// métadonnées par défaut
|
|
|
|
name = sf::String("Nouveau niveau");
|
|
|
|
current_file = "";
|
|
|
|
total_time = 30;
|
|
|
|
|
|
|
|
// zone de jeu par défaut
|
|
|
|
zone.clear();
|
|
|
|
zone.push_back(sf::Vector2f(-128, -128));
|
|
|
|
zone.push_back(sf::Vector2f(128, -128));
|
|
|
|
zone.push_back(sf::Vector2f(128, 128));
|
|
|
|
zone.push_back(sf::Vector2f(-128, 128));
|
|
|
|
|
|
|
|
// ressources par défaut
|
|
|
|
music = "";
|
|
|
|
background = "";
|
|
|
|
|
|
|
|
// objets par défaut
|
|
|
|
// TODO: ajouter quelques objets par défaut
|
|
|
|
}
|
|
|
|
|
2016-04-10 04:53:45 +00:00
|
|
|
void Level::load(std::string filename) {
|
2016-04-10 07:41:26 +00:00
|
|
|
std::ifstream file;
|
2016-04-11 00:20:40 +00:00
|
|
|
std::string full_path = getResourceManager().getLevelPath(filename);
|
|
|
|
|
|
|
|
// si le fichier n'existe pas, on utilise le niveau par défaut
|
|
|
|
if (!boost::filesystem::exists(full_path)) {
|
|
|
|
load();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// sinon, on charge les propriétés depuis le fichier
|
2016-04-10 07:41:26 +00:00
|
|
|
file.open(
|
|
|
|
getResourceManager().getLevelPath(filename),
|
|
|
|
std::ios::binary | std::ios::in
|
|
|
|
);
|
|
|
|
|
|
|
|
// on vérifie que le fichier ait correctement été ouvert en lecture
|
|
|
|
if (file.fail()) {
|
|
|
|
throw std::runtime_error(
|
|
|
|
"Impossible de charger le niveau \"" + name + "\" " +
|
|
|
|
"(" + std::string(strerror(errno)) + ")"
|
|
|
|
);
|
|
|
|
}
|
2016-04-03 19:05:27 +00:00
|
|
|
|
|
|
|
// lecture de la signture du fichier ("BAR")
|
2016-04-11 00:20:40 +00:00
|
|
|
current_file = filename;
|
2016-04-03 19:05:27 +00:00
|
|
|
char signature[3];
|
2016-04-10 04:53:45 +00:00
|
|
|
file.read(signature, 3);
|
2016-04-03 19:05:27 +00:00
|
|
|
|
2016-04-10 04:53:45 +00:00
|
|
|
if (strncmp(signature, "BAR", 3) != 0) {
|
2016-04-03 19:05:27 +00:00
|
|
|
throw std::runtime_error(
|
2016-04-11 00:20:40 +00:00
|
|
|
"Impossible de charger le niveau \"" + name + "\" " +
|
|
|
|
"(en-tête invalide)"
|
2016-04-03 19:05:27 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// lecture de la version du fichier
|
|
|
|
char file_version;
|
2016-04-10 03:10:27 +00:00
|
|
|
file.read(&file_version, 1);
|
2016-04-03 19:05:27 +00:00
|
|
|
|
2016-04-10 04:53:45 +00:00
|
|
|
if (file_version != VERSION_NUMBER) {
|
2016-04-03 19:05:27 +00:00
|
|
|
throw std::runtime_error(
|
2016-04-11 00:20:40 +00:00
|
|
|
"Impossible de charger le niveau \"" + name + "\" " +
|
|
|
|
"(version non prise en charge)"
|
2016-04-03 19:05:27 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// lecture du nom du niveau
|
2016-04-06 12:02:11 +00:00
|
|
|
std::string std_name;
|
2016-04-10 03:10:27 +00:00
|
|
|
std::getline(file, std_name, '\0');
|
2016-04-06 12:02:11 +00:00
|
|
|
name = sf::String(std_name);
|
2016-04-03 19:05:27 +00:00
|
|
|
|
2016-04-05 18:16:20 +00:00
|
|
|
// lecture du temps total du niveau
|
2016-04-10 04:53:45 +00:00
|
|
|
file.read(reinterpret_cast<char*>(&total_time), 4);
|
2016-04-05 18:16:20 +00:00
|
|
|
total_time = ntohl(total_time);
|
|
|
|
|
2016-04-03 19:05:27 +00:00
|
|
|
// lecture de la zone de jeu
|
|
|
|
char control_points;
|
2016-04-10 03:10:27 +00:00
|
|
|
file.read(&control_points, 1);
|
2016-04-03 19:05:27 +00:00
|
|
|
zone.clear();
|
|
|
|
|
|
|
|
for (int i = 0; i < control_points; i++) {
|
|
|
|
float pos_x, pos_y;
|
|
|
|
|
2016-04-10 04:53:45 +00:00
|
|
|
file.read(reinterpret_cast<char*>(&pos_x), 4);
|
|
|
|
file.read(reinterpret_cast<char*>(&pos_y), 4);
|
2016-04-03 19:05:27 +00:00
|
|
|
|
|
|
|
pos_x *= Constants::GRID;
|
|
|
|
pos_y *= Constants::GRID;
|
|
|
|
|
2016-04-10 06:33:09 +00:00
|
|
|
zone.push_back(sf::Vector2f(pos_x, pos_y));
|
2016-04-03 19:05:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// lecture des chemins de la musique et du fond
|
2016-04-10 04:53:45 +00:00
|
|
|
std::getline(file, music, '\0');
|
|
|
|
std::getline(file, background, '\0');
|
2016-04-03 19:05:27 +00:00
|
|
|
|
2016-04-10 04:53:45 +00:00
|
|
|
// lecture des objets
|
|
|
|
int object_count;
|
2016-04-03 19:05:27 +00:00
|
|
|
|
2016-04-10 04:53:45 +00:00
|
|
|
file.read(reinterpret_cast<char*>(&object_count), 4);
|
|
|
|
object_count = ntohl(object_count);
|
2016-04-03 19:05:27 +00:00
|
|
|
|
2016-04-10 04:53:45 +00:00
|
|
|
for (int i = 0; i < object_count; i++) {
|
|
|
|
char object_type;
|
|
|
|
file.read(&object_type, 1);
|
2016-04-03 19:05:27 +00:00
|
|
|
|
|
|
|
// vérifie que le type est pris en charge
|
|
|
|
// pour éviter une erreur de segmentation
|
2016-04-10 04:53:45 +00:00
|
|
|
if (object_type_map.count(object_type) == 0) {
|
2016-04-03 19:05:27 +00:00
|
|
|
throw std::runtime_error(
|
2016-04-11 00:20:40 +00:00
|
|
|
"Impossible de charger le niveau \"" + name + "\" " +
|
|
|
|
"(type d'objet " + std::to_string(object_type) + " inconnu)"
|
2016-04-03 19:05:27 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-04-10 04:53:45 +00:00
|
|
|
// lecture de l'objet
|
2016-04-10 21:00:10 +00:00
|
|
|
addObject(object_type_map[object_type](file));
|
2016-04-03 19:05:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-10 04:53:45 +00:00
|
|
|
void Level::save(std::string filename) {
|
2016-04-10 07:41:26 +00:00
|
|
|
std::ofstream file;
|
|
|
|
file.open(
|
|
|
|
getResourceManager().getLevelPath(filename),
|
|
|
|
std::ios::binary | std::ios::out
|
|
|
|
);
|
|
|
|
|
|
|
|
// on vérifie que le fichier ait correctement été ouvert en lecture
|
|
|
|
if (file.fail()) {
|
|
|
|
throw std::runtime_error(
|
|
|
|
"Impossible d'enregistrer le niveau \"" + name + "\" " +
|
|
|
|
"(" + std::string(strerror(errno)) + ")"
|
|
|
|
);
|
|
|
|
}
|
2016-04-10 04:53:45 +00:00
|
|
|
|
|
|
|
// écriture de la signture du fichier ("BAR")
|
|
|
|
char signature[3] = {'B', 'A', 'R'};
|
|
|
|
file.write(signature, 3);
|
|
|
|
|
|
|
|
// écriture de la version du fichier
|
|
|
|
char file_version = VERSION_NUMBER;
|
|
|
|
file.write(&file_version, 1);
|
|
|
|
|
|
|
|
// écriture du nom du niveau
|
|
|
|
char *write_name = (char*) name.toAnsiString().data();
|
|
|
|
file.write(write_name, name.getSize() + 1);
|
|
|
|
|
|
|
|
// écriture du temps total du niveau
|
|
|
|
int conv_total_time = htonl(total_time);
|
|
|
|
file.write(reinterpret_cast<char*>(&conv_total_time), 4);
|
|
|
|
|
|
|
|
// écriture de la zone de jeu
|
|
|
|
char control_points = (char) zone.size();
|
|
|
|
file.write(&control_points, 1);
|
|
|
|
|
|
|
|
for (int i = 0; i < control_points; i++) {
|
2016-04-10 06:33:09 +00:00
|
|
|
float pos_x = zone[i].x / Constants::GRID;
|
|
|
|
float pos_y = zone[i].y / Constants::GRID;
|
2016-04-10 04:53:45 +00:00
|
|
|
|
|
|
|
file.write(reinterpret_cast<char*>(&pos_x), 4);
|
|
|
|
file.write(reinterpret_cast<char*>(&pos_y), 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
// écriture des noms de la musique et du fond
|
|
|
|
char *write_music = (char*) music.data();
|
|
|
|
file.write(write_music, music.size() + 1);
|
2016-04-09 20:36:07 +00:00
|
|
|
|
2016-04-10 04:53:45 +00:00
|
|
|
char *write_background = (char*) background.data();
|
|
|
|
file.write(write_background, background.size() + 1);
|
|
|
|
|
|
|
|
// écriture des objets
|
|
|
|
int object_count = htonl(objects.size());
|
|
|
|
file.write(reinterpret_cast<char*>(&object_count), 4);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < objects.size(); i++) {
|
|
|
|
char object_type = objects[i]->getTypeId();
|
|
|
|
file.write(&object_type, 1);
|
|
|
|
|
|
|
|
// écriture de l'objet
|
|
|
|
objects[i]->save(file);
|
|
|
|
}
|
2016-04-03 19:05:27 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 00:20:40 +00:00
|
|
|
void Level::save() {
|
|
|
|
save(current_file);
|
|
|
|
}
|
|
|
|
|
2016-04-09 00:32:11 +00:00
|
|
|
void Level::begin() {
|
2016-04-10 18:40:02 +00:00
|
|
|
sf::Vector2u window_size = getWindow().getSize();
|
|
|
|
camera.setSize(window_size.x, window_size.y);
|
2016-04-10 03:10:27 +00:00
|
|
|
camera_angle = 180.f;
|
|
|
|
gravity_direction = GravityDirection::SOUTH;
|
2016-04-07 22:19:01 +00:00
|
|
|
}
|
|
|
|
|
2016-04-08 00:35:17 +00:00
|
|
|
void Level::processEvent(const sf::Event& event) {
|
2016-04-08 00:21:19 +00:00
|
|
|
// lorsque la fenêtre est redimensionnée, mise à jour
|
|
|
|
// de la taille de la caméra
|
|
|
|
if (event.type == sf::Event::Resized) {
|
|
|
|
camera.setSize(event.size.width, event.size.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-03 19:05:27 +00:00
|
|
|
void Level::draw() {
|
2016-04-09 02:36:30 +00:00
|
|
|
sf::RenderWindow& window = getWindow();
|
2016-04-08 00:21:19 +00:00
|
|
|
|
2016-04-09 14:31:09 +00:00
|
|
|
// animation de la rotation de la caméra
|
2016-04-09 15:37:12 +00:00
|
|
|
float goal = std::fmod((float) gravity_direction * 90, 360);
|
|
|
|
float diff = goal - camera_angle;
|
2016-04-10 02:47:02 +00:00
|
|
|
float speed = diff * Manager::FRAME_TIME.asSeconds() * 5;
|
2016-04-09 15:37:12 +00:00
|
|
|
|
|
|
|
if (std::abs(diff) < .05f) {
|
|
|
|
camera_angle = goal;
|
|
|
|
} else {
|
|
|
|
camera_angle += speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
camera.setRotation(camera_angle + 180);
|
2016-04-08 00:21:19 +00:00
|
|
|
window.setView(camera);
|
|
|
|
|
|
|
|
// efface la scène précédente et dessine la couche de fond
|
2016-04-03 19:05:27 +00:00
|
|
|
window.clear(sf::Color(66, 165, 245));
|
2016-04-10 04:53:45 +00:00
|
|
|
|
|
|
|
if (background != "") {
|
|
|
|
background_sprite.setTexture(getResourceManager().getTexture(background));
|
|
|
|
}
|
|
|
|
|
|
|
|
window.draw(background_sprite);
|
2016-04-03 19:05:27 +00:00
|
|
|
|
|
|
|
// chargement de la file d'affichage des objets
|
2016-04-10 05:37:09 +00:00
|
|
|
std::priority_queue<Object::Ptr, std::vector<Object::Ptr>, ObjectCompare> display_queue;
|
2016-04-03 19:05:27 +00:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < objects.size(); i++) {
|
|
|
|
display_queue.push(objects[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// dessin des objets de la file d'affichage couche par couche
|
|
|
|
while (!display_queue.empty()) {
|
2016-04-09 02:36:30 +00:00
|
|
|
display_queue.top()->draw(*this);
|
2016-04-03 19:05:27 +00:00
|
|
|
display_queue.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-06 12:02:11 +00:00
|
|
|
sf::String Level::getName() const {
|
2016-04-03 19:05:27 +00:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2016-04-06 12:02:11 +00:00
|
|
|
void Level::setName(sf::String set_name) {
|
2016-04-05 18:16:20 +00:00
|
|
|
name = set_name;
|
|
|
|
}
|
|
|
|
|
2016-04-06 12:02:11 +00:00
|
|
|
int Level::getTotalTime() const {
|
2016-04-05 18:16:20 +00:00
|
|
|
return total_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Level::setTotalTime(int set_total_time) {
|
2016-04-05 22:30:18 +00:00
|
|
|
// faisons rester le temps entre 10s et 59:59
|
|
|
|
set_total_time = std::min(set_total_time, 3599);
|
|
|
|
set_total_time = std::max(set_total_time, 10);
|
|
|
|
|
2016-04-05 18:16:20 +00:00
|
|
|
total_time = set_total_time;
|
|
|
|
}
|
|
|
|
|
2016-04-10 04:53:45 +00:00
|
|
|
std::string Level::getMusic() const {
|
|
|
|
return music;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Level::setMusic(std::string set_music) {
|
|
|
|
music = set_music;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Level::getBackground() const {
|
2016-04-06 12:02:11 +00:00
|
|
|
return background;
|
|
|
|
}
|
|
|
|
|
2016-04-10 04:53:45 +00:00
|
|
|
void Level::setBackground(std::string set_background) {
|
2016-04-06 12:02:11 +00:00
|
|
|
background = set_background;
|
|
|
|
}
|
|
|
|
|
2016-04-09 02:58:46 +00:00
|
|
|
sf::Vector2f Level::getGravity() const {
|
2016-04-09 14:12:18 +00:00
|
|
|
switch (gravity_direction) {
|
|
|
|
case GravityDirection::NORTH:
|
|
|
|
return sf::Vector2f(0, -GRAVITY);
|
|
|
|
|
|
|
|
case GravityDirection::EAST:
|
|
|
|
return sf::Vector2f(GRAVITY, 0);
|
|
|
|
|
|
|
|
case GravityDirection::SOUTH:
|
|
|
|
return sf::Vector2f(0, GRAVITY);
|
|
|
|
|
|
|
|
case GravityDirection::WEST:
|
|
|
|
return sf::Vector2f(-GRAVITY, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sf::Vector2f(0, 0);
|
2016-04-09 02:58:46 +00:00
|
|
|
}
|
|
|
|
|
2016-04-09 14:12:18 +00:00
|
|
|
sf::Vector2f Level::getLeftDirection() const {
|
|
|
|
switch (gravity_direction) {
|
2016-04-09 02:58:46 +00:00
|
|
|
case GravityDirection::NORTH:
|
2016-04-09 14:12:18 +00:00
|
|
|
return sf::Vector2f(MOVE, 0);
|
2016-04-09 02:58:46 +00:00
|
|
|
|
2016-04-09 03:43:40 +00:00
|
|
|
case GravityDirection::EAST:
|
2016-04-09 14:12:18 +00:00
|
|
|
return sf::Vector2f(0, MOVE);
|
2016-04-09 02:58:46 +00:00
|
|
|
|
|
|
|
case GravityDirection::SOUTH:
|
2016-04-09 14:12:18 +00:00
|
|
|
return sf::Vector2f(-MOVE, 0);
|
2016-04-09 02:58:46 +00:00
|
|
|
|
2016-04-09 03:43:40 +00:00
|
|
|
case GravityDirection::WEST:
|
2016-04-09 14:12:18 +00:00
|
|
|
return sf::Vector2f(0, -MOVE);
|
2016-04-09 02:58:46 +00:00
|
|
|
}
|
2016-04-09 14:12:18 +00:00
|
|
|
|
|
|
|
return sf::Vector2f(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
sf::Vector2f Level::getRightDirection() const {
|
|
|
|
return -1.f * getLeftDirection();
|
|
|
|
}
|
|
|
|
|
|
|
|
GravityDirection Level::getGravityDirection() {
|
|
|
|
return gravity_direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Level::setGravityDirection(GravityDirection set_gravity_direction) {
|
|
|
|
gravity_direction = set_gravity_direction;
|
2016-04-09 02:58:46 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 19:18:21 +00:00
|
|
|
std::vector<Object::Ptr>& Level::getObjects() {
|
2016-04-03 19:05:27 +00:00
|
|
|
return objects;
|
|
|
|
}
|
|
|
|
|
2016-04-10 05:37:09 +00:00
|
|
|
const std::vector<Object::Ptr>& Level::getObjects() const {
|
2016-04-09 02:36:30 +00:00
|
|
|
return objects;
|
|
|
|
}
|
|
|
|
|
2016-04-10 19:18:21 +00:00
|
|
|
std::vector<Player::Ptr>& Level::getPlayers() {
|
|
|
|
return players;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<Player::Ptr>& Level::getPlayers() const {
|
|
|
|
return players;
|
|
|
|
}
|
|
|
|
|
2016-04-10 23:36:20 +00:00
|
|
|
Object::Ptr Level::addObject(Object::Ptr object) {
|
2016-04-10 19:18:21 +00:00
|
|
|
// si c'est un joueur, on le met dans le tableau des joueurs
|
|
|
|
// et on lui attribue un numéro
|
|
|
|
if (object->getTypeId() == Player::TYPE_ID) {
|
2016-04-10 23:36:20 +00:00
|
|
|
// on n'autorise pas plus de deux joueurs
|
|
|
|
if (players.size() >= 2) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-04-10 19:18:21 +00:00
|
|
|
Player::Ptr player = std::dynamic_pointer_cast<Player>(object);
|
|
|
|
|
|
|
|
player->setPlayerNumber(players.size());
|
|
|
|
players.push_back(std::dynamic_pointer_cast<Player>(object));
|
|
|
|
}
|
|
|
|
|
|
|
|
objects.push_back(object);
|
2016-04-10 23:36:20 +00:00
|
|
|
return object;
|
2016-04-10 19:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Level::removeObject(Object::Ptr object) {
|
|
|
|
// si c'est un joueur, on le supprime de la liste des joueurs
|
|
|
|
if (object->getTypeId() == Player::TYPE_ID) {
|
|
|
|
Player::Ptr player = std::dynamic_pointer_cast<Player>(object);
|
|
|
|
players.erase(std::remove(
|
|
|
|
players.begin(), players.end(), player
|
|
|
|
), players.end());
|
|
|
|
|
|
|
|
// on réattribue les numéros de joueurs
|
|
|
|
for (unsigned int i = 0; i < players.size(); i++) {
|
|
|
|
players[i]->setPlayerNumber(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// on supprime l'objet de la liste d'objets
|
|
|
|
objects.erase(std::remove(
|
|
|
|
objects.begin(), objects.end(), object
|
|
|
|
), objects.end());
|
|
|
|
}
|
|
|
|
|
2016-04-10 06:33:09 +00:00
|
|
|
std::vector<sf::Vector2f>& Level::getZone() {
|
2016-04-03 19:05:27 +00:00
|
|
|
return zone;
|
|
|
|
}
|
2016-04-07 22:19:01 +00:00
|
|
|
|
2016-04-10 06:33:09 +00:00
|
|
|
const std::vector<sf::Vector2f>& Level::getZone() const {
|
2016-04-09 02:36:30 +00:00
|
|
|
return zone;
|
|
|
|
}
|
|
|
|
|
|
|
|
sf::View Level::getCamera() const {
|
2016-04-08 00:21:19 +00:00
|
|
|
return camera;
|
|
|
|
}
|
|
|
|
|
2016-04-08 22:26:47 +00:00
|
|
|
sf::Vector2f Level::pixelToCoords(sf::Vector2i pixel) {
|
2016-04-09 02:36:30 +00:00
|
|
|
sf::RenderWindow& window = getWindow();
|
2016-04-08 00:21:19 +00:00
|
|
|
sf::View old_view = window.getView();
|
|
|
|
|
|
|
|
window.setView(camera);
|
2016-04-08 22:26:47 +00:00
|
|
|
sf::Vector2f coords = window.mapPixelToCoords(pixel);
|
2016-04-08 00:21:19 +00:00
|
|
|
window.setView(old_view);
|
|
|
|
|
2016-04-08 22:26:47 +00:00
|
|
|
return coords;
|
|
|
|
}
|
|
|
|
|
|
|
|
sf::Vector2i Level::coordsToPixel(sf::Vector2f coords) {
|
2016-04-09 02:36:30 +00:00
|
|
|
sf::RenderWindow& window = getWindow();
|
2016-04-08 22:26:47 +00:00
|
|
|
sf::View old_view = window.getView();
|
|
|
|
|
|
|
|
window.setView(camera);
|
|
|
|
sf::Vector2i pixel = window.mapCoordsToPixel(coords);
|
|
|
|
window.setView(old_view);
|
|
|
|
|
|
|
|
return pixel;
|
2016-04-07 22:19:01 +00:00
|
|
|
}
|
|
|
|
|
2016-04-08 00:21:19 +00:00
|
|
|
void Level::setCamera(sf::View set_camera) {
|
|
|
|
camera = set_camera;
|
2016-04-07 22:19:01 +00:00
|
|
|
}
|