Fix conan script and deadlock in main()
This commit is contained in:
parent
65d8d93ce4
commit
93547835c5
2
.gitignore
vendored
2
.gitignore
vendored
@ -69,6 +69,7 @@ install_manifest.txt
|
||||
compile_commands.json
|
||||
_deps
|
||||
|
||||
logs/
|
||||
.project
|
||||
.vscode/
|
||||
|
||||
@ -78,3 +79,4 @@ conan.lock
|
||||
conanbuildinfo.txt
|
||||
conaninfo.txt
|
||||
graph_info.json
|
||||
CMakeUserPresets.json
|
||||
|
@ -35,7 +35,7 @@ SOURCE_GROUP("Header Files" FILES ${AST_HRDS})
|
||||
#set(CMAKE_BUILD_TYPE Debug)
|
||||
#include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_executable(AST ${AST_SCRS} ${AST_HRDS})
|
||||
#set_property(TARGET AST PROPERTY C_STANDARD 99)
|
||||
set_property(TARGET AST PROPERTY C_STANDARD 90)
|
||||
set_target_properties(AST PROPERTIES OUTPUT_NAME ${AST_NAME})
|
||||
if(MSVC)
|
||||
# msvc does not append 'lib' - do it here to have consistent name
|
||||
|
30
README.md
30
README.md
@ -1,38 +1,40 @@
|
||||
# Arena Survival Tournament
|
||||
|
||||
This is one of my first game prototype.
|
||||
It's fully coded in C with SDL2 and SDL2_image libs.
|
||||
All SDL2 parts and sub-parts are under the same license as SDL2 lib.
|
||||
It's completely coded in C and use SDL2 and SDL2_image libs for the graphical backend.
|
||||
All SDL2 parts and sub-parts are under the zlib license.
|
||||
All code of AST are covered by the MIT license.
|
||||
|
||||
## Functions
|
||||
|
||||
The game can do following and you can learn from that like we do when you created this code:
|
||||
- Generate random maps level
|
||||
- Control a simple IA
|
||||
- Manage gold resources
|
||||
- Players movements
|
||||
- Bad code practice
|
||||
Here is a non-exhaustive list of the elements implemented in this demo:
|
||||
- Random level generator,
|
||||
- Simple AI behavior,
|
||||
- Tiles management,
|
||||
- Players movements,
|
||||
- Bad code practices...
|
||||
|
||||
## Compiling
|
||||
|
||||
Before compiling, you need to install your favorite compiler (GCC or MSVC) with CMake and the lib manager Conan>=1.59 (https://conan.io):
|
||||
Before compiling, you need to install your favorite compiler (GCC or MSVC) with CMake.
|
||||
The library manager Conan>=1.59 (https://conan.io) is supported too for SDL2 easy-setup.
|
||||
|
||||
```shell
|
||||
# For debian based distribution:
|
||||
# For debian-based distribution:
|
||||
apt-get update
|
||||
apt-get install build-essential cmake conan
|
||||
apt-get install build-essential cmake
|
||||
python -m pip install -U conan
|
||||
```
|
||||
|
||||
Clone the repo and launch in order conan and cmake in order to compile the program:
|
||||
|
||||
```shell
|
||||
conan install . --build=missing -s build_type=Release -pr:b=default
|
||||
conan install . -of ./build --build=missing -s build_type=Release -pr:b=default #Conan v2
|
||||
conan install . -of ./build -if ./build --build=missing -s build_type=Release -pr:b=default #Conan v1
|
||||
cmake --preset release # or with '-G "MinGW Makefiles"/"Ninja"' if under Windows
|
||||
cmake --build --preset release
|
||||
cp -R data build/Release/.
|
||||
```
|
||||
|
||||
## Running
|
||||
|
||||
Simply run the program with `data` folder (required) and `logs` folder (optional) or use the launch script.
|
||||
Simply run the program with `data` folder (required) and `logs` folder (optional).
|
||||
|
23
conanfile.py
23
conanfile.py
@ -1,5 +1,5 @@
|
||||
from conan import ConanFile
|
||||
from conan.tools.cmake import CMakeToolchain, CMakeDeps, cmake_layout
|
||||
from conan.tools.cmake import CMakeToolchain
|
||||
from conan.tools.files import copy
|
||||
|
||||
required_conan_version = ">=1.59"
|
||||
@ -16,18 +16,16 @@ class AST(ConanFile):
|
||||
package_type = "application"
|
||||
revision_mode = "scm"
|
||||
settings = "os", "compiler", "build_type", "arch"
|
||||
generators = "CMakeToolchain", "CMakeDeps"
|
||||
generators = "CMakeDeps"
|
||||
|
||||
# default_options = {
|
||||
# "shared": True
|
||||
# }
|
||||
|
||||
def configure(self):
|
||||
self.options["sdl"].shared = True
|
||||
self.options["sdl"].vulkan = False
|
||||
self.options["sdl"].opengles = False
|
||||
self.options["sdl"].iconv = False
|
||||
self.options["sdl_image"].shared = True
|
||||
self.options["sdl_image"].with_libjpeg = False
|
||||
self.options["sdl_image"].with_libtiff = False
|
||||
self.options["sdl_image"].with_libwebp = False
|
||||
@ -41,20 +39,31 @@ class AST(ConanFile):
|
||||
self.options["sdl_image"].xv = False
|
||||
|
||||
if self.settings.os == "Linux":
|
||||
self.options["sdl"].shared = False
|
||||
self.options["sdl"].wayland = False
|
||||
self.options["sdl"].nas = True
|
||||
self.options["sdl_image"].shared = False
|
||||
|
||||
if self.settings.os == "Windows":
|
||||
self.options["sdl"].shared = True
|
||||
self.options["sdl"].directx = False
|
||||
self.options["sdl_image"].shared = True
|
||||
|
||||
def requirements(self):
|
||||
self.requires("sdl/2.28.5", override=True)
|
||||
self.requires("sdl/2.30.7", override=True)
|
||||
self.requires("sdl_image/[>=2.6.3 <2.7]")
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self, src_folder='.', build_folder='build')
|
||||
# def layout(self):
|
||||
# cmake_layout(self, src_folder='.', build_folder='build')
|
||||
|
||||
def generate(self):
|
||||
# cmake = CMakeDeps(self)
|
||||
# if self.options["AST"].shared:
|
||||
# cmake.configuration = "ReleaseShared"
|
||||
# cmake.generate()
|
||||
tc = CMakeToolchain(self)
|
||||
#tc.user_presets_path = False
|
||||
tc.generate()
|
||||
for dep in self.dependencies.values():
|
||||
if self.settings.os == "Windows":
|
||||
copy(self, "*.dll", dep.cpp_info.bindirs[0], self.build_folder)
|
||||
|
16
launch.sh
16
launch.sh
@ -1,16 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
DATA_DIR='data'
|
||||
LOGS_DIR='logs'
|
||||
|
||||
if [ ! -d "$DATA_DIR" ]; then
|
||||
echo "WARNING ! Missing DATA dir, can't launch program."
|
||||
echo "Exit..."
|
||||
fi
|
||||
|
||||
if [ ! -d "$LOGS_DIR" ]; then
|
||||
mkdir logs
|
||||
fi
|
||||
|
||||
chmod +x ArenaSurvivalTournament
|
||||
./ArenaSurvivalTournament
|
@ -47,30 +47,42 @@ int updateArena(SDL_Window* window, ARENA_H_TILE* arena, TILE *tiles, PLAYER *p_
|
||||
SDL_UpdateWindowSurface(window);
|
||||
|
||||
do {
|
||||
action=0;actionIA=0;
|
||||
oldposition.x = p1->PositionX * TILE_SIZE;
|
||||
oldposition.y = p1->PositionY * TILE_SIZE;
|
||||
oldIAposition.x = p2->PositionX * TILE_SIZE;
|
||||
oldIAposition.y = p2->PositionY * TILE_SIZE;
|
||||
|
||||
while(action == 0) {
|
||||
while(!action) {
|
||||
action=getKeyEvent();
|
||||
}
|
||||
|
||||
if(action == -1){
|
||||
return 0;
|
||||
} else if(action == 1) {
|
||||
switch (action)
|
||||
{
|
||||
case GAME_EVENT_UP:
|
||||
ActionPlayer(arena,tiles,p_list,p1,1); //Déplacement vers le haut
|
||||
} else if(action == 2) {
|
||||
ActionPlayer(arena,tiles,p_list,p1,2); //Déplacement vers la droite
|
||||
} else if(action == 3) {
|
||||
break;
|
||||
case GAME_EVENT_DOWN:
|
||||
ActionPlayer(arena,tiles,p_list,p1,3); //Déplacement vers le bas
|
||||
} else if(action == 4) {
|
||||
break;
|
||||
case GAME_EVENT_LEFT:
|
||||
ActionPlayer(arena,tiles,p_list,p1,4); //Déplacement vers la gauche
|
||||
} else if(action == 5) {
|
||||
break;
|
||||
case GAME_EVENT_RIGHT:
|
||||
ActionPlayer(arena,tiles,p_list,p1,2); //Déplacement vers la droite
|
||||
break;
|
||||
|
||||
case GAME_EVENT_ATTACK:
|
||||
//Regarder le perso en face, le plus près
|
||||
if (canAttackPlayer(p1,p2)==1) {
|
||||
AttackPlayer(p1,p2); //Voir quel player on choisit d'attaquer
|
||||
}
|
||||
break;
|
||||
|
||||
case GAME_EVENT_QUIT:
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// On place le joueur à la bonne position
|
||||
@ -108,8 +120,6 @@ int updateArena(SDL_Window* window, ARENA_H_TILE* arena, TILE *tiles, PLAYER *p_
|
||||
|
||||
SDL_UpdateWindowSurface(window);
|
||||
|
||||
action=0;actionIA=0;
|
||||
|
||||
} while((p1->HealthPoints > 0) && (NumberPlayerAlive(p_list) > 1));
|
||||
|
||||
printf("La partie est terminée\n");
|
||||
@ -133,27 +143,27 @@ int getKeyEvent()
|
||||
/* Si c'est un événement de type "Quitter" */
|
||||
case SDL_QUIT :
|
||||
printf("QUITTER\n");
|
||||
return -1;
|
||||
return GAME_EVENT_QUIT;
|
||||
case SDL_KEYUP:
|
||||
switch(event.key.keysym.sym) { //La valeur de touche
|
||||
case SDLK_ESCAPE:
|
||||
printf("ESCAPE KEY\n");
|
||||
return -1;
|
||||
return GAME_EVENT_QUIT;
|
||||
case SDLK_UP:
|
||||
printf("FLECHE DU HAUT\n");
|
||||
return 1;
|
||||
return GAME_EVENT_UP;
|
||||
case SDLK_DOWN:
|
||||
printf("FLECHE DU BAS\n");
|
||||
return 3;
|
||||
return GAME_EVENT_DOWN;
|
||||
case SDLK_RIGHT:
|
||||
printf("FLECHE DE DROITE\n");
|
||||
return 2;
|
||||
return GAME_EVENT_RIGHT;
|
||||
case SDLK_LEFT:
|
||||
printf("FLECHE DE GAUCHE\n");
|
||||
return 4;
|
||||
return GAME_EVENT_LEFT;
|
||||
case SDLK_SPACE:
|
||||
printf("BARRE D'ESPACE\n");
|
||||
return 5;
|
||||
return GAME_EVENT_ATTACK;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,15 @@
|
||||
#ifndef ARENAGUI_H_
|
||||
#define ARENAGUI_H_
|
||||
|
||||
enum {
|
||||
GAME_EVENT_QUIT = 1,
|
||||
GAME_EVENT_UP,
|
||||
GAME_EVENT_DOWN,
|
||||
GAME_EVENT_LEFT,
|
||||
GAME_EVENT_RIGHT,
|
||||
GAME_EVENT_ATTACK
|
||||
};
|
||||
|
||||
void displayArena(ARENA_H_TILE* arena, SDL_Window* windows, TILE *tiles, int size_h, int size_w, int tile_size);
|
||||
int updateArena(SDL_Window* window, ARENA_H_TILE* arena, TILE *tiles, PLAYER *player);
|
||||
int getKeyEvent();
|
||||
|
@ -63,7 +63,7 @@ int main(int argc, char *argv[]) {
|
||||
//IMG_Init(IMG_INIT_JPG & IMG_INIT_PNG);
|
||||
displayArena(arena, gameWindows, tile_ressources, A_HEIGHT, A_WIDTH, TILE_SIZE);
|
||||
|
||||
while (!updateArena(gameWindows,arena,tile_ressources,player_ressources)) {}
|
||||
while (updateArena(gameWindows,arena,tile_ressources,player_ressources)) {}
|
||||
SDL_DestroyWindow(gameWindows);
|
||||
|
||||
deleteArena(arena);
|
||||
|
Loading…
x
Reference in New Issue
Block a user