Compare commits

...

6 Commits

Author SHA1 Message Date
3c4dc154b1 add get hills 2024-08-04 15:33:49 +02:00
5e9082b327 restructure 2024-08-04 15:33:41 +02:00
5e728417aa hilldata 2024-08-04 15:24:26 +02:00
97d2e1913f hills len 2024-08-04 15:19:30 +02:00
67318b1be9 sdl_image 2024-08-04 15:18:30 +02:00
7e508cfc85 rename 2024-08-04 15:12:27 +02:00
22 changed files with 90 additions and 82 deletions

View File

@ -9,11 +9,12 @@ endif ()
find_package(SDL2 CONFIG REQUIRED)
find_package(SDL2_ttf CONFIG REQUIRED)
find_package(SDL2_image CONFIG REQUIRED)
find_package(CURL REQUIRED)
file(GLOB KULLE_SRC src/data/kulle_*_png.cpp)
file(GLOB KULLE_HEADER src/data/kulle_*_png.hpp)
file(GLOB KULLE_SOURCES src/data/kulle_*_png.cpp)
file(GLOB KULLE_HEADERS src/data/kulle_*_png.hpp)
add_executable(hang_man src/main.cpp
src/Game.cpp
@ -26,15 +27,17 @@ add_executable(hang_man src/main.cpp
src/GuessCorrector.hpp
src/default_font.cpp
src/default_font.hpp
${KULLE_SRC}
${KULLE_HEADER}
${KULLE_SOURCES}
${KULLE_HEADERS}
src/data/hills.cpp
src/data/hills.hpp
src/utils.cpp
)
target_link_libraries(hang_man PRIVATE
SDL2::SDL2
SDL2::SDL2main
SDL2_ttf::SDL2_ttf
SDL2_image::SDL2_image
CURL::libcurl
)

View File

@ -1,21 +1,13 @@
#include "hills.hpp"
#include "kulle_0_png.hpp"
#include "kulle_1_png.hpp"
#include "kulle_2_png.hpp"
#include "kulle_3_png.hpp"
#include "kulle_4_png.hpp"
#include "kulle_5_png.hpp"
#include "kulle_6_png.hpp"
#include "kulle_7_png.hpp"
unsigned const char *hills[] = {
kulle_0_png,
kulle_1_png,
kulle_2_png,
kulle_3_png,
kulle_4_png,
kulle_5_png,
kulle_6_png,
kulle_7_png,
const HillData hills[] = {
{kulle_0_png, kulle_0_png_length},
{kulle_1_png, kulle_1_png_length},
{kulle_2_png, kulle_2_png_length},
{kulle_3_png, kulle_3_png_length},
{kulle_4_png, kulle_4_png_length},
{kulle_5_png, kulle_5_png_length},
{kulle_6_png, kulle_6_png_length},
{kulle_7_png, kulle_7_png_length},
};
extern const size_t hills_length = 8;

View File

@ -1,3 +1,37 @@
#pragma once
extern unsigned const char *hills[];
#include <cstddef>
extern const unsigned char kulle_0_png[];
extern const size_t kulle_0_png_length;
extern const unsigned char kulle_1_png[];
extern const size_t kulle_1_png_length;
extern const unsigned char kulle_2_png[];
extern const size_t kulle_2_png_length;
extern const unsigned char kulle_3_png[];
extern const size_t kulle_3_png_length;
extern const unsigned char kulle_4_png[];
extern const size_t kulle_4_png_length;
extern const unsigned char kulle_5_png[];
extern const size_t kulle_5_png_length;
extern const unsigned char kulle_6_png[];
extern const size_t kulle_6_png_length;
extern const unsigned char kulle_7_png[];
extern const size_t kulle_7_png_length;
struct HillData {
unsigned const char *data;
const size_t length;
};
extern const HillData hills[];
extern const size_t hills_length;

View File

@ -1,4 +1,4 @@
#include "kulle_0_png.hpp"
#include "hills.hpp"
const unsigned char kulle_0_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,

View File

@ -1,6 +0,0 @@
#pragma once
#include <cstddef>
extern const unsigned char kulle_0_png[];
extern const size_t kulle_0_png_length;

View File

@ -1,4 +1,4 @@
#include "kulle_1_png.hpp"
#include "hills.hpp"
const unsigned char kulle_1_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,

View File

@ -1,6 +0,0 @@
#pragma once
#include <cstddef>
extern const unsigned char kulle_1_png[];
extern const size_t kulle_1_png_length;

View File

@ -1,4 +1,4 @@
#include "kulle_2_png.hpp"
#include "hills.hpp"
const unsigned char kulle_2_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,

View File

@ -1,6 +0,0 @@
#pragma once
#include <cstddef>
extern const unsigned char kulle_2_png[];
extern const size_t kulle_2_png_length;

View File

@ -1,5 +1,4 @@
// This is the bytes of .\Kulle3.png
#include "kulle_3_png.hpp"
#include "hills.hpp"
const unsigned char kulle_3_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,

View File

@ -1,6 +0,0 @@
#pragma once
#include <cstddef>
extern const unsigned char kulle_3_png[];
extern const size_t kulle_3_png_length;

View File

@ -1,4 +1,4 @@
#include "kulle_4_png.hpp"
#include "hills.hpp"
const unsigned char kulle_4_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,

View File

@ -1,6 +0,0 @@
#pragma once
#include <cstddef>
extern const unsigned char kulle_4_png[];
extern const size_t kulle_4_png_length;

View File

@ -1,4 +1,4 @@
#include "kulle_5_png.hpp"
#include "hills.hpp"
const unsigned char kulle_5_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,

View File

@ -1,6 +0,0 @@
#pragma once
#include <cstddef>
extern const unsigned char kulle_5_png[];
extern const size_t kulle_5_png_length;

View File

@ -1,4 +1,4 @@
#include "kulle_6_png.hpp"
#include "hills.hpp"
const unsigned char kulle_6_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,

View File

@ -1,6 +0,0 @@
#pragma once
#include <cstddef>
extern const unsigned char kulle_6_png[];
extern const size_t kulle_6_png_length;

View File

@ -1,4 +1,4 @@
#include "kulle_7_png.hpp"
#include "hills.hpp"
const unsigned char kulle_7_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,

View File

@ -1,6 +0,0 @@
#pragma once
#include <cstddef>
extern const unsigned char kulle_7_png[];
extern const size_t kulle_7_png_length;

25
src/utils.cpp Normal file
View File

@ -0,0 +1,25 @@
#include <stdexcept>
#include "utils.hpp"
#include "SDL_image.h"
#include "data/hills.hpp"
std::vector<SDL_Surface *> get_hills() {
std::vector<SDL_Surface *> surfaces;
for (int i = 0; i < hills_length; i++) {
HillData png = hills[i];
SDL_RWops *rw = SDL_RWFromMem(const_cast<unsigned char *>(png.data), png.length);
if (!rw)
throw std::runtime_error("Failed to create RWops from memory");
SDL_Surface *surface = IMG_Load_RW(rw, 1);
if (!surface) {
SDL_RWclose(rw);
throw std::runtime_error("Failed to load image from memory: " + std::string(IMG_GetError()));
}
surfaces.push_back(surface);
}
return surfaces;
}

View File

@ -1,7 +1,7 @@
#pragma once
#include <cstddef>
#include <vector>
#include "SDL_surface.h"
template<typename T>
constexpr size_t array_len(T *array[]) {
@ -10,3 +10,5 @@ constexpr size_t array_len(T *array[]) {
i++;
return i;
}
std::vector<SDL_Surface*> get_hills();

View File

@ -12,6 +12,7 @@
"version>=": "2.0.20"
},
"sdl2-ttf",
"sdl2-image",
"curl"
]
}