Compare commits
6 Commits
c609d5ccb0
...
3c4dc154b1
Author | SHA1 | Date | |
---|---|---|---|
3c4dc154b1 | |||
5e9082b327 | |||
5e728417aa | |||
97d2e1913f | |||
67318b1be9 | |||
7e508cfc85 |
@ -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
|
||||
)
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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,
|
||||
|
@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
extern const unsigned char kulle_0_png[];
|
||||
extern const size_t kulle_0_png_length;
|
@ -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,
|
||||
|
@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
extern const unsigned char kulle_1_png[];
|
||||
extern const size_t kulle_1_png_length;
|
@ -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,
|
||||
|
@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
extern const unsigned char kulle_2_png[];
|
||||
extern const size_t kulle_2_png_length;
|
@ -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,
|
||||
|
@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
extern const unsigned char kulle_3_png[];
|
||||
extern const size_t kulle_3_png_length;
|
@ -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,
|
||||
|
@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
extern const unsigned char kulle_4_png[];
|
||||
extern const size_t kulle_4_png_length;
|
@ -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,
|
||||
|
@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
extern const unsigned char kulle_5_png[];
|
||||
extern const size_t kulle_5_png_length;
|
@ -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,
|
||||
|
@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
extern const unsigned char kulle_6_png[];
|
||||
extern const size_t kulle_6_png_length;
|
@ -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,
|
||||
|
@ -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
25
src/utils.cpp
Normal 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;
|
||||
}
|
@ -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();
|
||||
|
@ -12,6 +12,7 @@
|
||||
"version>=": "2.0.20"
|
||||
},
|
||||
"sdl2-ttf",
|
||||
"sdl2-image",
|
||||
"curl"
|
||||
]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user