@@ -0,0 +1,10 @@ | |||||
root = true | |||||
[*] | |||||
charset = utf-8 | |||||
end_of_line = lf | |||||
indent_size = 2 | |||||
indent_style = tab | |||||
insert_final_newline = true | |||||
max_line_length = 120 | |||||
tab_width = 2 |
@@ -0,0 +1,62 @@ | |||||
*.d | |||||
*.o | |||||
*.ko | |||||
*.obj | |||||
*.elf | |||||
*.ilk | |||||
*.map | |||||
*.exp | |||||
*.gch | |||||
*.pch | |||||
*.lib | |||||
*.a | |||||
*.la | |||||
*.lo | |||||
*.dll | |||||
*.so | |||||
*.so.* | |||||
*.dylib | |||||
*.exe | |||||
*.out | |||||
*.app | |||||
*.i*86 | |||||
*.x86_64 | |||||
*.hex | |||||
*.dSYM/ | |||||
*.su | |||||
*.idb | |||||
*.pdb | |||||
*.mod* | |||||
*.cmd | |||||
.tmp_versions/ | |||||
modules.order | |||||
Module.symvers | |||||
Mkfile.old | |||||
dkms.conf | |||||
CMakeLists.txt.user | |||||
CMakeCache.txt | |||||
CMakeFiles | |||||
CMakeScripts | |||||
Testing | |||||
Makefile | |||||
cmake_install.cmake | |||||
install_manifest.txt | |||||
compile_commands.json | |||||
CTestTestfile.cmake | |||||
_deps | |||||
Thumbs.db | |||||
Thumbs.db:encryptable | |||||
ehthumbs.db | |||||
ehthumbs_vista.db | |||||
*.stackdump | |||||
[Dd]esktop.ini | |||||
$RECYCLE.BIN/ | |||||
*.cab | |||||
*.msi | |||||
*.msix | |||||
*.msm | |||||
*.msp | |||||
*.lnk | |||||
.idea/ | |||||
cmake-build-debug/ | |||||
dependencies/ |
@@ -0,0 +1,25 @@ | |||||
cmake_minimum_required(VERSION 3.20) | |||||
project(izanami C) | |||||
set(CMAKE_C_STANDARD 11) | |||||
set(SDL2PATH "E:\\Projects\\Games\\izanami\\dependencies\\SDL2-2.0.16\\x86_64-w64-mingw32") | |||||
find_package(SDL2 REQUIRED) | |||||
include_directories(${SDL2_INCLUDE_DIR}) | |||||
add_executable(izanami src/packages/game/main.c src/packages/game/math/IZ_vector.c src/packages/game/math/IZ_vector.h src/packages/game/math/IZ_math.c src/packages/game/math/IZ_math.h src/packages/game/core/IZ_placeable.c src/packages/game/core/IZ_placeable.h src/packages/game/core/IZ_movable.c src/packages/game/core/IZ_movable.h src/packages/game/core/IZ_spatial.c src/packages/game/core/IZ_spatial.h) | |||||
target_link_libraries(izanami ${SDL2_LIBRARY}) | |||||
if (WIN32) | |||||
add_custom_command(TARGET izanami POST_BUILD | |||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different # which executes "cmake - E copy_if_different..." | |||||
"${PROJECT_SOURCE_DIR}/dependencies/SDL2-2.0.16/x86_64-w64-mingw32/bin/SDL2.dll" # <--this is in-file | |||||
$<TARGET_FILE_DIR:izanami>) # <--this is out-file path | |||||
endif (WIN32) | |||||
if (WIN64) | |||||
add_custom_command(TARGET izanami POST_BUILD | |||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different # which executes "cmake - E copy_if_different..." | |||||
"${PROJECT_SOURCE_DIR}/dependencies/SDL2-2.0.16/x86_64-w64-mingw32/bin/SDL2.dll" # <--this is in-file | |||||
$<TARGET_FILE_DIR:izanami>) # <--this is out-file path | |||||
endif (WIN64) |
@@ -0,0 +1,15 @@ | |||||
# sdl2-hello-world | |||||
A beginner template for SDL2 powered by CMake. | |||||
## Setup | |||||
1. Clone this repo. | |||||
2. Download the **SDL2 Development Libraries** from the [official download page](https://www.libsdl.org/download-2.0.php). | |||||
1. For Windows, unpack the archive under `dependencies` folder in this project's root. | |||||
3. Build via CMake. | |||||
## Todo | |||||
- [X] Windows setup | |||||
- [ ] macOS setup |
@@ -0,0 +1 @@ | |||||
#include "IZ_movable.h" |
@@ -0,0 +1,10 @@ | |||||
#ifndef IZ_MOVABLE_H | |||||
#define IZ_MOVABLE_H | |||||
#include "../math/IZ_vector.h" | |||||
typedef struct { | |||||
IZ_Vector velocity; | |||||
} IZ_Movable; | |||||
#endif //IZ_MOVABLE_H |
@@ -0,0 +1 @@ | |||||
#include "IZ_placeable.h" |
@@ -0,0 +1,10 @@ | |||||
#ifndef IZ_PLACEABLE_H | |||||
#define IZ_PLACEABLE_H | |||||
#include "../math/IZ_vector.h" | |||||
typedef struct { | |||||
IZ_Vector location; | |||||
} IZ_Placeable; | |||||
#endif //IZ_PLACEABLE_H |
@@ -0,0 +1 @@ | |||||
#include "IZ_spatial.h" |
@@ -0,0 +1,11 @@ | |||||
#ifndef IZ_SPATIAL_H | |||||
#define IZ_SPATIAL_H | |||||
#include "IZ_placeable.h" | |||||
typedef struct { | |||||
IZ_Placeable placeable; | |||||
IZ_Vector size; | |||||
} IZ_Spatial; | |||||
#endif //IZ_SPATIAL_H |
@@ -0,0 +1,48 @@ | |||||
#include <SDL.h> | |||||
#include <stdbool.h> | |||||
#include <stdio.h> | |||||
const char* APP_NAME = "SDL2"; | |||||
const int SCREEN_WIDTH = 640; | |||||
const int SCREEN_HEIGHT = 480; | |||||
int main(int argc, char* args[]) { | |||||
SDL_Window* window = NULL; | |||||
SDL_Surface* screenSurface = NULL; | |||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) { | |||||
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError()); | |||||
return -1; | |||||
} | |||||
window = SDL_CreateWindow( | |||||
APP_NAME, | |||||
SDL_WINDOWPOS_UNDEFINED, | |||||
SDL_WINDOWPOS_UNDEFINED, | |||||
SCREEN_WIDTH, | |||||
SCREEN_HEIGHT, | |||||
SDL_WINDOW_SHOWN | |||||
); | |||||
if (window == NULL) { | |||||
printf("Window could not be created! SDL_Error: %s\n", SDL_GetError()); | |||||
return -2; | |||||
} | |||||
bool quit = false; | |||||
SDL_Event e; | |||||
screenSurface = SDL_GetWindowSurface(window); | |||||
while (!quit) { | |||||
while (SDL_PollEvent(&e) != 0) { | |||||
if (e.type == SDL_QUIT) { | |||||
quit = true; | |||||
} | |||||
SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF)); | |||||
SDL_UpdateWindowSurface(window); | |||||
} | |||||
} | |||||
SDL_DestroyWindow(window); | |||||
SDL_Quit(); | |||||
return 0; | |||||
} |
@@ -0,0 +1 @@ | |||||
#include "IZ_math.h" |
@@ -0,0 +1,10 @@ | |||||
#ifndef IZ_MATH_H | |||||
#define IZ_MATH_H | |||||
#include <math.h> | |||||
typedef float IZ_Real; | |||||
inline IZ_Real IZ_Sqrt(IZ_Real x) { return (IZ_Real) sqrtf(x); } | |||||
#endif //IZ_MATH_H |
@@ -0,0 +1 @@ | |||||
#include "IZ_vector.h" |
@@ -0,0 +1,52 @@ | |||||
#ifndef IZ_VECTOR_H | |||||
#define IZ_VECTOR_H | |||||
#include "IZ_math.h" | |||||
typedef struct { | |||||
// positive X is rightwards | |||||
IZ_Real x; | |||||
// positive Y is downwards | |||||
IZ_Real y; | |||||
} IZ_Vector; | |||||
inline IZ_Vector IZ_VectorAdd(IZ_Vector a, IZ_Vector b) { | |||||
return (IZ_Vector) { | |||||
.x = a.x + b.x, | |||||
.y = a.y + b.y, | |||||
}; | |||||
} | |||||
inline IZ_Vector IZ_VectorSubtract(IZ_Vector a, IZ_Vector b) { | |||||
return (IZ_Vector) { | |||||
.x = a.x - b.x, | |||||
.y = a.y - b.y, | |||||
}; | |||||
} | |||||
inline IZ_Vector IZ_VectorMultiply(IZ_Vector a, IZ_Real b) { | |||||
return (IZ_Vector) { | |||||
.x = a.x * b, | |||||
.y = a.y * b, | |||||
}; | |||||
} | |||||
inline IZ_Vector IZ_VectorDivide(IZ_Vector a, IZ_Real b) { | |||||
return (IZ_Vector) { | |||||
.x = a.x / b, | |||||
.y = a.y / b, | |||||
}; | |||||
} | |||||
inline IZ_Real IZ_VectorDot(IZ_Vector a, IZ_Vector b) { | |||||
return a.x * b.x + a.y * b.y; | |||||
} | |||||
inline IZ_Real IZ_VectorDistance(IZ_Vector a, IZ_Vector b) { | |||||
IZ_Real x = b.x - a.x; | |||||
IZ_Real y = b.y - a.y; | |||||
return IZ_Sqrt(x * x + y * y); | |||||
} | |||||
#endif //IZ_VECTOR_H |