Commit 19b99d92 authored by Corentin Bocquillon's avatar Corentin Bocquillon

Merge branch 'experimental'

parents 60af11fb caa30e11
FROM archlinux/base
RUN pacman --noconfirm -Syu
RUN pacman --noconfirm -S base-devel libxml2 protobuf guile jsoncpp libnoise sfml meson
pipeline
{
agent
{
dockerfile
{
filename 'Dockerfile.build'
}
}
stages
{
stage ('Build')
{
steps
{
sh './generate_protobuf.sh'
sh 'meson build'
sh 'ninja -C build'
}
}
}
}
File mode changed from 100644 to 100755
media/textures/pierre1.png

53 KB | W: | H:

media/textures/pierre1.png

3.11 KB | W: | H:

media/textures/pierre1.png
media/textures/pierre1.png
media/textures/pierre1.png
media/textures/pierre1.png
  • 2-up
  • Swipe
  • Onion skin
media/textures/pierre2.png

54.2 KB | W: | H:

media/textures/pierre2.png

3.68 KB | W: | H:

media/textures/pierre2.png
media/textures/pierre2.png
media/textures/pierre2.png
media/textures/pierre2.png
  • 2-up
  • Swipe
  • Onion skin
media/textures/pierre3.png

53.9 KB | W: | H:

media/textures/pierre3.png

4.12 KB | W: | H:

media/textures/pierre3.png
media/textures/pierre3.png
media/textures/pierre3.png
media/textures/pierre3.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -2,21 +2,22 @@ project('Factorywars', 'cpp', license: 'GPLv3+', version: '0.1',
default_options : ['cpp_std=c++11'])
compilateur = meson.get_compiler('cpp')
en_tetes = [include_directories('src'), include_directories('src/sdl')]
en_tetes = [include_directories('src'), include_directories('src/sfml')]
sources = ['src/main.cpp', 'src/items.cpp', 'src/config.cpp',
'src/items.cpp', 'src/save.cpp', 'src/tile.pb.cc', 'src/player.cpp',
'src/player-data.pb.cc', 'src/utils.cpp', 'src/XMLParser.cpp',
'src/sdl/display_map.cpp', 'src/sdl/game.cpp',
'src/sdl/game_events.cpp', 'src/sdl/gui_utils.cpp',
'src/sdl/gui_utils.h', 'src/sdl/menu.cpp', 'src/sdl/keyboard.cpp',
'src/sdl/mouse.cpp', 'src/sdl/FPSCounter.cpp',
'src/sdl/Interface.cpp', 'src/sdl/ground.cpp',
'src/MapGenerator.cpp', 'src/sdl/map.cpp', 'src/structures.hpp']
'src/sfml/display_map.cpp', 'src/sfml/game.cpp',
'src/sfml/game_events.cpp', 'src/sfml/gui_utils.cpp',
'src/sfml/gui_utils.h', 'src/sfml/menu.cpp', 'src/sfml/keyboard.cpp',
'src/sfml/mouse.cpp', 'src/sfml/FPSCounter.cpp',
'src/sfml/Interface.cpp', 'src/sfml/ground.cpp',
'src/MapGenerator.cpp', 'src/sfml/map.cpp', 'src/structures.hpp',
'src/sfml/inventory_interface.cpp']
libxml2 = dependency('libxml-2.0')
protobuf = dependency('protobuf')
guile = dependency('guile-2.0')
guile = dependency('guile-2.2')
json = dependency('jsoncpp')
noise = compilateur.find_library('noise')
if compilateur.has_header('libnoise/noise.h')
......
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
using namespace sf;
int
main (void)
{
cout << "Génération de l’image de l’inventaire…" << flush;
const int taille_case = 32;
const int espace_entre_case = 2;
const int espace_haut = 48;
const int espace_bas = 48;
const int espace_lateral = 10;
const int nb_case_lateral = 10;
const int nb_case_hauteur = 10;
Image fond;
int width = taille_case * nb_case_lateral;
width += espace_entre_case * (nb_case_lateral - 1);
width += espace_lateral * 2;
int height = taille_case * nb_case_hauteur;
height += espace_entre_case * (nb_case_hauteur - 1);
height += espace_haut + espace_bas;
fond.create (width, height, Color (59, 59, 59));
Image casei;
casei.create (taille_case, taille_case, Color::White);
for (unsigned i = 0; i < nb_case_lateral; ++i)
{
for (unsigned j = 0; j < nb_case_hauteur; ++j)
{
const int x = espace_lateral + i * taille_case + i * espace_entre_case;
const int y = espace_haut + j * taille_case + j * espace_entre_case;
fond.copy (casei, x, y);
}
}
fond.saveToFile ("inventaire.png");
cout << " Terminé !" << endl;
}
......@@ -38,27 +38,27 @@ ItemsName::ItemsName ()
{
string m_items_name[13] = {"Player",
// Ores
"Iron ore",
"Copper ore",
"Coal ore",
"Stone ore",
// Plates
"Iron plate",
"Copper plate",
// Inserters
"Burner inserter",
"Inserter",
"Fast inserter",
// Assembling machines
"Assembling machine",
// Other
"Wood",
"Stone block"};
// Ores
"Iron ore",
"Copper ore",
"Coal ore",
"Stone ore",
// Plates
"Iron plate",
"Copper plate",
// Inserters
"Burner inserter",
"Inserter",
"Fast inserter",
// Assembling machines
"Assembling machine",
// Other
"Wood",
"Stone block"};
for (int i = 0; sizeof (m_items_name) / sizeof (m_items_name[0]); i++)
{
m_items_map[i] = m_items_name[i];
......@@ -71,54 +71,54 @@ ItemsName::getItemName(int id)
return m_items_map[id];
}
std::map<int, sf::Texture> ItemsTexture::m_items_textures_map;
ItemsTexture::ItemsTexture ()
{
if (m_items_textures_map.size () == 0)
load_textures ();
}
ItemsTexture::~ItemsTexture ()
{
}
sf::Texture&
ItemsTexture::get_item_texture (int item_id)
{
return m_items_textures_map[item_id];
}
void
ItemsTexture::load_textures ()
{
string prefix;
if (!RUN_IN_PLACE)
prefix = string (TEXTURESDIR) + "/";
else
prefix = "../media/textures/";
vector<string> m_items_textures_path;
m_items_textures_path.push_back (prefix + "arbre2.png");
m_items_textures_path.push_back (prefix + "cuivre1.png");
m_items_textures_path.push_back (prefix + "cuivre2.png");
m_items_textures_path.push_back (prefix + "cuivre3.png");
m_items_textures_path.push_back (prefix + "fer1.png");
m_items_textures_path.push_back (prefix + "fer2.png");
m_items_textures_path.push_back (prefix + "fer3.png");
m_items_textures_path.push_back (prefix + "charbon1.png");
m_items_textures_path.push_back (prefix + "charbon2.png");
m_items_textures_path.push_back (prefix + "charbon3.png");
for (unsigned i = 1; i < m_items_textures_path.size () + 1; ++i)
{
if (!m_items_textures_map[i].loadFromFile (m_items_textures_path[i-1]))
throw runtime_error (m_items_textures_path[i] + string (" ")
+ " does not exist");
}
}
// std::map<int, sf::Texture> ItemsTexture::m_items_textures_map;
// ItemsTexture::ItemsTexture ()
// {
// if (m_items_textures_map.size () == 0)
// load_textures ();
// }
// ItemsTexture::~ItemsTexture ()
// {
// }
// sf::Texture&
// ItemsTexture::get_item_texture (int item_id)
// {
// return m_items_textures_map[item_id];
// }
// void
// ItemsTexture::load_textures ()
// {
// string prefix;
// if (!RUN_IN_PLACE)
// prefix = string (TEXTURESDIR) + "/";
// else
// prefix = "../media/textures/";
// vector<string> m_items_textures_path;
// m_items_textures_path.push_back (prefix + "arbre2.png");
// m_items_textures_path.push_back (prefix + "cuivre1.png");
// m_items_textures_path.push_back (prefix + "cuivre2.png");
// m_items_textures_path.push_back (prefix + "cuivre3.png");
// m_items_textures_path.push_back (prefix + "fer1.png");
// m_items_textures_path.push_back (prefix + "fer2.png");
// m_items_textures_path.push_back (prefix + "fer3.png");
// m_items_textures_path.push_back (prefix + "charbon1.png");
// m_items_textures_path.push_back (prefix + "charbon2.png");
// m_items_textures_path.push_back (prefix + "charbon3.png");
// for (unsigned i = 1; i < m_items_textures_path.size () + 1; ++i)
// {
// if (!m_items_textures_map[i].loadFromFile (m_items_textures_path[i-1]))
// throw runtime_error (m_items_textures_path[i] + string (" ")
// + " does not exist");
// }
// }
Machines::Machines()
......
......@@ -6,7 +6,7 @@
*
* @section LICENSE
*
* Copyright (C) 2016 Corentin Bocquillon <0x539@nybble.fr>
* Copyright (C) 2016-2018 Corentin Bocquillon <0x539@nybble.fr>
* Copyright (C) 2016 Loup Fourment
* Copyright (C) 2016 Pierre Gillet <pierre.gillet+factorywars@linuxw.info>
*
......@@ -49,17 +49,27 @@ ItemsName
};
class ItemsTexture
// class ItemsTexture
// {
// public:
// ItemsTexture ();
// ~ItemsTexture ();
// sf::Texture& get_item_texture (int item_id);
// private:
// static std::map<int, sf::Texture> m_items_textures_map;
// void load_textures ();
// };
class Item
{
public:
ItemsTexture ();
~ItemsTexture ();
sf::Texture& get_item_texture (int item_id);
int get_id ();
private:
static std::map<int, sf::Texture> m_items_textures_map;
void load_textures ();
int m_id;
};
......
......@@ -33,7 +33,7 @@
#include <getopt.h>
#include <clocale>
#include "sdl/game.h"
#include "sfml/game.h"
#include "gettext.h"
#define _(string) gettext (string)
......@@ -76,11 +76,7 @@ main (int argc, char *argv[])
print_help ();
exit (EXIT_SUCCESS);
break;
// L’option pour spécifier l’IP du serveur auquel on veut se
// connecter.
// case 's':
// IP = optarg;
// break;
case 'v':
print_version ();
exit(EXIT_SUCCESS);
......@@ -98,12 +94,11 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
if (run_gui () != 0)
{
return 1;
}
return 0;
int r = run_gui ();
if (r != 0)
return 1;
else
return 0;
}
static void
......
This diff is collapsed.
This diff is collapsed.
......@@ -476,3 +476,9 @@ Player::update_time (sf::Time elapsed_time)
{
player_walks (elapsed_time);
}
Inventory&
Player::get_inventory ()
{
return m_inventory;
}
......@@ -98,13 +98,12 @@ public:
/**
* Get the inventory array.
*/
*/
std::array<std::array<std::pair<int,int>, 10>, 10>
get_inventory () const;
private:
static const int STACK_LIMIT = 100;
std::array<std::array<std::pair<int,int>, 10>, 10> m_inventory;
std::vector<std::reference_wrapper<std::pair<int, int>>>
......@@ -119,8 +118,7 @@ private:
class Player
{
public:
public:
/**
* Constructor that creates a player with default values.
*/
......@@ -133,7 +131,8 @@ class Player
* @param m_coordinates are the coordinates of the player.
* @param velocity is the velocity of the player.
*/
Player (int health, std::string name, struct coordinates coordinates, int velocity);
Player (int health, std::string name, struct coordinates coordinates,
int velocity);
/**
* Get the player's health.
......@@ -214,7 +213,7 @@ class Player
/**
* Fill the members variables with those in the default save file.
*/
*/
int read_save ();
/**
......@@ -238,7 +237,12 @@ class Player
*/
void update_time (sf::Time elapsed_time);
private:
/**
* Get the player’s inventory.
*/
Inventory& get_inventory ();
private:
std::string m_name;
int m_health;
......
......@@ -6,10 +6,8 @@
*
* @section LICENSE
*
* Copyright (C) 2016 Corentin Bocquillon <0x539@nybble.fr>
*
* Copyright (C) 2016-2018 Corentin Bocquillon <0x539@nybble.fr>
* Copyright (C) 2016 Loup Fourment
*
* Copyright (C) 2016 Pierre Gillet <pierre.gillet+factorywars@linuxw.info>
*
* factorywars is free software: you can redistribute it and/or modify
......
......@@ -36,8 +36,7 @@
#include <SFML/Window.hpp>
#include "game.h"
#include "config.h"
#include "save.hpp"
#include "../save.hpp"
using namespace std;
......@@ -119,10 +118,11 @@ save_players (vector<Player>& players, string player_save_directory)
}
}
Game::Game (sf::RenderWindow & window, string save_name,
Game::Game (sf::RenderWindow &window, string save_name,
string player_name)
: m_window (window), m_interface (window), m_in_game_menu (window),
m_quit (false), m_save (false), m_map (save_name)
m_quit (false), m_save (false), m_map (save_name),
m_inventory_interface (window), m_inventory_opened (false)
{
load_textures ();
......@@ -144,6 +144,10 @@ save_players (vector<Player>& players, string player_save_directory)
if (!m_ttf_freesans.loadFromFile (font_path))
throw runtime_error (font_path + " " + _("does not exist"));
m_inventory_interface.set_font (m_ttf_freesans);
m_current_event_handler = &m_default_event_handler;
create_event_handlers ();
create_interface ();
}
......@@ -158,13 +162,17 @@ Game::run ()
m_window.setKeyRepeatEnabled (false);
display_a_frame ();
int r = 1;
sf::Clock last_displayed_frame_time;
while (true)
{
this->handle_events ();
save_if_necessary ();
if (m_quit)
break;
{
r = 0;
break;
}
move_player_if_necessary ();
handle_clicks ();
......@@ -175,7 +183,7 @@ Game::run ()
}
m_window.setKeyRepeatEnabled (true);
return 1;
return r;
}
void
......@@ -185,6 +193,7 @@ Game::create_player (string player_name)
m_players[0].setSaveFilePath (m_save_path + player_name);
m_players[0].read_save ();
m_current_player_texture = m_player_textures[1];
m_inventory_interface.set_inventory (m_players[0].get_inventory ());
}
void
......@@ -285,7 +294,10 @@ Game::set_event_handlers ()
(sf::Keyboard::Key::Escape, true,
[&, this] () mutable
{
this->display_menu ();
if (this->m_inventory_opened)
this->close_inventory ();
else
this->display_menu ();
});
m_mouse.set_event_handler
......@@ -320,6 +332,92 @@ Game::set_event_handlers ()
(click_map_coords.chunk, click_map_coords.square, -1, 0);
}
});
m_keyboard.set_event_handler
(sf::Keyboard::Key::E, false,
[this] ()
{
if (this->m_inventory_opened)
close_inventory ();
else
open_inventory ();
});
}
void
Game::create_event_handlers ()
{
m_default_event_handler
= [this] (sf::Event event)
{
coordinates click_coords;
switch (event.type)
{
case sf::Event::Closed:
this->m_quit = true;
break;
case sf::Event::KeyPressed:
this->m_keyboard.handle_keyboard_event (event.key.code, true);
break;
case sf::Event::KeyReleased:
this->m_keyboard.handle_keyboard_event (event.key.code, false);
break;
case sf::Event::MouseButtonPressed:
click_coords = {.x = event.mouseButton.x,
.y = event.mouseButton.y};
this->m_mouse.handle_mouse_event (event.mouseButton.button, true,
click_coords);
break;
case sf::Event::MouseButtonReleased:
click_coords = {.x = event.mouseButton.x,
.y = event.mouseButton.y};
this->m_mouse.handle_mouse_event (event.mouseButton.button, false,
click_coords);
break;
case sf::Event::MouseWheelScrolled:
handle_mousewheel (event.mouseWheelScroll, this->m_players);
break;
case sf::Event::Resized:
this->calculate_screen_center ();
this->calculate_screen_relative_player_coordinates ();
this->calculate_screen_origin ();
break;
default:
break;
}
};
m_inventory_event_handler
= [this] (sf::Event event)
{
if (event.type == sf::Event::KeyReleased
&& (event.key.code == sf::Keyboard::Key::Escape
|| event.key.code == sf::Keyboard::Key::E))
{
this->close_inventory ();
return;
}
switch (event.type)
{
case sf::Event::Resized:
case sf::Event::Closed:
this->m_default_event_handler (event);
break;
default:
this->m_inventory_interface.handle_event (event);
break;
}
};
}
void
......@@ -341,6 +439,8 @@ Game::display_a_frame ()
m_interface.display ();
display_players (m_players, m_screen_origin, m_window,
m_current_player_texture);
if (m_inventory_opened)
m_inventory_interface.display ();
m_window.display ();
}
......@@ -358,45 +458,7 @@ Game::handle_events ()
struct coordinates click_coords;
while (m_window.pollEvent (event))
{
switch (event.type)
{
case sf::Event::Closed:
m_quit = true;
break;
case sf::Event::KeyPressed:
m_keyboard.handle_keyboard_event (event.key.code, true);
break;
case sf::Event::KeyReleased:
m_keyboard.handle_keyboard_event (event.key.code, false);
break;
case sf::Event::MouseButtonPressed:
click_coords = {.x = event.mouseButton.x,
.y = event.mouseButton.y};
m_mouse.handle_mouse_event (event.mouseButton.button, true, click_coords);
break;
case sf::Event::MouseButtonReleased:
click_coords = {.x = event.mouseButton.x,
.y = event.mouseButton.y};
m_mouse.handle_mouse_event (event.mouseButton.button, false, click_coords);
break;
case sf::Event::MouseWheelScrolled:
handle_mousewheel (event.mouseWheelScroll, m_players);
break;
case sf::Event::Resized:
calculate_screen_center ();
calculate_screen_relative_player_coordinates ();
calculate_screen_origin ();
break;
default:
break;
}
(*m_current_event_handler) (event);
}
}
......@@ -459,3 +521,17 @@ Game::handle_clicks ()
{
}
void
Game::open_inventory ()
{
m_current_event_handler = &m_inventory_event_handler;
m_inventory_opened = true;
}
void
Game::close_inventory ()
{
m_current_event_handler = &m_default_event_handler;
m_inventory_opened = false;
}
......@@ -50,6 +50,7 @@
#include "keyboard.h"
#include "mouse.h"
#include "Interface.h"
#include "inventory_interface.hpp"
/**
......@@ -59,7 +60,7 @@
int run_gui ();
/**
* Blit the players in “players” on the renderer “renderer”
* Blit the players in “players”.
*
* @param players is the vector containing every players.
* @param screen_origin is the offset in pixels from the origin of the map.
......@@ -92,7 +93,7 @@ class Game
sf::Texture m_current_player_texture;
std::vector<sf::Texture> m_hud_textures;
sf::RenderWindow & m_window;
sf::RenderWindow &m_window;
std::string m_save_path;
std::vector<Player> m_players;
......@@ -116,6 +117,14 @@ class Game
// Font
sf::Font m_ttf_freesans;
std::function<void (sf::Event)> *m_current_event_handler;
std::function<void (sf::Event)> m_default_event_handler;
std::function<void (sf::Event)> m_inventory_event_handler;
Graphics::InventoryInterface m_inventory_interface;
bool m_inventory_opened;
void create_player (std::string player_name);