Commit 630e5561 authored by papush!'s avatar papush!

C’est le plombier.

parent c8d59890
This diff is collapsed.
......@@ -70,16 +70,6 @@ get_chunk_coordinates_from_player_movement (struct coordinates player_offset);
std::string get_save_directory_path ();
enum class binded_to
{
north,
north_east,
east,
south,
south_west,
west
};
class Map;
......@@ -116,36 +106,23 @@ class Chunk
inline struct coordinates getTileCoordinates () const;
/**
* Get the chunk’s texture.
* Get the chunk’s textures.
*
* @return the chunk’s texture.
* @return the chunk’s textures.
*/
const sf::Texture& get_chunk_texture ();
const std::vector<std::vector<std::pair<sf::Texture, sf::Texture>>>& get_chunk_textures ();
void set_square_item (struct coordinates square_coordinates, int item_id,
int quantity = 1);
int quantity = 1);
int get_square_item_id (struct coordinates square_coordinates);
int get_square_item_quantity (struct coordinates square_coordinates);
time_t getLastUse () const;
std::vector<binded_to> get_bindings () const;
void add_missing_texture (std::tuple<Rectangle,
Rectangle, int, binded_to> missing_texture);
void remove_missing_texture (std::tuple<Rectangle,
Rectangle, int, binded_to> missing_texture);
void force_item_surface_regeneration ();
void bind ();
coordinates get_chunk_coordinates_from_binding (binded_to binding) const;
bool operator== (const Chunk &other);
private:
sf::RenderTexture m_chunk_texture;
sf::RenderTexture m_ground, m_items;
std::vector<std::vector<std::pair<sf::Texture, sf::Texture>>> m_chunk_textures;
Map *m_map;
chunk_proto *m_me;
......@@ -153,38 +130,10 @@ class Chunk
time_t m_last_use;
/**
* List of chunk bindings because of us.
*
* The first member of the pair is the chunk with whom we are
* binded.
*
* The second member is the coordinates of the square which
* binds us to this chunk.
*/
std::vector<std::tuple<Rectangle, Rectangle, int,
binded_to, coordinates>> m_bindings;
/**
* This is the vector containing the missing texture’s bit.
*
* The tuple contains the location, the texture’s bit, the item id
* and with whom we are binded.
*/
std::vector<std::tuple<Rectangle, Rectangle, int, binded_to>> m_missing_texture_bit;
unsigned m_square_size = 24;
unsigned m_square_per_row = 16;
void generate_ground_surface ();
void generate_item_surface ();
void generate_texture ();
void bind_chunk (coordinates square_coordinates, int square_item,
Rectangle position_on_floor);
void blit_missing_textures_bit ();
void regenerate_item_surface_of_chunks_binded ();
};
......@@ -215,14 +164,14 @@ class Map
~Map ();
/**
* Obtain the texture of a specific chunk.
* Obtain the textures of a specific chunk.
*
* @param chunk_coordinates is the coordinates of the chunk frow
* which we want the texture.
* which we want the textures.
*
* @return the chunk texture.
* @return the chunk textures.
*/
const sf::Texture& get_chunk_texture (struct coordinates chunk_coordinates);
const std::vector<std::vector<std::pair<sf::Texture, sf::Texture>>>& get_chunk_textures (struct coordinates chunk_coordinates);
/**
* Obtain the item id at the specified coordinates.
......@@ -234,30 +183,14 @@ class Map
* @return the item id of the item on the surface.
*/
int get_surface_item (struct coordinates chunk_coordinates,
struct coordinates square_coordinates);
struct coordinates square_coordinates);
void set_surface_item (struct coordinates chunk_coordinates,
struct coordinates square_coordinates, int item_id,
int quantity = 1);
struct coordinates square_coordinates, int item_id,
int quantity = 1);
void save();
/**
* Bind a chunk to another chunk.
*
* @param chunk_coordinates is the coordinates of the chunk to bind.
* @param binding is the tuple which contain the binding, see
* Chunk::m_missing_texture_bit.
*/
void bind_chunk (coordinates chunk_coordinates,
std::tuple<Rectangle, Rectangle, int, binded_to> binding);
void remove_missing_texture (coordinates chunk_coordinates,
std::tuple<Rectangle,
Rectangle, int, binded_to> missing_texture);
void force_item_surface_regeneration (coordinates chunk_coordinates);
private:
int m_seed;
std::string m_game_path;
......@@ -276,17 +209,11 @@ class Map
void save_tiles ();
void unload_unused_chunks ();
void unload_chunks (std::vector<std::shared_ptr<Chunk>> chunks);
bool check_if_chunks_bindings_need_to_be_deleted (std::shared_ptr<Chunk> chunk,
bool check_down = true,
bool check_up = true);
std::vector<std::shared_ptr<Chunk>>
get_chunks_binded_group (std::shared_ptr<Chunk> chunk, bool look_up = true,
bool look_down = true);
void unload_chunk (std::shared_ptr<Chunk> chunk);
void generate_tile (struct coordinates tile_coordinates);
struct coordinates get_tile_by_chunk (struct coordinates
chunk_coordinates) const;
chunk_coordinates) const;
int get_floor_id (double random_value);
int get_item_id (double random_value);
......@@ -294,4 +221,3 @@ class Map
std::shared_ptr<Chunk> get_chunk_by_coordinates (coordinates chunk_coordinates);
};
binded_to get_opposite_binding (binded_to binding);
......@@ -34,17 +34,14 @@
void
display_background (sf::RenderWindow & window,
Map& map,
struct coordinates screen_origin)
Map& map,
struct coordinates screen_origin)
{
int number_of_square_per_row = 16;
int square_width = 24;
const int chunk_width = number_of_square_per_row * square_width;
screen_origin.x = (screen_origin.x < 0)? 0 : screen_origin.x;
screen_origin.y = (screen_origin.y < 0)? 0 : screen_origin.y;
struct coordinates hero_coords;
struct coordinates coords;
......@@ -53,16 +50,37 @@ display_background (sf::RenderWindow & window,
for(int i(0); i < screen_dimensions.y + screen_origin.y % chunk_width; i += chunk_width)
{
for(int j(0); j < screen_dimensions.x + screen_origin.x % chunk_width ; j += chunk_width)
{
hero_coords = {.x = (int) screen_origin.x + j,
.y = (int) screen_origin.y + i};
coords = get_chunk_coordinates_from_player_movement (hero_coords);
{
hero_coords = {.x = (int) screen_origin.x + j,
.y = (int) screen_origin.y + i};
coords = get_chunk_coordinates_from_player_movement (hero_coords);
sf::Sprite sprite (map.get_chunk_texture (coords));
sprite.setPosition (j - screen_origin.x % chunk_width,
i - screen_origin.y % chunk_width);
int y = 0;
for (const std::vector<std::pair<sf::Texture, sf::Texture>> &row : map.get_chunk_textures (coords))
{
int x = 0;
for (const std::pair<sf::Texture, sf::Texture> &textures : row)
{
sf::Sprite ground (textures.second);
sf::Sprite item (textures.first);
int item_height = textures.second.getSize ().y;
window.draw (sprite);
}
ground.setPosition (j - screen_origin.x % chunk_width
+ x*square_width,
i - screen_origin.y % chunk_width // Origine du tronçon en coordonnées d’écran.
+ y*square_width); // Décalage de la case.
item.setPosition (j - screen_origin.x % chunk_width
+ x*square_width,
i - screen_origin.y % chunk_width
+ y*square_width
- item_height); // Chuuuuuuuuuut.
window.draw(ground);
window.draw(item);
x++;
}
y++;
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment