From 9cef1b2b852f0e35a0f46ec54b25852bd79bf4a5 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 22 Mar 2026 12:48:48 +0000 Subject: [PATCH] Refactor directory structure to domain-driven architecture Organized all source files and headers into logically grouped subdirectories: - `Characters/` (Player, Enemy, Character) - `Core/` (Game, Extern, main) - `Scene/` (Start, Home, DungeonMenu, Dungeon, Congratulations, GameOver) - `System/` (AStar, LTexture) - `GenerateDungeon/` (Generator, AreaDivide, RRA, Tile, Enum, Const) - `UI/` (Log, Button) - `Utils/` (Util, Color, RectUtils, Texture, Ivec2) Updated all `#include` paths throughout the codebase, refactored the Makefile to compile from these new directories and resolved various relative path issues. Co-authored-by: unchunks <117646402+unchunks@users.noreply.github.com> --- Makefile | 341 ++++---- src/{ => Characters}/Character.cpp | 824 +++++++++--------- .../Character.h | 234 ++--- src/{ => Characters}/Enemy.cpp | 564 ++++++------ src/{GenerateDungeon => Characters}/Enemy.h | 98 +-- src/{ => Characters}/Player.cpp | 60 +- src/{GenerateDungeon => Characters}/Player.h | 30 +- src/{ => Core}/Extern.cpp | 0 src/{ => Core}/Game.cpp | 640 +++++++------- src/{ => Core}/Game.h | 92 +- src/{ => Core}/main.cpp | 28 +- src/{ => GenerateDungeon}/AreaDivide.cpp | 0 src/GenerateDungeon/AreaDivide.h | 26 +- src/{ => GenerateDungeon}/Generator.cpp | 2 +- src/GenerateDungeon/Generator.h | 98 +-- src/{ => GenerateDungeon}/RRA.cpp | 0 src/GenerateDungeon/RRA.h | 18 +- src/GenerateDungeon/Room.h | 70 +- src/{ => GenerateDungeon}/Tile.cpp | 0 src/GenerateDungeon/Tile.h | 8 +- src/{ => Scene}/1_Start.cpp | 0 src/Scene/1_Start.h | 56 +- src/{ => Scene}/2_Home.cpp | 0 src/Scene/2_Home.h | 12 +- src/{ => Scene}/3_DungeonMenu.cpp | 0 src/Scene/3_DungeonMenu.h | 62 +- src/{ => Scene}/4_Dungeon.cpp | 0 src/Scene/4_Dungeon.h | 201 +++-- src/{ => Scene}/5_Congratulations.cpp | 0 src/Scene/5_Congratulations.h | 10 +- src/{ => Scene}/6_GameOver.cpp | 0 src/Scene/6_GameOver.h | 10 +- src/{ => System}/AStar.cpp | 2 +- src/{GenerateDungeon => System}/AStar.h | 62 +- src/{ => System}/LTexture.cpp | 338 +++---- src/{GenerateDungeon => System}/LTexture.h | 2 +- src/UI/Button.h | 186 ++-- src/{ => UI}/Log.cpp | 0 src/UI/Log.h | 4 +- src/{Functions => Utils}/Color.h | 0 Ivec2.h => src/Utils/Ivec2.h | 0 src/{Functions => Utils}/RectUtils.h | 0 src/{Functions => Utils}/Texture.h | 2 +- src/{Functions => Utils}/Util.h | 5 +- test.cpp | 2 +- tests/test_AinB.cpp | 2 +- 46 files changed, 2040 insertions(+), 2049 deletions(-) rename src/{ => Characters}/Character.cpp (93%) rename src/{GenerateDungeon => Characters}/Character.h (91%) rename src/{ => Characters}/Enemy.cpp (95%) rename src/{GenerateDungeon => Characters}/Enemy.h (89%) rename src/{ => Characters}/Player.cpp (88%) rename src/{GenerateDungeon => Characters}/Player.h (83%) rename src/{ => Core}/Extern.cpp (100%) rename src/{ => Core}/Game.cpp (90%) rename src/{ => Core}/Game.h (87%) rename src/{ => Core}/main.cpp (85%) rename src/{ => GenerateDungeon}/AreaDivide.cpp (100%) rename src/{ => GenerateDungeon}/Generator.cpp (99%) rename src/{ => GenerateDungeon}/RRA.cpp (100%) rename src/{ => GenerateDungeon}/Tile.cpp (100%) rename src/{ => Scene}/1_Start.cpp (100%) rename src/{ => Scene}/2_Home.cpp (100%) rename src/{ => Scene}/3_DungeonMenu.cpp (100%) rename src/{ => Scene}/4_Dungeon.cpp (100%) rename src/{ => Scene}/5_Congratulations.cpp (100%) rename src/{ => Scene}/6_GameOver.cpp (100%) rename src/{ => System}/AStar.cpp (99%) rename src/{GenerateDungeon => System}/AStar.h (86%) rename src/{ => System}/LTexture.cpp (94%) rename src/{GenerateDungeon => System}/LTexture.h (93%) rename src/{ => UI}/Log.cpp (100%) rename src/{Functions => Utils}/Color.h (100%) rename Ivec2.h => src/Utils/Ivec2.h (100%) rename src/{Functions => Utils}/RectUtils.h (100%) rename src/{Functions => Utils}/Texture.h (91%) rename src/{Functions => Utils}/Util.h (78%) diff --git a/Makefile b/Makefile index 59a7536..aa4db22 100644 --- a/Makefile +++ b/Makefile @@ -1,175 +1,166 @@ -#OBSRC specifies which files to compile as part of the project -OBSRC = src/*.cpp - -OBJO = 1_Start.o 2_Home.o 3_DungeonMenu.o 4_Dungeon.o 5_Congratulations.o 6_GameOver.o AreaDivide.o AStar.o Character.o Enemy.o Extern.o Game.o Generator.o Log.o LTexture.o main.o Player.o RRA.o Tile.o - -#CC specifies which compiler we're using -CC = g++ - -#COMPILER_FLAGS specifies the additional compilation options we're using -# -w suppresses all warnings -COMPILER_FLAGS = -Wall - -COMPILE_OPTIONS = `sdl2-config --cflags --libs` - -#LINKER_FLAGS specifies the libraries we're linking against -LINKER_FLAGS = -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer - -#OBJ_NAME specifies the name of our exectuable -OBJ_NAME = rogue - -#This is the target that compiles our executable -link : $(OBJO) - $(CC) $(OBJO) -o $(OBJ_NAME) $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) - -compile : $(OBJO) - -reset : $(OBJO) - make clean - make link - -do : $(OBJO) - make link - ./$(OBJ_NAME) - -release : $(OBSRC) - $(CC) $(OBSRC) $(COMPILER_FLAGS) -O3 -s $(COMPILE_OPTIONS) $(LINKER_FLAGS) -o $(OBJ_NAME) - -.PHONY : clean -clean : $(OBJO) - rm $(OBJO) - rm -f tests/test_run - -valgrind : $(OBSRC) -#$(CC) $(OBSRC) $(COMPILER_FLAGS) -g $(COMPILE_OPTIONS) $(LINKER_FLAGS) -o $(OBJ_NAME) - valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all -s ./$(OBJ_NAME) - -debug : $(OBSRC) - $(CC) $(OBSRC) -g $(COMPILE_OPTIONS) $(LINKER_FLAGS) -o $(OBJ_NAME) - -appimage : - make release - - # AppDirを削除して再作成 - rm -rf AppDir - mkdir -p AppDir/usr/bin - mkdir -p AppDir/usr/lib - mkdir -p AppDir/usr/share/rogue - - # バイナリをコピー - cp ./rogue AppDir/usr/bin/ - - # アセットをコピー - cp -r ./assets AppDir/usr/share/rogue/ - - # 必要なライブラリを自動収集 - echo "Collecting dependencies..." - ldd ./rogue | awk '/=>/ {print $3}' | grep -v '^$' | while read lib; do - if [[ $lib == /usr/lib/* ]] || [[ $lib == /lib/* ]]; then - echo "Copying $lib" - cp "$lib" AppDir/usr/lib/ 2>/dev/null || true - fi - done - - # SDL2関連ライブラリを明示的にコピー - for lib in /usr/lib/x86_64-linux-gnu/libSDL2*.so*; do - if [ -f "$lib" ]; then - echo "Copying SDL2 library: $lib" - cp "$lib" AppDir/usr/lib/ - fi - done - - # .desktopファイルを作成 - cat > AppDir/rogue.desktop << EOF - [Desktop Entry] - Type=Application - Name=Rogue - Exec=rogue - Icon=rogue - Categories=Game; - EOF - - # AppRunスクリプトを作成 - cat > AppDir/AppRun << 'EOF' - #!/bin/bash - HERE="$(dirname "$(readlink -f "${0}")")" - export LD_LIBRARY_PATH="${HERE}/usr/lib:${HERE}/usr/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}" - export PATH="${HERE}/usr/bin:${PATH}" - exec "${HERE}/usr/bin/rogue" "$@" - EOF - - chmod +x AppDir/AppRun - - # シンボリックリンクを作成 - ln -sf rogue.desktop AppDir/ - ln -sf usr/share/icons/hicolor/256x256/apps/rogue.png AppDir/ 2>/dev/null || touch AppDir/rogue.png - - echo "AppDir created successfully!" - echo "Now run: appimagetool AppDir" - - ./appimage-builder-x86_64.AppImage --recipe AppImageBuilder.yml - -# gdbの手順 -# gdb ./$(BOJS) -# run -# bt - -test : tests/test_AinB.cpp src/Functions/RectUtils.h - $(CC) $(COMPILER_FLAGS) -I./tests/include -I./src tests/test_AinB.cpp -o tests/test_run - ./tests/test_run - -commit-% : - git add -A - git commit -m "${@:commit-%=%}" - -push-% : - git add -A - git commit -m "${@:push-%=%}" - git push - -wc: src/* src/*/* - wc src/* src/*/* -m -l - -play: $(OBSRC) - sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsdl2-mixer-dev -y - make release - ./$(OBJ_NAME) - -1_Start.o : src/1_Start.cpp src/Scene/1_Start.h src/UI/Button.h src/Functions/Color.h src/GenerateDungeon/Const.h src/Game.h - g++ src/1_Start.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -2_Home.o : src/2_Home.cpp src/Scene/2_Home.h src/UI/Button.h src/Functions/Color.h src/Functions/Util.h src/GenerateDungeon/Const.h src/GenerateDungeon/LTexture.h src/Game.h - g++ src/2_Home.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -3_DungeonMenu.o : src/3_DungeonMenu.cpp src/Scene/3_DungeonMenu.h src/UI/Button.h src/Functions/Color.h src/GenerateDungeon/Const.h src/Game.h - g++ src/3_DungeonMenu.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -4_Dungeon.o : src/4_Dungeon.cpp src/Scene/4_Dungeon.h src/UI/Log.h src/Functions/Color.h src/Functions/Util.h src/GenerateDungeon/Const.h src/GenerateDungeon/AreaDivide.h src/GenerateDungeon/RRA.h src/GenerateDungeon/Player.h src/GenerateDungeon/Enemy.h src/GenerateDungeon/Const.h src/GenerateDungeon/Tile.h src/GenerateDungeon/LTexture.h src/Game.h - g++ src/4_Dungeon.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -5_Congratulations.o : src/5_Congratulations.cpp src/Scene/5_Congratulations.h src/UI/Button.h src/Functions/Color.h src/GenerateDungeon/Const.h src/Game.h - g++ src/5_Congratulations.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -6_GameOver.o : src/6_GameOver.cpp src/Scene/6_GameOver.h src/UI/Button.h src/Functions/Color.h src/GenerateDungeon/Const.h src/Game.h - g++ src/6_GameOver.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -AreaDivide.o : src/AreaDivide.cpp src/GenerateDungeon/AreaDivide.h src/GenerateDungeon/Generator.h - g++ src/AreaDivide.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -AStar.o : src/AStar.cpp src/GenerateDungeon/AStar.h src/GenerateDungeon/Const.h src/GenerateDungeon/Enum.h Ivec2.h - g++ src/AStar.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -Character.o : src/Character.cpp src/GenerateDungeon/Character.h src/GenerateDungeon/Const.h src/GenerateDungeon/Enum.h src/GenerateDungeon/Tile.h Ivec2.h - g++ src/Character.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -Enemy.o : src/Enemy.cpp src/GenerateDungeon/Enemy.h src/GenerateDungeon/AStar.h src/GenerateDungeon/Character.h src/GenerateDungeon/Const.h src/GenerateDungeon/Enum.h src/GenerateDungeon/Tile.h Ivec2.h - g++ src/Enemy.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -Extern.o : src/Extern.cpp - g++ src/Extern.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -Game.o : src/Game.cpp src/Game.h src/Scene/1_Start.h src/Scene/2_Home.h src/Scene/3_DungeonMenu.h src/Scene/4_Dungeon.h src/Scene/5_Congratulations.h src/GenerateDungeon/Const.h src/Functions/Util.h - g++ src/Game.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -Generator.o : src/Generator.cpp src/GenerateDungeon/Generator.h src/GenerateDungeon/Area.h src/GenerateDungeon/Room.h src/GenerateDungeon/Player.h src/GenerateDungeon/Enemy.h src/GenerateDungeon/Enum.h src/GenerateDungeon/Const.h Ivec2.h - g++ src/Generator.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -Log.o : src/Log.cpp src/UI/Log.h src/GenerateDungeon/Const.h src/Functions/Util.h - g++ src/Log.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -LTexture.o : src/LTexture.cpp src/GenerateDungeon/LTexture.h src/GenerateDungeon/Const.h src/GenerateDungeon/Enum.h Ivec2.h - g++ src/LTexture.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -main.o : src/main.cpp - g++ src/main.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -Player.o : src/Player.cpp src/GenerateDungeon/Player.h src/GenerateDungeon/Character.h - g++ src/Player.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -RRA.o : src/RRA.cpp src/GenerateDungeon/RRA.h src/GenerateDungeon/Generator.h - g++ src/RRA.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) -Tile.o : src/Tile.cpp src/GenerateDungeon/Tile.h src/GenerateDungeon/Enum.h src/GenerateDungeon/Const.h src/GenerateDungeon/LTexture.h - g++ src/Tile.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +#OBSRC specifies which files to compile as part of the project +OBSRC = src/*/*.cpp + +OBJO = 1_Start.o 2_Home.o 3_DungeonMenu.o 4_Dungeon.o 5_Congratulations.o 6_GameOver.o AreaDivide.o AStar.o Character.o Enemy.o Extern.o Game.o Generator.o Log.o LTexture.o main.o Player.o RRA.o Tile.o + +#CC specifies which compiler we're using +CC = g++ + +#COMPILER_FLAGS specifies the additional compilation options we're using +# -w suppresses all warnings +COMPILER_FLAGS = -Wall -I./src + +COMPILE_OPTIONS = `sdl2-config --cflags --libs` + +#LINKER_FLAGS specifies the libraries we're linking against +LINKER_FLAGS = -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer + +#OBJ_NAME specifies the name of our exectuable +OBJ_NAME = rogue + +#This is the target that compiles our executable +link : $(OBJO) + $(CC) $(OBJO) -o $(OBJ_NAME) $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) + +compile : $(OBJO) + +reset : $(OBJO) + make clean + make link + +do : $(OBJO) + make link + ./$(OBJ_NAME) + +release : $(OBSRC) + $(CC) $(OBSRC) $(COMPILER_FLAGS) -O3 -s $(COMPILE_OPTIONS) $(LINKER_FLAGS) -o $(OBJ_NAME) + +.PHONY : clean +clean : $(OBJO) + rm -f $(OBJO) + rm -f tests/test_run + +valgrind : $(OBSRC) +#$(CC) $(OBSRC) $(COMPILER_FLAGS) -g $(COMPILE_OPTIONS) $(LINKER_FLAGS) -o $(OBJ_NAME) + valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all -s ./$(OBJ_NAME) + +debug : $(OBSRC) + $(CC) $(OBSRC) -g $(COMPILE_OPTIONS) $(LINKER_FLAGS) -o $(OBJ_NAME) + +appimage : + make release + + # AppDirを削除して再作成 + rm -rf AppDir + mkdir -p AppDir/usr/bin + mkdir -p AppDir/usr/lib + mkdir -p AppDir/usr/share/rogue + + # バイナリをコピー + cp ./rogue AppDir/usr/bin/ + + # アセットをコピー + cp -r ./assets AppDir/usr/share/rogue/ + + # 必要なライブラリを自動収集 + echo "Collecting dependencies..." + ldd ./rogue | awk '/=>/ {print $$3}' | grep -v '^$$' | while read lib; do \ + if [[ $$lib == /usr/lib/* ]] || [[ $$lib == /lib/* ]]; then \ + echo "Copying $$lib"; \ + cp "$$lib" AppDir/usr/lib/ 2>/dev/null || true; \ + fi \ + done + + # SDL2関連ライブラリを明示的にコピー + for lib in /usr/lib/x86_64-linux-gnu/libSDL2*.so*; do \ + if [ -f "$$lib" ]; then \ + echo "Copying SDL2 library: $$lib"; \ + cp "$$lib" AppDir/usr/lib/; \ + fi \ + done + + # .desktopファイルを作成 + cat > AppDir/rogue.desktop << EOL + [Desktop Entry] + Type=Application + Name=Rogue + Exec=rogue + Icon=rogue + Categories=Game; + EOL + + # AppRunスクリプトを作成 + cat > AppDir/AppRun << 'EOL' + #!/bin/bash + HERE="$$(dirname "$$(readlink -f "$${0}")")" + export LD_LIBRARY_PATH="$${HERE}/usr/lib:$${HERE}/usr/lib/x86_64-linux-gnu:$${LD_LIBRARY_PATH}" + export PATH="$${HERE}/usr/bin:$${PATH}" + exec "$${HERE}/usr/bin/rogue" "$$@" + EOL + + chmod +x AppDir/AppRun + + # シンボリックリンクを作成 + ln -sf rogue.desktop AppDir/ + ln -sf usr/share/icons/hicolor/256x256/apps/rogue.png AppDir/ 2>/dev/null || touch AppDir/rogue.png + + echo "AppDir created successfully!" + echo "Now run: appimagetool AppDir" + + ./appimage-builder-x86_64.AppImage --recipe AppImageBuilder.yml + +# gdbの手順 +# gdb ./$(BOJS) +# run +# bt + +test : tests/test_AinB.cpp src/Utils/RectUtils.h + $(CC) $(COMPILER_FLAGS) -I./tests/include -I./src tests/test_AinB.cpp -o tests/test_run + ./tests/test_run + +wc: src/* src/*/* + wc src/* src/*/* -m -l + +play: $(OBSRC) + sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsdl2-mixer-dev -y + make release + ./$(OBJ_NAME) + +1_Start.o : src/Scene/1_Start.cpp src/Scene/1_Start.h src/UI/Button.h src/Utils/Color.h src/GenerateDungeon/Const.h src/Core/Game.h + g++ src/Scene/1_Start.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +2_Home.o : src/Scene/2_Home.cpp src/Scene/2_Home.h src/UI/Button.h src/Utils/Color.h src/Utils/Util.h src/GenerateDungeon/Const.h src/System/LTexture.h src/Core/Game.h + g++ src/Scene/2_Home.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +3_DungeonMenu.o : src/Scene/3_DungeonMenu.cpp src/Scene/3_DungeonMenu.h src/UI/Button.h src/Utils/Color.h src/GenerateDungeon/Const.h src/Core/Game.h + g++ src/Scene/3_DungeonMenu.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +4_Dungeon.o : src/Scene/4_Dungeon.cpp src/Scene/4_Dungeon.h src/UI/Log.h src/Utils/Color.h src/Utils/Util.h src/GenerateDungeon/Const.h src/GenerateDungeon/AreaDivide.h src/GenerateDungeon/RRA.h src/Characters/Player.h src/Characters/Enemy.h src/GenerateDungeon/Const.h src/GenerateDungeon/Tile.h src/System/LTexture.h src/Core/Game.h + g++ src/Scene/4_Dungeon.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +5_Congratulations.o : src/Scene/5_Congratulations.cpp src/Scene/5_Congratulations.h src/UI/Button.h src/Utils/Color.h src/GenerateDungeon/Const.h src/Core/Game.h + g++ src/Scene/5_Congratulations.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +6_GameOver.o : src/Scene/6_GameOver.cpp src/Scene/6_GameOver.h src/UI/Button.h src/Utils/Color.h src/GenerateDungeon/Const.h src/Core/Game.h + g++ src/Scene/6_GameOver.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +AreaDivide.o : src/GenerateDungeon/AreaDivide.cpp src/GenerateDungeon/AreaDivide.h src/GenerateDungeon/Generator.h + g++ src/GenerateDungeon/AreaDivide.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +AStar.o : src/System/AStar.cpp src/System/AStar.h src/GenerateDungeon/Const.h src/GenerateDungeon/Enum.h src/Utils/Ivec2.h + g++ src/System/AStar.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +Character.o : src/Characters/Character.cpp src/Characters/Character.h src/GenerateDungeon/Const.h src/GenerateDungeon/Enum.h src/GenerateDungeon/Tile.h src/Utils/Ivec2.h + g++ src/Characters/Character.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +Enemy.o : src/Characters/Enemy.cpp src/Characters/Enemy.h src/System/AStar.h src/Characters/Character.h src/GenerateDungeon/Const.h src/GenerateDungeon/Enum.h src/GenerateDungeon/Tile.h src/Utils/Ivec2.h + g++ src/Characters/Enemy.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +Extern.o : src/Core/Extern.cpp + g++ src/Core/Extern.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +Game.o : src/Core/Game.cpp src/Core/Game.h src/Scene/1_Start.h src/Scene/2_Home.h src/Scene/3_DungeonMenu.h src/Scene/4_Dungeon.h src/Scene/5_Congratulations.h src/GenerateDungeon/Const.h src/Utils/Util.h + g++ src/Core/Game.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +Generator.o : src/GenerateDungeon/Generator.cpp src/GenerateDungeon/Generator.h src/GenerateDungeon/Area.h src/GenerateDungeon/Room.h src/Characters/Player.h src/Characters/Enemy.h src/GenerateDungeon/Enum.h src/GenerateDungeon/Const.h src/Utils/Ivec2.h + g++ src/GenerateDungeon/Generator.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +Log.o : src/UI/Log.cpp src/UI/Log.h src/GenerateDungeon/Const.h src/Utils/Util.h + g++ src/UI/Log.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +LTexture.o : src/System/LTexture.cpp src/System/LTexture.h src/GenerateDungeon/Const.h src/GenerateDungeon/Enum.h src/Utils/Ivec2.h + g++ src/System/LTexture.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +main.o : src/Core/main.cpp + g++ src/Core/main.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +Player.o : src/Characters/Player.cpp src/Characters/Player.h src/Characters/Character.h + g++ src/Characters/Player.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +RRA.o : src/GenerateDungeon/RRA.cpp src/GenerateDungeon/RRA.h src/GenerateDungeon/Generator.h + g++ src/GenerateDungeon/RRA.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) +Tile.o : src/GenerateDungeon/Tile.cpp src/GenerateDungeon/Tile.h src/GenerateDungeon/Enum.h src/GenerateDungeon/Const.h src/System/LTexture.h + g++ src/GenerateDungeon/Tile.cpp -c $(COMPILER_FLAGS) $(COMPILE_OPTIONS) $(LINKER_FLAGS) diff --git a/src/Character.cpp b/src/Characters/Character.cpp similarity index 93% rename from src/Character.cpp rename to src/Characters/Character.cpp index 115d4ec..bb0e74b 100644 --- a/src/Character.cpp +++ b/src/Characters/Character.cpp @@ -1,420 +1,420 @@ -#include "GenerateDungeon/Character.h" - -extern SDL_Renderer *gRenderer; - -LTexture Character::mCharTexture = LTexture(); - -Character::Character() - : mAnimFrame(0), receivingDamage(false), mName("キャラクター") -{ - sprile_clips.resize(ANIMATION_FRAMES * static_cast(NO_DIRECTION), {0, 0, 0, 0}); -} - -Character::Character(int _x, int _y, int _maxHP, int _STR, int _VIT, STATE _state, DIRECTION _dir, CHAR_TYPE _type, std::string _name) - : isMoved(false), nowHP(_maxHP), maxHP(_maxHP), STR(_STR), VIT(_VIT), mState(_state), mDir(_dir), mType(_type) - , mBox({TILE_W * 2, TILE_H * 2, SPRITE_CHAR_WIDTH, SPRITE_CHAR_HEIGHT}) - , mAnimFrame(0), receivingDamage(false), mName(_name) -{ -} - -Character::~Character() -{ - sprile_clips.clear(); - sprile_clips.shrink_to_fit(); -} - -bool Character::move(std::vector _tiles, const std::vector& _otherCharacters) -{ - Ivec2 front = getDataPos(); - switch (mDir) - { - case LEFT: front.x--; break; - case RIGHT: front.x++; break; - case UP: front.y--; break; - case DOWN: front.y++; break; - default: break; - } - if(onTileCenter() && collided(_tiles, front, _otherCharacters)) - { - - // SDL_Log("移動先に障害物あり"); - - return true; - } - - // SDL_Log("移動先に障害物無し"); - - // 次のマス目につくまで前フレームの移動を継続 - switch (mDir) - { - case LEFT: - - // if(onTileCenter()) - // SDL_Log("move: 左に移動"); - - mBox.x -= CHAR_VEL; - if(mBox.y % TILE_H != TILE_H / 4) - { - - // SDL_Log("上下位置調整"); - - mBox.y += (TILE_H / 4) - (mBox.y % TILE_H); - } - break; - case RIGHT: - - // if(onTileCenter()) - // SDL_Log("move: 右に移動"); - - mBox.x += CHAR_VEL; - if(mBox.y % TILE_H != TILE_H / 4) - { - - // SDL_Log("上下位置調整"); - - mBox.y += (TILE_H / 4) - (mBox.y % TILE_H); - } - break; - case UP: - - // if(onTileCenter()) - // SDL_Log("move: 上に移動"); - - mBox.y -= CHAR_VEL; - if(mBox.x % TILE_W != TILE_W / 4) - { - - // SDL_Log("左右位置調整"); - - mBox.x += (TILE_W / 4) - (mBox.x % TILE_W); - } - break; - case DOWN: - - // if(onTileCenter()) - // SDL_Log("move: 下に移動"); - - mBox.y += CHAR_VEL; - if(mBox.x % TILE_W != TILE_W / 4) - { - - // SDL_Log("左右位置調整"); - - mBox.x += (TILE_W / 4) - (mBox.x % TILE_W); - } - break; - case NO_DIRECTION: - break; - } - return false; -} - -bool Character::moveTo(Ivec2 _destination, std::vector _tiles, const std::vector& _otherCharacters) -{ - if(_destination.x < getDataPos().x) - { - mDir = LEFT; - } - else if(_destination.x > getDataPos().x) - { - mDir = RIGHT; - } - else if(_destination.y < getDataPos().y) - { - mDir = UP; - } - else if(_destination.y > getDataPos().y) - { - mDir = DOWN; - } - else if(onTileCenter()) - { - return false; - } - - // SDL_Log("moveTo: 行き先(%d, %d)、現在地(%d, %d)", _destination.x, _destination.y, getDataPos().x, getDataPos().y); - - return move(_tiles, _otherCharacters); -} - +#include "Characters/Character.h" + +extern SDL_Renderer *gRenderer; + +LTexture Character::mCharTexture = LTexture(); + +Character::Character() + : mAnimFrame(0), receivingDamage(false), mName("キャラクター") +{ + sprile_clips.resize(ANIMATION_FRAMES * static_cast(NO_DIRECTION), {0, 0, 0, 0}); +} + +Character::Character(int _x, int _y, int _maxHP, int _STR, int _VIT, STATE _state, DIRECTION _dir, CHAR_TYPE _type, std::string _name) + : isMoved(false), nowHP(_maxHP), maxHP(_maxHP), STR(_STR), VIT(_VIT), mState(_state), mDir(_dir), mType(_type) + , mBox({TILE_W * 2, TILE_H * 2, SPRITE_CHAR_WIDTH, SPRITE_CHAR_HEIGHT}) + , mAnimFrame(0), receivingDamage(false), mName(_name) +{ +} + +Character::~Character() +{ + sprile_clips.clear(); + sprile_clips.shrink_to_fit(); +} + +bool Character::move(std::vector _tiles, const std::vector& _otherCharacters) +{ + Ivec2 front = getDataPos(); + switch (mDir) + { + case LEFT: front.x--; break; + case RIGHT: front.x++; break; + case UP: front.y--; break; + case DOWN: front.y++; break; + default: break; + } + if(onTileCenter() && collided(_tiles, front, _otherCharacters)) + { + + // SDL_Log("移動先に障害物あり"); + + return true; + } + + // SDL_Log("移動先に障害物無し"); + + // 次のマス目につくまで前フレームの移動を継続 + switch (mDir) + { + case LEFT: + + // if(onTileCenter()) + // SDL_Log("move: 左に移動"); + + mBox.x -= CHAR_VEL; + if(mBox.y % TILE_H != TILE_H / 4) + { + + // SDL_Log("上下位置調整"); + + mBox.y += (TILE_H / 4) - (mBox.y % TILE_H); + } + break; + case RIGHT: + + // if(onTileCenter()) + // SDL_Log("move: 右に移動"); + + mBox.x += CHAR_VEL; + if(mBox.y % TILE_H != TILE_H / 4) + { + + // SDL_Log("上下位置調整"); + + mBox.y += (TILE_H / 4) - (mBox.y % TILE_H); + } + break; + case UP: + + // if(onTileCenter()) + // SDL_Log("move: 上に移動"); + + mBox.y -= CHAR_VEL; + if(mBox.x % TILE_W != TILE_W / 4) + { + + // SDL_Log("左右位置調整"); + + mBox.x += (TILE_W / 4) - (mBox.x % TILE_W); + } + break; + case DOWN: + + // if(onTileCenter()) + // SDL_Log("move: 下に移動"); + + mBox.y += CHAR_VEL; + if(mBox.x % TILE_W != TILE_W / 4) + { + + // SDL_Log("左右位置調整"); + + mBox.x += (TILE_W / 4) - (mBox.x % TILE_W); + } + break; + case NO_DIRECTION: + break; + } + return false; +} + +bool Character::moveTo(Ivec2 _destination, std::vector _tiles, const std::vector& _otherCharacters) +{ + if(_destination.x < getDataPos().x) + { + mDir = LEFT; + } + else if(_destination.x > getDataPos().x) + { + mDir = RIGHT; + } + else if(_destination.y < getDataPos().y) + { + mDir = UP; + } + else if(_destination.y > getDataPos().y) + { + mDir = DOWN; + } + else if(onTileCenter()) + { + return false; + } + + // SDL_Log("moveTo: 行き先(%d, %d)、現在地(%d, %d)", _destination.x, _destination.y, getDataPos().x, getDataPos().y); + + return move(_tiles, _otherCharacters); +} + DIRECTION Character::adjacent(const Character& _opponent) -{ - if(!onTileCenter()) - return NO_DIRECTION; - - if( (mBox.x == _opponent.mBox.x) && (mBox.y - TILE_H == _opponent.mBox.y) ) - { - mDir = UP; - - // SDL_Log("adjacent: キャラに隣接(上)"); - - return mDir; - } - - if( (mBox.x == _opponent.mBox.x) && (mBox.y + TILE_H == _opponent.mBox.y) ) - { - mDir = DOWN; - - // SDL_Log("adjacent: キャラに隣接(下)"); - - return mDir; - } - - if( (mBox.x - TILE_W == _opponent.mBox.x) && (mBox.y == _opponent.mBox.y) ) - { - mDir = LEFT; - - // SDL_Log("adjacent: キャラに隣接(左)"); - - return mDir; - } - - if( (mBox.x + TILE_W == _opponent.mBox.x) && (mBox.y == _opponent.mBox.y) ) - { - mDir = RIGHT; - - // SDL_Log("adjacent: キャラに隣接(右)"); - - return mDir; - } - return NO_DIRECTION; -} - +{ + if(!onTileCenter()) + return NO_DIRECTION; + + if( (mBox.x == _opponent.mBox.x) && (mBox.y - TILE_H == _opponent.mBox.y) ) + { + mDir = UP; + + // SDL_Log("adjacent: キャラに隣接(上)"); + + return mDir; + } + + if( (mBox.x == _opponent.mBox.x) && (mBox.y + TILE_H == _opponent.mBox.y) ) + { + mDir = DOWN; + + // SDL_Log("adjacent: キャラに隣接(下)"); + + return mDir; + } + + if( (mBox.x - TILE_W == _opponent.mBox.x) && (mBox.y == _opponent.mBox.y) ) + { + mDir = LEFT; + + // SDL_Log("adjacent: キャラに隣接(左)"); + + return mDir; + } + + if( (mBox.x + TILE_W == _opponent.mBox.x) && (mBox.y == _opponent.mBox.y) ) + { + mDir = RIGHT; + + // SDL_Log("adjacent: キャラに隣接(右)"); + + return mDir; + } + return NO_DIRECTION; +} + DIRECTION Character::adjacent(const std::vector& _opponents) -{ +{ for(const auto& oppo : _opponents) - { + { DIRECTION dir = adjacent(oppo); if(dir != NO_DIRECTION) - { + { return dir; - } - } - return NO_DIRECTION; -} - -std::string Character::attack(Character &_opponent) -{ - if(!onTileCenter()) - return ""; - - return mName + "の攻撃 " + _opponent.receiveDamage(STR); -} - -std::string Character::receiveDamage(int _damage) -{ - receivingDamage = true; - - _damage -= (VIT / 2); - if (_damage <= 0) - _damage = 1; - nowHP -= _damage; - if (nowHP <= 0) - { - nowHP = 0; - mState = DEAD; - } - std::string log = mName + "は" + std::to_string(_damage); - if(mState == DEAD) - { - log += "ダメージを受けて倒れた"; - } - else - { - log += "ダメージを受けた"; - } - return log; -} - -void Character::healed(int _heal_val) -{ - nowHP += _heal_val; - if (nowHP > maxHP) - nowHP = maxHP; -} - -void Character::setImagePos(Ivec2 _image_pos) -{ - - // SDL_Log("setImagePos: (%d, %d)", _image_pos.x / TILE_W, _image_pos.y / TILE_H); - - mBox.x = _image_pos.x; - mBox.y = _image_pos.y; -} - -void Character::setDataPos(Ivec2 _data_pos) -{ - - // SDL_Log("setDataPos: (%d, %d)", _data_pos.x, _data_pos.y); - - mBox.x = _data_pos.x * TILE_W + TILE_W / 4; - mBox.y = _data_pos.y * TILE_H + TILE_H / 4; -} - -void Character::setState(STATE _state) -{ - mState = _state; -} - -void Character::setDir(DIRECTION _dir) -{ - mDir = _dir; -} - -void Character::setCamera(SDL_Rect &_camera) -{ - // Center the _camera over the player - _camera.x = (mBox.x + SPRITE_CHAR_WIDTH / 2) - SCREEN_WIDTH / 2; - _camera.y = (mBox.y + SPRITE_CHAR_HEIGHT / 2) - SCREEN_HEIGHT / 2; - - // Keep the _camera in bounds - if (_camera.x < 0) - { - _camera.x = 0; - } - if (_camera.y < 0) - { - _camera.y = 0; - } - if (_camera.x > LEVEL_WIDTH - _camera.w) - { - _camera.x = LEVEL_WIDTH - _camera.w; - } - if (_camera.y > LEVEL_HEIGHT - _camera.h) - { - _camera.y = LEVEL_HEIGHT - _camera.h; - } -} - -void Character::render(SDL_Rect &_camera) -{ - const int HP_BAR_H = 5; - SDL_Rect hp_bar_frame = { - mBox.x - _camera.x, - mBox.y - _camera.y - HP_BAR_H, - SPRITE_CHAR_WIDTH, - HP_BAR_H}; - SDL_Rect hp_bar = { - mBox.x - _camera.x, - mBox.y - _camera.y - HP_BAR_H, - SPRITE_CHAR_WIDTH * nowHP / maxHP, - HP_BAR_H}; - - // HPのフレームを表示 - SDL_SetRenderDrawColor(gRenderer, 100, 100, 100, 255); - SDL_RenderFillRect(gRenderer, &hp_bar_frame); - - // HPを表示 - SDL_SetRenderDrawColor(gRenderer, 5, 255, 0, 255); - SDL_RenderFillRect(gRenderer, &hp_bar); - - int c_sprite_num = (static_cast(mDir) * ANIMATION_FRAMES); - if(isMoved) - { - mAnimFrame++; - if(mAnimFrame >= ANIMATION_FRAMES * FPS / ANIM_SPEED) - { - mAnimFrame = 0; - } - c_sprite_num += (mAnimFrame * ANIM_SPEED / FPS); - } - else - { - mAnimFrame = 0; - } - // キャラクターを表示 - mCharTexture.render(mBox.x - _camera.x, mBox.y - _camera.y, &sprile_clips[c_sprite_num], receivingDamage); - receivingDamage = false; -} - -Ivec2 Character::getFrontDataPos() -{ - switch(mDir) - { - case LEFT: return getDataPos() + Ivec2( -1, 0); break; - case RIGHT: return getDataPos() + Ivec2( 1, 0); break; - case UP: return getDataPos() + Ivec2( 0, -1); break; - case DOWN: return getDataPos() + Ivec2( 0, 1); break; - case NO_DIRECTION: break; - } - return getDataPos(); -} - -bool Character::onTileCenter() -{ - if ( ( ( mBox.x % TILE_W ) == ( TILE_W / 4 ) ) - && ( ( mBox.y % TILE_H ) == ( TILE_H / 4 ) ) ) - { - return true; - } - return false; -} - -bool Character::collided(std::vector _tiles, Ivec2 _data_pos, std::vector _otherCharacters) -{ - return (mapOver() || touchWall(_tiles, _data_pos) || touchChars(_otherCharacters, _data_pos)); -} - -bool Character::touchWall(std::vector _tiles, Ivec2 _data_pos) -{ - for (auto _tile : _tiles) - { - // 壁でなければスキップ - if ((_tile.getType() == FLOOR) || (_tile.getType() == AISLE) || (_tile.getType() == STEP)) - { - continue; - } - // 壁ならtrueを返す - if (_data_pos.x == (_tile.getBox().x / TILE_W) - && _data_pos.y == (_tile.getBox().y / TILE_H)) - { - - // SDL_Log("touchWall: 壁に接触"); - - return true; - } - } - - return false; -} - -bool Character::touchChars(const std::vector& _otherCharacters, Ivec2 _data_pos) -{ + } + } + return NO_DIRECTION; +} + +std::string Character::attack(Character &_opponent) +{ + if(!onTileCenter()) + return ""; + + return mName + "の攻撃 " + _opponent.receiveDamage(STR); +} + +std::string Character::receiveDamage(int _damage) +{ + receivingDamage = true; + + _damage -= (VIT / 2); + if (_damage <= 0) + _damage = 1; + nowHP -= _damage; + if (nowHP <= 0) + { + nowHP = 0; + mState = DEAD; + } + std::string log = mName + "は" + std::to_string(_damage); + if(mState == DEAD) + { + log += "ダメージを受けて倒れた"; + } + else + { + log += "ダメージを受けた"; + } + return log; +} + +void Character::healed(int _heal_val) +{ + nowHP += _heal_val; + if (nowHP > maxHP) + nowHP = maxHP; +} + +void Character::setImagePos(Ivec2 _image_pos) +{ + + // SDL_Log("setImagePos: (%d, %d)", _image_pos.x / TILE_W, _image_pos.y / TILE_H); + + mBox.x = _image_pos.x; + mBox.y = _image_pos.y; +} + +void Character::setDataPos(Ivec2 _data_pos) +{ + + // SDL_Log("setDataPos: (%d, %d)", _data_pos.x, _data_pos.y); + + mBox.x = _data_pos.x * TILE_W + TILE_W / 4; + mBox.y = _data_pos.y * TILE_H + TILE_H / 4; +} + +void Character::setState(STATE _state) +{ + mState = _state; +} + +void Character::setDir(DIRECTION _dir) +{ + mDir = _dir; +} + +void Character::setCamera(SDL_Rect &_camera) +{ + // Center the _camera over the player + _camera.x = (mBox.x + SPRITE_CHAR_WIDTH / 2) - SCREEN_WIDTH / 2; + _camera.y = (mBox.y + SPRITE_CHAR_HEIGHT / 2) - SCREEN_HEIGHT / 2; + + // Keep the _camera in bounds + if (_camera.x < 0) + { + _camera.x = 0; + } + if (_camera.y < 0) + { + _camera.y = 0; + } + if (_camera.x > LEVEL_WIDTH - _camera.w) + { + _camera.x = LEVEL_WIDTH - _camera.w; + } + if (_camera.y > LEVEL_HEIGHT - _camera.h) + { + _camera.y = LEVEL_HEIGHT - _camera.h; + } +} + +void Character::render(SDL_Rect &_camera) +{ + const int HP_BAR_H = 5; + SDL_Rect hp_bar_frame = { + mBox.x - _camera.x, + mBox.y - _camera.y - HP_BAR_H, + SPRITE_CHAR_WIDTH, + HP_BAR_H}; + SDL_Rect hp_bar = { + mBox.x - _camera.x, + mBox.y - _camera.y - HP_BAR_H, + SPRITE_CHAR_WIDTH * nowHP / maxHP, + HP_BAR_H}; + + // HPのフレームを表示 + SDL_SetRenderDrawColor(gRenderer, 100, 100, 100, 255); + SDL_RenderFillRect(gRenderer, &hp_bar_frame); + + // HPを表示 + SDL_SetRenderDrawColor(gRenderer, 5, 255, 0, 255); + SDL_RenderFillRect(gRenderer, &hp_bar); + + int c_sprite_num = (static_cast(mDir) * ANIMATION_FRAMES); + if(isMoved) + { + mAnimFrame++; + if(mAnimFrame >= ANIMATION_FRAMES * FPS / ANIM_SPEED) + { + mAnimFrame = 0; + } + c_sprite_num += (mAnimFrame * ANIM_SPEED / FPS); + } + else + { + mAnimFrame = 0; + } + // キャラクターを表示 + mCharTexture.render(mBox.x - _camera.x, mBox.y - _camera.y, &sprile_clips[c_sprite_num], receivingDamage); + receivingDamage = false; +} + +Ivec2 Character::getFrontDataPos() +{ + switch(mDir) + { + case LEFT: return getDataPos() + Ivec2( -1, 0); break; + case RIGHT: return getDataPos() + Ivec2( 1, 0); break; + case UP: return getDataPos() + Ivec2( 0, -1); break; + case DOWN: return getDataPos() + Ivec2( 0, 1); break; + case NO_DIRECTION: break; + } + return getDataPos(); +} + +bool Character::onTileCenter() +{ + if ( ( ( mBox.x % TILE_W ) == ( TILE_W / 4 ) ) + && ( ( mBox.y % TILE_H ) == ( TILE_H / 4 ) ) ) + { + return true; + } + return false; +} + +bool Character::collided(std::vector _tiles, Ivec2 _data_pos, std::vector _otherCharacters) +{ + return (mapOver() || touchWall(_tiles, _data_pos) || touchChars(_otherCharacters, _data_pos)); +} + +bool Character::touchWall(std::vector _tiles, Ivec2 _data_pos) +{ + for (auto _tile : _tiles) + { + // 壁でなければスキップ + if ((_tile.getType() == FLOOR) || (_tile.getType() == AISLE) || (_tile.getType() == STEP)) + { + continue; + } + // 壁ならtrueを返す + if (_data_pos.x == (_tile.getBox().x / TILE_W) + && _data_pos.y == (_tile.getBox().y / TILE_H)) + { + + // SDL_Log("touchWall: 壁に接触"); + + return true; + } + } + + return false; +} + +bool Character::touchChars(const std::vector& _otherCharacters, Ivec2 _data_pos) +{ for(const auto& _otherCharacter : _otherCharacters) - { - if( touchChar(_otherCharacter, _data_pos) ) - { - return true; - } - } - return false; -} - -bool Character::touchChar(const Character& _otherCharacter, Ivec2 _data_pos) -{ - try - { - if( (_data_pos == _otherCharacter.getDataPos()) ) - { - // SDL_Log("touchChar: キャラクターに接触"); - return true; - } - } catch (const std::exception& e) { - std::cout << e.what() << std::endl; - } - return false; -} - -bool Character::mapOver() -{ - if( (getDataPos().x < 0) || (getDataPos().x >= FLOOR_W) - || (getDataPos().y < 0) || (getDataPos().y >= FLOOR_H)) - { - - // SDL_Log("mapOver: 範囲外"); - - return true; - } - else - return false; + { + if( touchChar(_otherCharacter, _data_pos) ) + { + return true; + } + } + return false; +} + +bool Character::touchChar(const Character& _otherCharacter, Ivec2 _data_pos) +{ + try + { + if( (_data_pos == _otherCharacter.getDataPos()) ) + { + // SDL_Log("touchChar: キャラクターに接触"); + return true; + } + } catch (const std::exception& e) { + std::cout << e.what() << std::endl; + } + return false; +} + +bool Character::mapOver() +{ + if( (getDataPos().x < 0) || (getDataPos().x >= FLOOR_W) + || (getDataPos().y < 0) || (getDataPos().y >= FLOOR_H)) + { + + // SDL_Log("mapOver: 範囲外"); + + return true; + } + else + return false; } \ No newline at end of file diff --git a/src/GenerateDungeon/Character.h b/src/Characters/Character.h similarity index 91% rename from src/GenerateDungeon/Character.h rename to src/Characters/Character.h index 33f4795..8e06b21 100644 --- a/src/GenerateDungeon/Character.h +++ b/src/Characters/Character.h @@ -1,119 +1,119 @@ -#pragma once - -#include -#include -#include -#include "../../Ivec2.h" - -#include "Enum.h" -#include "Tile.h" -#include "Const.h" - -enum STATE { - // プレイヤー - ALIVE, - // 敵キャラ - SEARCH, - FOUND, - ESCAPE, - // どちらも - DEAD -}; - -class Character -{ -public: - Character(); - Character(int _x, int _y, int _maxHP, int _STR, int _VIT, STATE _state, DIRECTION _dir, CHAR_TYPE _type, std::string _name); - ~Character(); - +#pragma once + +#include +#include +#include +#include "Utils/Ivec2.h" + +#include "GenerateDungeon/Enum.h" +#include "GenerateDungeon/Tile.h" +#include "GenerateDungeon/Const.h" + +enum STATE { + // プレイヤー + ALIVE, + // 敵キャラ + SEARCH, + FOUND, + ESCAPE, + // どちらも + DEAD +}; + +class Character +{ +public: + Character(); + Character(int _x, int _y, int _maxHP, int _STR, int _VIT, STATE _state, DIRECTION _dir, CHAR_TYPE _type, std::string _name); + ~Character(); + DIRECTION adjacent(const class Character& _opponent); DIRECTION adjacent(const std::vector& _opponents); - virtual std::string attack(class Character& _opponent); - std::string receiveDamage(int _damage); - void healed(int _heal_val); - - /// @brief 座標テレポート - /// @param _image_pos 画像系座標 - void setImagePos(Ivec2 _image_pos); - - /// @brief 座標テレポート - /// @param _data_pos データ系座標 - void setDataPos(Ivec2 _data_pos); - void setState(STATE _state); - void setDir(DIRECTION _dir); - - int getNowHP() const {return nowHP;} - int getMaxHP() const {return maxHP;} - int getSTR() const {return STR;} - int getVIT() const {return VIT;} - STATE getState() const {return mState;} - DIRECTION getDir() const {return mDir;} - CHAR_TYPE getType() const {return mType;} - std::string getName() const {return mName;} - - /// @brief 画像系座標を返す - Ivec2 getImagePos() const {return Ivec2(mBox.x, mBox.y);} - - /// @brief データ系座標を返す - Ivec2 getDataPos() const {return Ivec2(static_cast(mBox.x / TILE_W), static_cast(mBox.y / TILE_H));} - - /// @brief 前方の座標を返す - /// @return NO_DIRECTIONの場合は現在地を返す - Ivec2 getFrontDataPos(); - bool onTileCenter(); - - /// @brief 向いている方向に移動。当たり判定も含む - /// @param _tiles 当たり判定用の全タイルの配列 - bool move(std::vector _tiles, const std::vector& _otherCharacters); - - /// @brief 向いている方向に移動。当たり判定も含む - /// @param _destination 移動先のデータ系座標 - /// @param _tiles 当たり判定用の全タイルの配列 - bool moveTo(Ivec2 _destination, std::vector _tiles, const std::vector& _otherCharacters); - void setCamera(SDL_Rect& _camera); - void render(SDL_Rect& _camera); - bool collided(std::vector _tiles, Ivec2 _data_pos, std::vector _otherCharacters); - - static LTexture mCharTexture; - // LTexture mCharTexture; - - std::vector sprile_clips; - - bool isMoved; - -protected: - /// @brief 矩形とタイルの衝突判定 - /// @param _tiles 全タイルの配列 - /// @param _data_pos 対象のデータ系座標 - bool touchWall(std::vector _tiles, Ivec2 _data_pos); - - /// @brief キャラとキャラの衝突判定 - /// @param _otherCharacters - /// @param _data_pos - /// @return 当たっていたらtrue - bool touchChars(const std::vector& _otherCharacters, Ivec2 _data_pos); - - /// @brief キャラとキャラの衝突判定 - /// @param _otherCharacter - /// @param _data_pos - /// @return 当たっていたらtrue - bool touchChar(const class Character & _otherCharacter, Ivec2 _data_pos); - - /// @brief マップ外か判定 - /// @return マップ外だったらtrue - bool mapOver(); - - int nowHP; - int maxHP, STR, VIT; - STATE mState; - DIRECTION mDir; - CHAR_TYPE mType; - - //プレイヤーの衝突判定 - SDL_Rect mBox; - - int mAnimFrame; - bool receivingDamage; - std::string mName; -}; + virtual std::string attack(class Character& _opponent); + std::string receiveDamage(int _damage); + void healed(int _heal_val); + + /// @brief 座標テレポート + /// @param _image_pos 画像系座標 + void setImagePos(Ivec2 _image_pos); + + /// @brief 座標テレポート + /// @param _data_pos データ系座標 + void setDataPos(Ivec2 _data_pos); + void setState(STATE _state); + void setDir(DIRECTION _dir); + + int getNowHP() const {return nowHP;} + int getMaxHP() const {return maxHP;} + int getSTR() const {return STR;} + int getVIT() const {return VIT;} + STATE getState() const {return mState;} + DIRECTION getDir() const {return mDir;} + CHAR_TYPE getType() const {return mType;} + std::string getName() const {return mName;} + + /// @brief 画像系座標を返す + Ivec2 getImagePos() const {return Ivec2(mBox.x, mBox.y);} + + /// @brief データ系座標を返す + Ivec2 getDataPos() const {return Ivec2(static_cast(mBox.x / TILE_W), static_cast(mBox.y / TILE_H));} + + /// @brief 前方の座標を返す + /// @return NO_DIRECTIONの場合は現在地を返す + Ivec2 getFrontDataPos(); + bool onTileCenter(); + + /// @brief 向いている方向に移動。当たり判定も含む + /// @param _tiles 当たり判定用の全タイルの配列 + bool move(std::vector _tiles, const std::vector& _otherCharacters); + + /// @brief 向いている方向に移動。当たり判定も含む + /// @param _destination 移動先のデータ系座標 + /// @param _tiles 当たり判定用の全タイルの配列 + bool moveTo(Ivec2 _destination, std::vector _tiles, const std::vector& _otherCharacters); + void setCamera(SDL_Rect& _camera); + void render(SDL_Rect& _camera); + bool collided(std::vector _tiles, Ivec2 _data_pos, std::vector _otherCharacters); + + static LTexture mCharTexture; + // LTexture mCharTexture; + + std::vector sprile_clips; + + bool isMoved; + +protected: + /// @brief 矩形とタイルの衝突判定 + /// @param _tiles 全タイルの配列 + /// @param _data_pos 対象のデータ系座標 + bool touchWall(std::vector _tiles, Ivec2 _data_pos); + + /// @brief キャラとキャラの衝突判定 + /// @param _otherCharacters + /// @param _data_pos + /// @return 当たっていたらtrue + bool touchChars(const std::vector& _otherCharacters, Ivec2 _data_pos); + + /// @brief キャラとキャラの衝突判定 + /// @param _otherCharacter + /// @param _data_pos + /// @return 当たっていたらtrue + bool touchChar(const class Character & _otherCharacter, Ivec2 _data_pos); + + /// @brief マップ外か判定 + /// @return マップ外だったらtrue + bool mapOver(); + + int nowHP; + int maxHP, STR, VIT; + STATE mState; + DIRECTION mDir; + CHAR_TYPE mType; + + //プレイヤーの衝突判定 + SDL_Rect mBox; + + int mAnimFrame; + bool receivingDamage; + std::string mName; +}; diff --git a/src/Enemy.cpp b/src/Characters/Enemy.cpp similarity index 95% rename from src/Enemy.cpp rename to src/Characters/Enemy.cpp index 213e085..d980ac9 100644 --- a/src/Enemy.cpp +++ b/src/Characters/Enemy.cpp @@ -1,284 +1,284 @@ -#include "GenerateDungeon/Enemy.h" - -Enemy::Enemy(const Enemy& other) -:ID(other.ID) -{ - maxHP = other.maxHP; - STR = other.STR; - VIT = other.VIT; - mName = other.mName; - enemy_type = other.enemy_type; - mBox.x = other.mBox.x; - mBox.y = other.mBox.y; - mState = other.mState; - mDir = other.mDir; - mType = other.mType; - nowHP = other.nowHP; -} - -Enemy::Enemy(ENEMY_TYPE _enemy_type, int _id) -: Character(), ID(_id), elapsedTurn(0) -{ - enemy_type = _enemy_type; - switch(enemy_type) - { - case DEKA: - maxHP = DEKA_HP; - STR = DEKA_STR; - VIT = DEKA_VIT; - EXP = DEKA_EXP; - mName = "  デ カ  "; - break; - - case GURI: - maxHP = GURI_HP; - STR = GURI_STR; - VIT = GURI_VIT; - EXP = GURI_EXP; - mName = "  グ リ  "; - break; - - case JELYF: - maxHP = JELYF_HP; - STR = JELYF_STR; - VIT = JELYF_VIT; - EXP = JELYF_EXP; - mName = "  ジェリフ  "; - break; - - case YUMMY: - maxHP = YUMMY_HP; - STR = YUMMY_STR; - VIT = YUMMY_VIT; - EXP = YUMMY_EXP; - mName = "  ヤミー  "; - break; - - case CRYSTAL: - maxHP = CRYSTAL_HP; - STR = CRYSTAL_STR; - VIT = CRYSTAL_VIT; - EXP = CRYSTAL_EXP; - mName = " クリスタル "; - break; - - case GROSSPIDER: - maxHP = GROSSPIDER_HP; - STR = GROSSPIDER_STR; - VIT = GROSSPIDER_VIT; - EXP = GROSSPIDER_EXP; - mName = "グロスパイダー"; - break; - - case IRON: - maxHP = IRON_HP; - STR = IRON_STR; - VIT = IRON_VIT; - EXP = IRON_EXP; - mName = "  アイアン "; - break; - - case TATSU: - maxHP = TATSU_HP; - STR = TATSU_STR; - VIT = TATSU_VIT; - EXP = TATSU_EXP; - mName = "  タ ツ  "; - break; - - case BALL: - maxHP = BALL_HP; - STR = BALL_STR; - VIT = BALL_VIT; - EXP = BALL_EXP; - mName = "  ボール  "; - break; - - case ENEMY_TYPE_NUMBER: break; - } - mBox.x = 0; - mBox.y = 0; - mState = SEARCH; - mDir = DOWN; - mType = ENEMY; - nowHP = maxHP; -} - -Enemy::Enemy(int _x, int _y, int _maxHP, int _STR, int _VIT, int _id) -: Character(), ID(_id), elapsedTurn(0) -{ - enemy_type = DEKA; - maxHP = DEKA_HP; - STR = DEKA_STR; - VIT = DEKA_VIT; - mName = " オリジナル "; - mBox.x = 0; - mBox.y = 0; - mState = SEARCH; - mDir = DOWN; - mType = ENEMY; - nowHP = maxHP; - EXP = DEKA_EXP; -} - -Enemy::~Enemy() -{ - route.clear(); - route.shrink_to_fit(); -} - -void Enemy::walk(std::vector _tiles, class Character& _player, const std::vector& _otherEnemies) -{ - std::vector otherCharacters; - otherCharacters.push_back(static_cast(_player)); +#include "Characters/Enemy.h" + +Enemy::Enemy(const Enemy& other) +:ID(other.ID) +{ + maxHP = other.maxHP; + STR = other.STR; + VIT = other.VIT; + mName = other.mName; + enemy_type = other.enemy_type; + mBox.x = other.mBox.x; + mBox.y = other.mBox.y; + mState = other.mState; + mDir = other.mDir; + mType = other.mType; + nowHP = other.nowHP; +} + +Enemy::Enemy(ENEMY_TYPE _enemy_type, int _id) +: Character(), ID(_id), elapsedTurn(0) +{ + enemy_type = _enemy_type; + switch(enemy_type) + { + case DEKA: + maxHP = DEKA_HP; + STR = DEKA_STR; + VIT = DEKA_VIT; + EXP = DEKA_EXP; + mName = "  デ カ  "; + break; + + case GURI: + maxHP = GURI_HP; + STR = GURI_STR; + VIT = GURI_VIT; + EXP = GURI_EXP; + mName = "  グ リ  "; + break; + + case JELYF: + maxHP = JELYF_HP; + STR = JELYF_STR; + VIT = JELYF_VIT; + EXP = JELYF_EXP; + mName = "  ジェリフ  "; + break; + + case YUMMY: + maxHP = YUMMY_HP; + STR = YUMMY_STR; + VIT = YUMMY_VIT; + EXP = YUMMY_EXP; + mName = "  ヤミー  "; + break; + + case CRYSTAL: + maxHP = CRYSTAL_HP; + STR = CRYSTAL_STR; + VIT = CRYSTAL_VIT; + EXP = CRYSTAL_EXP; + mName = " クリスタル "; + break; + + case GROSSPIDER: + maxHP = GROSSPIDER_HP; + STR = GROSSPIDER_STR; + VIT = GROSSPIDER_VIT; + EXP = GROSSPIDER_EXP; + mName = "グロスパイダー"; + break; + + case IRON: + maxHP = IRON_HP; + STR = IRON_STR; + VIT = IRON_VIT; + EXP = IRON_EXP; + mName = "  アイアン "; + break; + + case TATSU: + maxHP = TATSU_HP; + STR = TATSU_STR; + VIT = TATSU_VIT; + EXP = TATSU_EXP; + mName = "  タ ツ  "; + break; + + case BALL: + maxHP = BALL_HP; + STR = BALL_STR; + VIT = BALL_VIT; + EXP = BALL_EXP; + mName = "  ボール  "; + break; + + case ENEMY_TYPE_NUMBER: break; + } + mBox.x = 0; + mBox.y = 0; + mState = SEARCH; + mDir = DOWN; + mType = ENEMY; + nowHP = maxHP; +} + +Enemy::Enemy(int _x, int _y, int _maxHP, int _STR, int _VIT, int _id) +: Character(), ID(_id), elapsedTurn(0) +{ + enemy_type = DEKA; + maxHP = DEKA_HP; + STR = DEKA_STR; + VIT = DEKA_VIT; + mName = " オリジナル "; + mBox.x = 0; + mBox.y = 0; + mState = SEARCH; + mDir = DOWN; + mType = ENEMY; + nowHP = maxHP; + EXP = DEKA_EXP; +} + +Enemy::~Enemy() +{ + route.clear(); + route.shrink_to_fit(); +} + +void Enemy::walk(std::vector _tiles, class Character& _player, const std::vector& _otherEnemies) +{ + std::vector otherCharacters; + otherCharacters.push_back(static_cast(_player)); for(const auto& enemy : _otherEnemies) - { - if(enemy.getDataPos() == getDataPos()) - continue; - - otherCharacters.push_back(static_cast(enemy)); - } - // if(onTileCenter()) - // { - // SDL_Log("walk: nextPos(%d, %d)", nextPos.x, nextPos.y); - // SDL_Log("walk: enemPos(%d, %d)", getDataPos().x, getDataPos().y); - // } - - // SDL_Log("タイル内座標(x: %d, y: %d)\n", (mBox.x % TILE_W), (mBox.y % TILE_H)); - - bool touched = moveTo(nextPos, _tiles, otherCharacters); - if(touched) - { - elapsedTurn = ENEMY_SEARCH_INTERVAL + 1; - } - - if(onTileCenter() && mState == SEARCH) - { - nextPos = route[0]; - route.pop_front(); - elapsedTurn++; - - // SDL_Log("walk: %2d %s elapsedTurn = %3d, route size = %3d\n", ID, mName.c_str(), elapsedTurn, static_cast(route.size())); - - } -} - -void Enemy::walkTo(Ivec2 _destination, std::vector _tiles, class Character& _player, const std::vector& _otherEnemies) -{ - _destination.x = _destination.x / TILE_W; - _destination.y = _destination.y / TILE_H; - - nextPos = _destination; - - walk(_tiles, _player, _otherEnemies); -} - -void Enemy::setGoal(CELL_TYPE _dungeon[FLOOR_H][FLOOR_W], Ivec2 _goal) -{ - if(_goal.x > FLOOR_W || _goal.y > FLOOR_H || _goal.x < 0 || _goal.y < 0) - { - SDL_Log("Goal position error"); - return; - } - goal = _goal; - route.clear(); - - // SDL_Log("setGoal: ルート探索"); - - route = AStar::AStar(_dungeon, getDataPos(), goal); - // 現在地をポップ - - // SDL_Log("現在地としてポップ(%d, %d)", route.at(0).x, route.at(0).y); - - route.pop_front(); - if(route.size() == 0) - { - return; - } - - // SDL_Log("setGoal: 更新後のルート一覧"); - // for(auto vec2 : route) - // { - // SDL_Log("setGoal: (%d, %d)", vec2.x, vec2.y); - // } - - nextPos = route.at(0); - route.pop_front(); - elapsedTurn = 0; -} - -std::string Enemy::attack(Character& _opponent) -{ - if(!onTileCenter()) - return ""; - - elapsedTurn++; - return mName + "の攻撃 " + _opponent.receiveDamage(STR); -} - -bool Enemy::find(Character _opponent) -{ - if(!onTileCenter()) - return false; - - return ( getDataPos().manhattan(_opponent.getDataPos()) <= ENEMY_FIND_RANGE ); -} - -bool Enemy::mustUpdateRoute() -{ - if(!onTileCenter()) - return false; - - bool result = ((static_cast(route.size()) < 1) || (elapsedTurn > ENEMY_SEARCH_INTERVAL)); - - // if( static_cast(route.size()) < 1 ) - // { - // SDL_Log("mustUpdateRoute: ルートサイズが少ない %d", static_cast(route.size())); - // } - // if( elapsedTurn > ENEMY_SEARCH_INTERVAL ) - // { - // SDL_Log("mustUpdateRoute: 経過ターン超過 %d", elapsedTurn); - // } - - if(result) - { - - // SDL_Log("mustUpdateRoute: 更新要求"); - - routeClear(); - } - return result; -} - -bool Enemy::changeState(Character _opponent) -{ - if(!onTileCenter()) - return false; - - if(nowHP <= 0) - { - setState(DEAD); - routeClear(); - return true; - } - else if (find(_opponent) && mState != FOUND) - { - - // SDL_Log("プレイヤー発見"); - - setState(FOUND); - routeClear(); - return true; - } - else if(!find(_opponent) && mState != SEARCH) - { - - // SDL_Log("プレイヤー未発見"); - - setState(SEARCH); - routeClear(); - return false; - } - - return false; + { + if(enemy.getDataPos() == getDataPos()) + continue; + + otherCharacters.push_back(static_cast(enemy)); + } + // if(onTileCenter()) + // { + // SDL_Log("walk: nextPos(%d, %d)", nextPos.x, nextPos.y); + // SDL_Log("walk: enemPos(%d, %d)", getDataPos().x, getDataPos().y); + // } + + // SDL_Log("タイル内座標(x: %d, y: %d)\n", (mBox.x % TILE_W), (mBox.y % TILE_H)); + + bool touched = moveTo(nextPos, _tiles, otherCharacters); + if(touched) + { + elapsedTurn = ENEMY_SEARCH_INTERVAL + 1; + } + + if(onTileCenter() && mState == SEARCH) + { + nextPos = route[0]; + route.pop_front(); + elapsedTurn++; + + // SDL_Log("walk: %2d %s elapsedTurn = %3d, route size = %3d\n", ID, mName.c_str(), elapsedTurn, static_cast(route.size())); + + } +} + +void Enemy::walkTo(Ivec2 _destination, std::vector _tiles, class Character& _player, const std::vector& _otherEnemies) +{ + _destination.x = _destination.x / TILE_W; + _destination.y = _destination.y / TILE_H; + + nextPos = _destination; + + walk(_tiles, _player, _otherEnemies); +} + +void Enemy::setGoal(CELL_TYPE _dungeon[FLOOR_H][FLOOR_W], Ivec2 _goal) +{ + if(_goal.x > FLOOR_W || _goal.y > FLOOR_H || _goal.x < 0 || _goal.y < 0) + { + SDL_Log("Goal position error"); + return; + } + goal = _goal; + route.clear(); + + // SDL_Log("setGoal: ルート探索"); + + route = AStar::AStar(_dungeon, getDataPos(), goal); + // 現在地をポップ + + // SDL_Log("現在地としてポップ(%d, %d)", route.at(0).x, route.at(0).y); + + route.pop_front(); + if(route.size() == 0) + { + return; + } + + // SDL_Log("setGoal: 更新後のルート一覧"); + // for(auto vec2 : route) + // { + // SDL_Log("setGoal: (%d, %d)", vec2.x, vec2.y); + // } + + nextPos = route.at(0); + route.pop_front(); + elapsedTurn = 0; +} + +std::string Enemy::attack(Character& _opponent) +{ + if(!onTileCenter()) + return ""; + + elapsedTurn++; + return mName + "の攻撃 " + _opponent.receiveDamage(STR); +} + +bool Enemy::find(Character _opponent) +{ + if(!onTileCenter()) + return false; + + return ( getDataPos().manhattan(_opponent.getDataPos()) <= ENEMY_FIND_RANGE ); +} + +bool Enemy::mustUpdateRoute() +{ + if(!onTileCenter()) + return false; + + bool result = ((static_cast(route.size()) < 1) || (elapsedTurn > ENEMY_SEARCH_INTERVAL)); + + // if( static_cast(route.size()) < 1 ) + // { + // SDL_Log("mustUpdateRoute: ルートサイズが少ない %d", static_cast(route.size())); + // } + // if( elapsedTurn > ENEMY_SEARCH_INTERVAL ) + // { + // SDL_Log("mustUpdateRoute: 経過ターン超過 %d", elapsedTurn); + // } + + if(result) + { + + // SDL_Log("mustUpdateRoute: 更新要求"); + + routeClear(); + } + return result; +} + +bool Enemy::changeState(Character _opponent) +{ + if(!onTileCenter()) + return false; + + if(nowHP <= 0) + { + setState(DEAD); + routeClear(); + return true; + } + else if (find(_opponent) && mState != FOUND) + { + + // SDL_Log("プレイヤー発見"); + + setState(FOUND); + routeClear(); + return true; + } + else if(!find(_opponent) && mState != SEARCH) + { + + // SDL_Log("プレイヤー未発見"); + + setState(SEARCH); + routeClear(); + return false; + } + + return false; } \ No newline at end of file diff --git a/src/GenerateDungeon/Enemy.h b/src/Characters/Enemy.h similarity index 89% rename from src/GenerateDungeon/Enemy.h rename to src/Characters/Enemy.h index 85a4cc5..31bd718 100644 --- a/src/GenerateDungeon/Enemy.h +++ b/src/Characters/Enemy.h @@ -1,49 +1,49 @@ -#pragma once - -#include -#include -#include -#include "../../Ivec2.h" - -#include "AStar.h" -#include "Character.h" -#include "Const.h" -#include "Enum.h" - -class Enemy : public Character -{ -public: - Enemy(const Enemy& other); - Enemy(ENEMY_TYPE _enemy_type, int _id); - Enemy(int _x, int _y, int _maxHP, int _STR, int _VIT, int _id); - ~Enemy(); - - void walk(std::vector _tiles, class Character& _player, const std::vector& _otherEnemies); - void walkTo(Ivec2 _destination, std::vector _tiles, class Character& _player, const std::vector& _otherEnemies); - - /// @brief 目的地を設定し、ルートを検索 - /// @param dungeon データ系のマップ情報 - /// @param _goal データ系の目的地の座標 - void setGoal(CELL_TYPE dungeon[FLOOR_H][FLOOR_W], Ivec2 _goal); - - std::string attack(class Character& _opponent) override; - bool find(class Character _opponent); - bool mustUpdateRoute(); - bool changeState(class Character _opponent); - - void routeClear() {route.clear(); elapsedTurn = ENEMY_SEARCH_INTERVAL + 1;} - - int getRouteSize() {return static_cast(route.size());} - int getElapsedTurn() {return elapsedTurn;} - ENEMY_TYPE getEnemyType() {return enemy_type;} - - int ID; - int EXP; - -private: - std::deque route; - Ivec2 goal; - Ivec2 nextPos; - int elapsedTurn; - ENEMY_TYPE enemy_type; -}; +#pragma once + +#include +#include +#include +#include "Utils/Ivec2.h" + +#include "System/AStar.h" +#include "Characters/Character.h" +#include "GenerateDungeon/Const.h" +#include "GenerateDungeon/Enum.h" + +class Enemy : public Character +{ +public: + Enemy(const Enemy& other); + Enemy(ENEMY_TYPE _enemy_type, int _id); + Enemy(int _x, int _y, int _maxHP, int _STR, int _VIT, int _id); + ~Enemy(); + + void walk(std::vector _tiles, class Character& _player, const std::vector& _otherEnemies); + void walkTo(Ivec2 _destination, std::vector _tiles, class Character& _player, const std::vector& _otherEnemies); + + /// @brief 目的地を設定し、ルートを検索 + /// @param dungeon データ系のマップ情報 + /// @param _goal データ系の目的地の座標 + void setGoal(CELL_TYPE dungeon[FLOOR_H][FLOOR_W], Ivec2 _goal); + + std::string attack(class Character& _opponent) override; + bool find(class Character _opponent); + bool mustUpdateRoute(); + bool changeState(class Character _opponent); + + void routeClear() {route.clear(); elapsedTurn = ENEMY_SEARCH_INTERVAL + 1;} + + int getRouteSize() {return static_cast(route.size());} + int getElapsedTurn() {return elapsedTurn;} + ENEMY_TYPE getEnemyType() {return enemy_type;} + + int ID; + int EXP; + +private: + std::deque route; + Ivec2 goal; + Ivec2 nextPos; + int elapsedTurn; + ENEMY_TYPE enemy_type; +}; diff --git a/src/Player.cpp b/src/Characters/Player.cpp similarity index 88% rename from src/Player.cpp rename to src/Characters/Player.cpp index d438d50..7654b42 100644 --- a/src/Player.cpp +++ b/src/Characters/Player.cpp @@ -1,31 +1,31 @@ -#include "GenerateDungeon/Player.h" - -Player::Player(int _x, int _y, int _maxHP, int _STR, int _VIT) -: Character(_x, _y, _maxHP, _STR, _VIT, ALIVE, DOWN, PLAYER, " プレイヤー "), level(1), exp(0) -{ -} - -bool Player::levelUp(int _exp) -{ - exp += _exp; - if(exp >= level * PLAYER_EXP) - { - exp = 0; - level++; - maxHP += 10; - nowHP += 10; - STR += 2; - VIT += 2; - return true; - } - return false; -} - -void Player::reset() -{ - nowHP = maxHP; - mState = ALIVE; - mDir = DOWN; - level = 1; - exp = 0; +#include "Characters/Player.h" + +Player::Player(int _x, int _y, int _maxHP, int _STR, int _VIT) +: Character(_x, _y, _maxHP, _STR, _VIT, ALIVE, DOWN, PLAYER, " プレイヤー "), level(1), exp(0) +{ +} + +bool Player::levelUp(int _exp) +{ + exp += _exp; + if(exp >= level * PLAYER_EXP) + { + exp = 0; + level++; + maxHP += 10; + nowHP += 10; + STR += 2; + VIT += 2; + return true; + } + return false; +} + +void Player::reset() +{ + nowHP = maxHP; + mState = ALIVE; + mDir = DOWN; + level = 1; + exp = 0; } \ No newline at end of file diff --git a/src/GenerateDungeon/Player.h b/src/Characters/Player.h similarity index 83% rename from src/GenerateDungeon/Player.h rename to src/Characters/Player.h index 82d828f..f63a3b3 100644 --- a/src/GenerateDungeon/Player.h +++ b/src/Characters/Player.h @@ -1,15 +1,15 @@ -#pragma once - -#include "Character.h" - -class Player : public Character -{ -public: - Player(int _x, int _y, int _maxHP, int _STR, int _VIT); - - bool levelUp(int _exp); - void reset(); - - int level; - int exp; -}; +#pragma once + +#include "Characters/Character.h" + +class Player : public Character +{ +public: + Player(int _x, int _y, int _maxHP, int _STR, int _VIT); + + bool levelUp(int _exp); + void reset(); + + int level; + int exp; +}; diff --git a/src/Extern.cpp b/src/Core/Extern.cpp similarity index 100% rename from src/Extern.cpp rename to src/Core/Extern.cpp diff --git a/src/Game.cpp b/src/Core/Game.cpp similarity index 90% rename from src/Game.cpp rename to src/Core/Game.cpp index b21bc3b..0e2f9ff 100644 --- a/src/Game.cpp +++ b/src/Core/Game.cpp @@ -1,322 +1,322 @@ -#include "Game.h" - -extern SDL_Window *gWindow; -extern SDL_Renderer *gRenderer; -extern TTF_Font *gFontN, *gFontB; -extern Mix_Chunk* gClickEffect; -extern SCENE gNowScene; - -SDL_atomic_t frames; - -/* 設定された間隔で平均フレームレートの計算と表示を行う */ -Uint32 fps_timer_callback(Uint32 interval, void *data) -{ - // const Uint32 f = SDL_AtomicGet(&frames); - // const iv = interval * 0.001f; - - /* 注意: SDL_Logがスレッドセーフであるかは環境に依存する */ -// printf("%.2f\tfps\n", f / iv); - - /* フレームカウンタをリセットする */ - SDL_AtomicSet(&frames, 0); - - return interval; -} - -Game::Game() -:mIsRunning(true) -{ - -} - -Game::~Game() -{ - Shutdown(); -} - -bool Game::Init() -{ - // Initialize SDL - int sdlResult = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); - if (sdlResult != 0) - { - SDL_Log("Unable to initialize SDL: %s", SDL_GetError()); - return false; - } - - // Initialize SDL_IMG - sdlResult = IMG_Init(IMG_INIT_PNG); - if (!(sdlResult & IMG_INIT_PNG)) - { - SDL_Log("Unable to initialize SDL_IMG: %s", IMG_GetError()); - return false; - } - - // Initialize SDL_TTF - sdlResult = TTF_Init(); - if (sdlResult != 0) - { - SDL_Log("Unable to initialize SDL_TTF: %s", TTF_GetError()); - return false; - } - +#include "Core/Game.h" + +extern SDL_Window *gWindow; +extern SDL_Renderer *gRenderer; +extern TTF_Font *gFontN, *gFontB; +extern Mix_Chunk* gClickEffect; +extern SCENE gNowScene; + +SDL_atomic_t frames; + +/* 設定された間隔で平均フレームレートの計算と表示を行う */ +Uint32 fps_timer_callback(Uint32 interval, void *data) +{ + // const Uint32 f = SDL_AtomicGet(&frames); + // const iv = interval * 0.001f; + + /* 注意: SDL_Logがスレッドセーフであるかは環境に依存する */ +// printf("%.2f\tfps\n", f / iv); + + /* フレームカウンタをリセットする */ + SDL_AtomicSet(&frames, 0); + + return interval; +} + +Game::Game() +:mIsRunning(true) +{ + +} + +Game::~Game() +{ + Shutdown(); +} + +bool Game::Init() +{ + // Initialize SDL + int sdlResult = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); + if (sdlResult != 0) + { + SDL_Log("Unable to initialize SDL: %s", SDL_GetError()); + return false; + } + + // Initialize SDL_IMG + sdlResult = IMG_Init(IMG_INIT_PNG); + if (!(sdlResult & IMG_INIT_PNG)) + { + SDL_Log("Unable to initialize SDL_IMG: %s", IMG_GetError()); + return false; + } + + // Initialize SDL_TTF + sdlResult = TTF_Init(); + if (sdlResult != 0) + { + SDL_Log("Unable to initialize SDL_TTF: %s", TTF_GetError()); + return false; + } + gFontN = TTF_OpenFont(resource_path("JF-Dot-K14.ttf").c_str(), 30); - if (!gFontN) { - SDL_Log("TTF_OpenFont: %s\n", TTF_GetError()); - return false; - } + if (!gFontN) { + SDL_Log("TTF_OpenFont: %s\n", TTF_GetError()); + return false; + } gFontB = TTF_OpenFont(resource_path("JF-Dot-K14B.ttf").c_str(), 30); - if (!gFontB) { - SDL_Log("TTF_OpenFont: %s\n", TTF_GetError()); - return false; - } - - // Initialize SDL_Mix - sdlResult = Mix_Init(MIX_INIT_MP3 | MIX_INIT_OGG); - if (sdlResult < 0) - { - SDL_Log("Unable to initialize SDL_Mix: %s", Mix_GetError()); - return false; - } - - sdlResult = Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096); - if (sdlResult < 0) - { - SDL_Log("Unable to initialize SDL_mixer: %s", Mix_GetError()); - return false; - } - - // Create an SDL Window - gWindow = SDL_CreateWindow( - "Rogue", // Window title - SDL_WINDOWPOS_UNDEFINED, // Top left x-coordinate of window - SDL_WINDOWPOS_UNDEFINED, // Top left y-coordinate of window - SCREEN_WIDTH, // Width of window - SCREEN_HEIGHT, // Height of window - 0 // Flags (0 for no flags set) - ); - - if (!gWindow) - { - SDL_Log("Failed to create window: %s", SDL_GetError()); - return false; - } - - // Create SDL renderer - gRenderer = SDL_CreateRenderer( - gWindow, // Window to create renderer for - -1, // Usually -1 - SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); - if (!gRenderer) - { - SDL_Log("Failed to create renderer: %s", SDL_GetError()); - return false; - } - - gClickEffect = Mix_LoadWAV(resource_path("click.mp3").c_str()); - if(gClickEffect == NULL) { - SDL_Log("Failed to load sound effect : %s", Mix_GetError()); - return false; - } - - mMusic = Mix_LoadMUS(resource_path("dungeon.ogg").c_str());//Mix_LoadMUS("assets/BGM.mp3"); - if(mMusic == NULL) { - SDL_Log("Failed to load BGM : %s", Mix_GetError()); - return false; - } - - mStart = new Start(); - mHome = new Home(); - mDungeonMenu = new DungeonMenu(); - mDungeon = new Dungeon(); - mCongratulations = new Congratulations(); - mGameOver = new GameOver(); - - Mix_PlayMusic(mMusic, -1); - - return true; -} - -void Game::RunLoop() -{ - // SDL_AddTimer(1000, fps_timer_callback, NULL); - int beforTime = SDL_GetTicks(); - int afterTime = SDL_GetTicks(); - int elapsedTime = 0; - -// 別スレッドで1秒毎にフレームレートを表示 -// SDL_AddTimer(1000, fps_timer_callback, NULL); - while (mIsRunning) - { - beforTime = SDL_GetTicks(); - - // SDL_Log("Input"); - Input(); - // SDL_Log("Update"); - Update(); - // SDL_Log("Output"); - Output(); - - - /* フレーム数に1を加える */ - // SDL_AtomicAdd(&frames, 1); - - // FPS調整 - afterTime = SDL_GetTicks(); - elapsedTime = afterTime - beforTime; - if(SPF > elapsedTime) - SDL_Delay(SPF - elapsedTime); - } -} - -void Game::Input() -{ - Button staticButton; - while (SDL_PollEvent(&event)) - { - if (event.type == SDL_QUIT) - { - mIsRunning = false; - } - if(event.type != SDL_KEYDOWN && event.type != SDL_KEYUP) - { - continue; - } - - switch (gNowScene) - { - case START: - mStart->Input(event); - break; - - case HOME: - mHome->Input(event); - break; - - case DUNGEON_MENU: - mDungeonMenu->Input(event); - break; - - case DUNGEON_AREA_DIVIDE: - case DUNGEON_RRA: - mDungeon->Input(event); - break; - - case CONGRATULATIONS: - mCongratulations->Input(event); - break; - - case GAME_OVER: - mGameOver->Input(event); - break; - } - } - const Uint8 *state = SDL_GetKeyboardState(NULL); - if (state[SDL_SCANCODE_ESCAPE]) mIsRunning = false; -} - -//画面の切り替わり後はここから -void Game::Update() -{ - switch (gNowScene) - { - case START: - mStart->Update(); - break; - case HOME: - mHome->Update(); - break; - case DUNGEON_MENU: - mDungeonMenu->Update(); - break; - case DUNGEON_AREA_DIVIDE: - case DUNGEON_RRA: - mDungeon->Update(); - break; - case CONGRATULATIONS: - mCongratulations->Update(); - break; - case GAME_OVER: - mGameOver->Update(); - break; - } -} - -void Game::Output() -{ - SDL_SetRenderDrawColor(gRenderer, 50, 50, 50, 255); - SDL_RenderClear(gRenderer); - - switch (gNowScene) - { - case START: - mStart->Output(); - break; - case HOME: - mHome->Output(); - break; - case DUNGEON_MENU: - mDungeonMenu->Output(); - break; - case DUNGEON_AREA_DIVIDE: - case DUNGEON_RRA: - mDungeon->Output(); - break; - case CONGRATULATIONS: - mCongratulations->Output(); - break; - case GAME_OVER: - mGameOver->Output(); - break; - } - - SDL_RenderPresent(gRenderer); -} - -void Game::Shutdown() -{ - Mix_HaltMusic(); - Mix_FreeMusic(mMusic); - mMusic = NULL; - Mix_FreeChunk(gClickEffect); - gClickEffect = NULL; - Mix_CloseAudio(); - - - delete mStart; - mStart = nullptr; - delete mHome; - mHome = nullptr; - delete mDungeonMenu; - mDungeonMenu = nullptr; - delete mDungeon; - mDungeon = nullptr; - delete mCongratulations; - mCongratulations = nullptr; - delete mGameOver; - mGameOver = nullptr; - - // try { - // delete mStart; - // delete mHome; - // delete mDungeonMenu; - // delete mDungeon; - // delete mCongratulations; - // delete mGameOver; - - // } catch (const std::exception& e) { - // std::cout << "class" << std::endl; - // std::cout << e.what() << std::endl; - // } - - SDL_DestroyRenderer(gRenderer); - gRenderer = NULL; - SDL_DestroyWindow(gWindow); - gWindow = NULL; - - IMG_Quit(); - TTF_Quit(); - Mix_Quit(); - - SDL_Quit(); -} + if (!gFontB) { + SDL_Log("TTF_OpenFont: %s\n", TTF_GetError()); + return false; + } + + // Initialize SDL_Mix + sdlResult = Mix_Init(MIX_INIT_MP3 | MIX_INIT_OGG); + if (sdlResult < 0) + { + SDL_Log("Unable to initialize SDL_Mix: %s", Mix_GetError()); + return false; + } + + sdlResult = Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096); + if (sdlResult < 0) + { + SDL_Log("Unable to initialize SDL_mixer: %s", Mix_GetError()); + return false; + } + + // Create an SDL Window + gWindow = SDL_CreateWindow( + "Rogue", // Window title + SDL_WINDOWPOS_UNDEFINED, // Top left x-coordinate of window + SDL_WINDOWPOS_UNDEFINED, // Top left y-coordinate of window + SCREEN_WIDTH, // Width of window + SCREEN_HEIGHT, // Height of window + 0 // Flags (0 for no flags set) + ); + + if (!gWindow) + { + SDL_Log("Failed to create window: %s", SDL_GetError()); + return false; + } + + // Create SDL renderer + gRenderer = SDL_CreateRenderer( + gWindow, // Window to create renderer for + -1, // Usually -1 + SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); + if (!gRenderer) + { + SDL_Log("Failed to create renderer: %s", SDL_GetError()); + return false; + } + + gClickEffect = Mix_LoadWAV(resource_path("click.mp3").c_str()); + if(gClickEffect == NULL) { + SDL_Log("Failed to load sound effect : %s", Mix_GetError()); + return false; + } + + mMusic = Mix_LoadMUS(resource_path("dungeon.ogg").c_str());//Mix_LoadMUS("assets/BGM.mp3"); + if(mMusic == NULL) { + SDL_Log("Failed to load BGM : %s", Mix_GetError()); + return false; + } + + mStart = new Start(); + mHome = new Home(); + mDungeonMenu = new DungeonMenu(); + mDungeon = new Dungeon(); + mCongratulations = new Congratulations(); + mGameOver = new GameOver(); + + Mix_PlayMusic(mMusic, -1); + + return true; +} + +void Game::RunLoop() +{ + // SDL_AddTimer(1000, fps_timer_callback, NULL); + int beforTime = SDL_GetTicks(); + int afterTime = SDL_GetTicks(); + int elapsedTime = 0; + +// 別スレッドで1秒毎にフレームレートを表示 +// SDL_AddTimer(1000, fps_timer_callback, NULL); + while (mIsRunning) + { + beforTime = SDL_GetTicks(); + + // SDL_Log("Input"); + Input(); + // SDL_Log("Update"); + Update(); + // SDL_Log("Output"); + Output(); + + + /* フレーム数に1を加える */ + // SDL_AtomicAdd(&frames, 1); + + // FPS調整 + afterTime = SDL_GetTicks(); + elapsedTime = afterTime - beforTime; + if(SPF > elapsedTime) + SDL_Delay(SPF - elapsedTime); + } +} + +void Game::Input() +{ + Button staticButton; + while (SDL_PollEvent(&event)) + { + if (event.type == SDL_QUIT) + { + mIsRunning = false; + } + if(event.type != SDL_KEYDOWN && event.type != SDL_KEYUP) + { + continue; + } + + switch (gNowScene) + { + case START: + mStart->Input(event); + break; + + case HOME: + mHome->Input(event); + break; + + case DUNGEON_MENU: + mDungeonMenu->Input(event); + break; + + case DUNGEON_AREA_DIVIDE: + case DUNGEON_RRA: + mDungeon->Input(event); + break; + + case CONGRATULATIONS: + mCongratulations->Input(event); + break; + + case GAME_OVER: + mGameOver->Input(event); + break; + } + } + const Uint8 *state = SDL_GetKeyboardState(NULL); + if (state[SDL_SCANCODE_ESCAPE]) mIsRunning = false; +} + +//画面の切り替わり後はここから +void Game::Update() +{ + switch (gNowScene) + { + case START: + mStart->Update(); + break; + case HOME: + mHome->Update(); + break; + case DUNGEON_MENU: + mDungeonMenu->Update(); + break; + case DUNGEON_AREA_DIVIDE: + case DUNGEON_RRA: + mDungeon->Update(); + break; + case CONGRATULATIONS: + mCongratulations->Update(); + break; + case GAME_OVER: + mGameOver->Update(); + break; + } +} + +void Game::Output() +{ + SDL_SetRenderDrawColor(gRenderer, 50, 50, 50, 255); + SDL_RenderClear(gRenderer); + + switch (gNowScene) + { + case START: + mStart->Output(); + break; + case HOME: + mHome->Output(); + break; + case DUNGEON_MENU: + mDungeonMenu->Output(); + break; + case DUNGEON_AREA_DIVIDE: + case DUNGEON_RRA: + mDungeon->Output(); + break; + case CONGRATULATIONS: + mCongratulations->Output(); + break; + case GAME_OVER: + mGameOver->Output(); + break; + } + + SDL_RenderPresent(gRenderer); +} + +void Game::Shutdown() +{ + Mix_HaltMusic(); + Mix_FreeMusic(mMusic); + mMusic = NULL; + Mix_FreeChunk(gClickEffect); + gClickEffect = NULL; + Mix_CloseAudio(); + + + delete mStart; + mStart = nullptr; + delete mHome; + mHome = nullptr; + delete mDungeonMenu; + mDungeonMenu = nullptr; + delete mDungeon; + mDungeon = nullptr; + delete mCongratulations; + mCongratulations = nullptr; + delete mGameOver; + mGameOver = nullptr; + + // try { + // delete mStart; + // delete mHome; + // delete mDungeonMenu; + // delete mDungeon; + // delete mCongratulations; + // delete mGameOver; + + // } catch (const std::exception& e) { + // std::cout << "class" << std::endl; + // std::cout << e.what() << std::endl; + // } + + SDL_DestroyRenderer(gRenderer); + gRenderer = NULL; + SDL_DestroyWindow(gWindow); + gWindow = NULL; + + IMG_Quit(); + TTF_Quit(); + Mix_Quit(); + + SDL_Quit(); +} diff --git a/src/Game.h b/src/Core/Game.h similarity index 87% rename from src/Game.h rename to src/Core/Game.h index a9ceb7b..359de05 100644 --- a/src/Game.h +++ b/src/Core/Game.h @@ -1,46 +1,46 @@ -#pragma once - -#include -#include - -#include -#include -#include -#include "../SDL2/SDL_mixer.h" - -#include "Functions/Util.h" - -#include "Scene/1_Start.h" -#include "Scene/2_Home.h" -#include "Scene/3_DungeonMenu.h" -#include "Scene/4_Dungeon.h" -#include "Scene/5_Congratulations.h" -#include "Scene/6_GameOver.h" - -class Game -{ -public: - Game(); - ~Game(); - - bool Init(); - void RunLoop(); - void Shutdown(); - -private: - void Input(); - void Update(); - void Output(); - - SDL_Event event; - Mix_Music* mMusic; - - bool mIsRunning; - - class Start *mStart; - class Home *mHome; - class DungeonMenu *mDungeonMenu; - class Dungeon *mDungeon; - class Congratulations *mCongratulations; - class GameOver *mGameOver; -}; +#pragma once + +#include +#include + +#include +#include +#include +#include + +#include "Utils/Util.h" + +#include "Scene/1_Start.h" +#include "Scene/2_Home.h" +#include "Scene/3_DungeonMenu.h" +#include "Scene/4_Dungeon.h" +#include "Scene/5_Congratulations.h" +#include "Scene/6_GameOver.h" + +class Game +{ +public: + Game(); + ~Game(); + + bool Init(); + void RunLoop(); + void Shutdown(); + +private: + void Input(); + void Update(); + void Output(); + + SDL_Event event; + Mix_Music* mMusic; + + bool mIsRunning; + + class Start *mStart; + class Home *mHome; + class DungeonMenu *mDungeonMenu; + class Dungeon *mDungeon; + class Congratulations *mCongratulations; + class GameOver *mGameOver; +}; diff --git a/src/main.cpp b/src/Core/main.cpp similarity index 85% rename from src/main.cpp rename to src/Core/main.cpp index d19d30a..50fa3c2 100644 --- a/src/main.cpp +++ b/src/Core/main.cpp @@ -1,15 +1,15 @@ -#define __DEBUG_ - -#include "Game.h" - -int main(int argc, char **argv) -{ - Game game; - bool success = game.Init(); - if(success) - { - game.RunLoop(); - } - game.Shutdown(); - return 0; +#define __DEBUG_ + +#include "Core/Game.h" + +int main(int argc, char **argv) +{ + Game game; + bool success = game.Init(); + if(success) + { + game.RunLoop(); + } + game.Shutdown(); + return 0; } \ No newline at end of file diff --git a/src/AreaDivide.cpp b/src/GenerateDungeon/AreaDivide.cpp similarity index 100% rename from src/AreaDivide.cpp rename to src/GenerateDungeon/AreaDivide.cpp diff --git a/src/GenerateDungeon/AreaDivide.h b/src/GenerateDungeon/AreaDivide.h index f6752b0..f183032 100644 --- a/src/GenerateDungeon/AreaDivide.h +++ b/src/GenerateDungeon/AreaDivide.h @@ -1,13 +1,13 @@ -#pragma once - -#include "Generator.h" - -class AreaDivide : public Generator -{ -public: - void generate(); - -private: - void divide(int ID); - -}; +#pragma once + +#include "GenerateDungeon/Generator.h" + +class AreaDivide : public Generator +{ +public: + void generate(); + +private: + void divide(int ID); + +}; diff --git a/src/Generator.cpp b/src/GenerateDungeon/Generator.cpp similarity index 99% rename from src/Generator.cpp rename to src/GenerateDungeon/Generator.cpp index 8fc84db..da950f8 100644 --- a/src/Generator.cpp +++ b/src/GenerateDungeon/Generator.cpp @@ -1,5 +1,5 @@ #include "GenerateDungeon/Generator.h" -#include "Functions/Util.h" +#include "Utils/Util.h" std::random_device random_seed; std::mt19937 random_engine(random_seed()); diff --git a/src/GenerateDungeon/Generator.h b/src/GenerateDungeon/Generator.h index aa7576e..efaa155 100644 --- a/src/GenerateDungeon/Generator.h +++ b/src/GenerateDungeon/Generator.h @@ -1,49 +1,49 @@ -#pragma once - -#include -#include -#include -#include -#include -#include "../../Ivec2.h" - -#include "Area.h" -#include "Room.h" -#include "Player.h" -#include "Enemy.h" -#include "Enum.h" -#include "Const.h" - -class Generator -{ -public: - Generator(); - ~Generator(); - - Area getArea(int id) { return areas[id]; } - Room getRoom(int id) { return rooms[id]; } - int getAreaNum() { return areas.size(); } - int getRoomNum() { return rooms.size(); } - - /// @brief ランダムなデータ系座標を返す - Ivec2 getRandomFloorDataPos(); - - int areaCount = 0; - int randomNumber; - - CELL_TYPE buff[BUFF_FLOOR_H][BUFF_FLOOR_W]; - -protected: - void initFloor(); - void fillSurround(); - void eraseDeadEnd(); - void randomEraseDeadEnd(); - void identificationWallKind(); - void outputMap(); - - void outputMap_forDebug(); - - CELL_TYPE floorTYPE[FLOOR_H][FLOOR_W]; - std::vector areas = std::vector(1, Area(0, 0, FLOOR_W, FLOOR_H)); - std::vector rooms = std::vector(1, Room(ROOM_MARGIN, ROOM_MARGIN, FLOOR_W - 2*ROOM_MARGIN, FLOOR_H - 2*ROOM_MARGIN)); -}; +#pragma once + +#include +#include +#include +#include +#include +#include "Utils/Ivec2.h" + +#include "GenerateDungeon/Area.h" +#include "GenerateDungeon/Room.h" +#include "Characters/Player.h" +#include "Characters/Enemy.h" +#include "GenerateDungeon/Enum.h" +#include "GenerateDungeon/Const.h" + +class Generator +{ +public: + Generator(); + ~Generator(); + + Area getArea(int id) { return areas[id]; } + Room getRoom(int id) { return rooms[id]; } + int getAreaNum() { return areas.size(); } + int getRoomNum() { return rooms.size(); } + + /// @brief ランダムなデータ系座標を返す + Ivec2 getRandomFloorDataPos(); + + int areaCount = 0; + int randomNumber; + + CELL_TYPE buff[BUFF_FLOOR_H][BUFF_FLOOR_W]; + +protected: + void initFloor(); + void fillSurround(); + void eraseDeadEnd(); + void randomEraseDeadEnd(); + void identificationWallKind(); + void outputMap(); + + void outputMap_forDebug(); + + CELL_TYPE floorTYPE[FLOOR_H][FLOOR_W]; + std::vector areas = std::vector(1, Area(0, 0, FLOOR_W, FLOOR_H)); + std::vector rooms = std::vector(1, Room(ROOM_MARGIN, ROOM_MARGIN, FLOOR_W - 2*ROOM_MARGIN, FLOOR_H - 2*ROOM_MARGIN)); +}; diff --git a/src/RRA.cpp b/src/GenerateDungeon/RRA.cpp similarity index 100% rename from src/RRA.cpp rename to src/GenerateDungeon/RRA.cpp diff --git a/src/GenerateDungeon/RRA.h b/src/GenerateDungeon/RRA.h index a2949c9..4238e58 100644 --- a/src/GenerateDungeon/RRA.h +++ b/src/GenerateDungeon/RRA.h @@ -1,9 +1,9 @@ -#pragma once - -#include "Generator.h" - -class RRA : public Generator -{ -public: - void generate(); -}; +#pragma once + +#include "GenerateDungeon/Generator.h" + +class RRA : public Generator +{ +public: + void generate(); +}; diff --git a/src/GenerateDungeon/Room.h b/src/GenerateDungeon/Room.h index c2c6eaf..e2ae749 100644 --- a/src/GenerateDungeon/Room.h +++ b/src/GenerateDungeon/Room.h @@ -1,35 +1,35 @@ -#pragma once - -#include "Area.h" -#include "Const.h" - -const int ROOM_MARGIN = 2; - -class Room -{ -public: - Room() - { - x = y = 0; - w = h = 0; - }; - Room(int _x, int _y, int _w, int _h) - :x(_x), y(_y), w(_w), h(_h){}; - Room(Area area) - { - x = area.x + ROOM_MARGIN; - y = area.y + ROOM_MARGIN; - w = area.w - 2*ROOM_MARGIN; - h = area.h - 2*ROOM_MARGIN; - } - - void operator = (Room room) - { - x = room.x; - y = room.y; - w = room.w; - h = room.h; - } - - int x, y, w, h; -}; +#pragma once + +#include "GenerateDungeon/Area.h" +#include "GenerateDungeon/Const.h" + +const int ROOM_MARGIN = 2; + +class Room +{ +public: + Room() + { + x = y = 0; + w = h = 0; + }; + Room(int _x, int _y, int _w, int _h) + :x(_x), y(_y), w(_w), h(_h){}; + Room(Area area) + { + x = area.x + ROOM_MARGIN; + y = area.y + ROOM_MARGIN; + w = area.w - 2*ROOM_MARGIN; + h = area.h - 2*ROOM_MARGIN; + } + + void operator = (Room room) + { + x = room.x; + y = room.y; + w = room.w; + h = room.h; + } + + int x, y, w, h; +}; diff --git a/src/Tile.cpp b/src/GenerateDungeon/Tile.cpp similarity index 100% rename from src/Tile.cpp rename to src/GenerateDungeon/Tile.cpp diff --git a/src/GenerateDungeon/Tile.h b/src/GenerateDungeon/Tile.h index 5827632..3aa9696 100644 --- a/src/GenerateDungeon/Tile.h +++ b/src/GenerateDungeon/Tile.h @@ -2,10 +2,10 @@ #include -#include "Enum.h" -#include "Const.h" -#include "LTexture.h" -#include "../Functions/RectUtils.h" +#include "GenerateDungeon/Enum.h" +#include "GenerateDungeon/Const.h" +#include "System/LTexture.h" +#include "Utils/RectUtils.h" //タイルクラス class Tile diff --git a/src/1_Start.cpp b/src/Scene/1_Start.cpp similarity index 100% rename from src/1_Start.cpp rename to src/Scene/1_Start.cpp diff --git a/src/Scene/1_Start.h b/src/Scene/1_Start.h index 527785d..83d9b45 100644 --- a/src/Scene/1_Start.h +++ b/src/Scene/1_Start.h @@ -1,28 +1,28 @@ -#pragma once - -#include -#include -#include -#include - -#include "../UI/Button.h" -#include "../Functions/Color.h" -#include "../GenerateDungeon/Const.h" -#include "../GenerateDungeon/Enum.h" - -class Start -{ -public: - Start(); - ~Start(); - - void Input(SDL_Event event); - void Update(); - void Output(); - -private: - void LoadData(); - void PlayMusic(); - - Button mStartButton; -}; +#pragma once + +#include +#include +#include +#include + +#include "UI/Button.h" +#include "Utils/Color.h" +#include "GenerateDungeon/Const.h" +#include "GenerateDungeon/Enum.h" + +class Start +{ +public: + Start(); + ~Start(); + + void Input(SDL_Event event); + void Update(); + void Output(); + +private: + void LoadData(); + void PlayMusic(); + + Button mStartButton; +}; diff --git a/src/2_Home.cpp b/src/Scene/2_Home.cpp similarity index 100% rename from src/2_Home.cpp rename to src/Scene/2_Home.cpp diff --git a/src/Scene/2_Home.h b/src/Scene/2_Home.h index 515c7a8..6a264ea 100644 --- a/src/Scene/2_Home.h +++ b/src/Scene/2_Home.h @@ -5,13 +5,13 @@ #include #include -#include "../UI/Button.h" -#include "../Functions/Color.h" -#include "../Functions/Util.h" -#include "../GenerateDungeon/Const.h" -#include "../GenerateDungeon/LTexture.h" +#include "UI/Button.h" +#include "Utils/Color.h" +#include "Utils/Util.h" +#include "GenerateDungeon/Const.h" +#include "System/LTexture.h" -#include "../Game.h" +#include "Core/Game.h" class Home { diff --git a/src/3_DungeonMenu.cpp b/src/Scene/3_DungeonMenu.cpp similarity index 100% rename from src/3_DungeonMenu.cpp rename to src/Scene/3_DungeonMenu.cpp diff --git a/src/Scene/3_DungeonMenu.h b/src/Scene/3_DungeonMenu.h index 191bd09..5701545 100644 --- a/src/Scene/3_DungeonMenu.h +++ b/src/Scene/3_DungeonMenu.h @@ -1,31 +1,31 @@ -#pragma once - -#include -#include -#include -#include - -#include "../UI/Button.h" -#include "../Functions/Color.h" -#include "../GenerateDungeon/Const.h" -#include "../GenerateDungeon/Enum.h" - -#include "../Game.h" - -class DungeonMenu -{ -public: - DungeonMenu(); - ~DungeonMenu(); - - void Input(SDL_Event event); - void Update(); - void Output(); - -private: - void LoadData(); - void PlayMusic(); - - Button mAreaDivide; - Button mRRA; -}; +#pragma once + +#include +#include +#include +#include + +#include "UI/Button.h" +#include "Utils/Color.h" +#include "GenerateDungeon/Const.h" +#include "GenerateDungeon/Enum.h" + +#include "Core/Game.h" + +class DungeonMenu +{ +public: + DungeonMenu(); + ~DungeonMenu(); + + void Input(SDL_Event event); + void Update(); + void Output(); + +private: + void LoadData(); + void PlayMusic(); + + Button mAreaDivide; + Button mRRA; +}; diff --git a/src/4_Dungeon.cpp b/src/Scene/4_Dungeon.cpp similarity index 100% rename from src/4_Dungeon.cpp rename to src/Scene/4_Dungeon.cpp diff --git a/src/Scene/4_Dungeon.h b/src/Scene/4_Dungeon.h index b573192..cbc71cd 100644 --- a/src/Scene/4_Dungeon.h +++ b/src/Scene/4_Dungeon.h @@ -1,101 +1,100 @@ -#pragma once - -#include -#include -#include -#include -#include -#include "../../Ivec2.h" - -#include "../UI/Log.h" -#include "../Functions/Color.h" -#include "../Functions/Util.h" -#include "../GenerateDungeon/Const.h" -#include "../GenerateDungeon/Enum.h" - -#include "../GenerateDungeon/AreaDivide.h" -#include "../GenerateDungeon/RRA.h" - -#include "../GenerateDungeon/Player.h" -#include "../GenerateDungeon/Enemy.h" -#include "../GenerateDungeon/Const.h" -#include "../GenerateDungeon/Tile.h" -#include "../GenerateDungeon/LTexture.h" - -#include "../Game.h" - -enum GOAL_TYPE -{ - RANDOM_POS, - PLAYER_POS -}; - -class Dungeon -{ -public: - Dungeon(); - ~Dungeon(); - - void Input(SDL_Event event); - void Update(); - void Output(); - -// ダンジョン生成 - void InitDungeon(); - void quit(); - - bool in_dungeon; - -private: - bool LoadData(); - void PlayMusic(); - - //.mapファイルからタイルをセット - bool setTiles(); - - void updateEnemyRoute(Enemy& _enemy, GOAL_TYPE _goleType); - - /// @brief 座標に自身以外のキャラが居るか - /// @param _data_pos データ系座標 - /// @return 座標にいるキャラの数 - int isOtherPos(Ivec2 _data_pos); - - /// @brief 引数の位置に移動できるか判定する - /// @param _data_pos データ系座標 - /// @return 移動できるなら true - bool canGetOn(Ivec2 _data_pos); - - /// @brief ランダムな座標を返す - /// @param _roomCount - /// @return データ系座標 - Ivec2 getRandomDataPos(int _roomCount); - - /// @brief 座標にいる敵を返す - /// @param _data_pos - /// @return 敵の参照を返す - Enemy& whichEnemy(Ivec2 _data_pos); - - // ダンジョン生成フラグ - bool go_next_floor; - - CELL_TYPE floor[FLOOR_H][FLOOR_W]; - - AreaDivide area_divide; - RRA rra; - - Player player = Player(0, 0, PLAYER_HP, PLAYER_STR, PLAYER_VIT); - std::vector enemies = std::vector(NUM_ENEMY, Enemy(DEKA, 0)); - - std::vector tileSet; - - SDL_Rect camera; - std::vector mPlayerSpriteClips; - std::vector> enemy_sprite_clips; - - CHAR_TYPE nowTurn; - - Log log; - - int floor_num; -}; - +#pragma once + +#include +#include +#include +#include +#include +#include "Utils/Ivec2.h" + +#include "UI/Log.h" +#include "Utils/Color.h" +#include "Utils/Util.h" +#include "GenerateDungeon/Const.h" +#include "GenerateDungeon/Enum.h" + +#include "GenerateDungeon/AreaDivide.h" +#include "GenerateDungeon/RRA.h" + +#include "Characters/Player.h" +#include "Characters/Enemy.h" +#include "GenerateDungeon/Const.h" +#include "GenerateDungeon/Tile.h" +#include "System/LTexture.h" + +#include "Core/Game.h" + +enum GOAL_TYPE +{ + RANDOM_POS, + PLAYER_POS +}; + +class Dungeon +{ +public: + Dungeon(); + ~Dungeon(); + + void Input(SDL_Event event); + void Update(); + void Output(); + +// ダンジョン生成 + void InitDungeon(); + void quit(); + + bool in_dungeon; + +private: + bool LoadData(); + void PlayMusic(); + + //.mapファイルからタイルをセット + bool setTiles(); + + void updateEnemyRoute(Enemy& _enemy, GOAL_TYPE _goleType); + + /// @brief 座標に自身以外のキャラが居るか + /// @param _data_pos データ系座標 + /// @return 座標にいるキャラの数 + int isOtherPos(Ivec2 _data_pos); + + /// @brief 引数の位置に移動できるか判定する + /// @param _data_pos データ系座標 + /// @return 移動できるなら true + bool canGetOn(Ivec2 _data_pos); + + /// @brief ランダムな座標を返す + /// @param _roomCount + /// @return データ系座標 + Ivec2 getRandomDataPos(int _roomCount); + + /// @brief 座標にいる敵を返す + /// @param _data_pos + /// @return 敵の参照を返す + Enemy& whichEnemy(Ivec2 _data_pos); + + // ダンジョン生成フラグ + bool go_next_floor; + + CELL_TYPE floor[FLOOR_H][FLOOR_W]; + + AreaDivide area_divide; + RRA rra; + + Player player = Player(0, 0, PLAYER_HP, PLAYER_STR, PLAYER_VIT); + std::vector enemies = std::vector(NUM_ENEMY, Enemy(DEKA, 0)); + + std::vector tileSet; + + SDL_Rect camera; + std::vector mPlayerSpriteClips; + std::vector> enemy_sprite_clips; + + CHAR_TYPE nowTurn; + + Log log; + + int floor_num; +}; diff --git a/src/5_Congratulations.cpp b/src/Scene/5_Congratulations.cpp similarity index 100% rename from src/5_Congratulations.cpp rename to src/Scene/5_Congratulations.cpp diff --git a/src/Scene/5_Congratulations.h b/src/Scene/5_Congratulations.h index 576a3d0..b619f61 100644 --- a/src/Scene/5_Congratulations.h +++ b/src/Scene/5_Congratulations.h @@ -5,12 +5,12 @@ #include #include -#include "../UI/Button.h" -#include "../Functions/Color.h" -#include "../GenerateDungeon/Const.h" -#include "../GenerateDungeon/Enum.h" +#include "UI/Button.h" +#include "Utils/Color.h" +#include "GenerateDungeon/Const.h" +#include "GenerateDungeon/Enum.h" -#include "../Game.h" +#include "Core/Game.h" class Congratulations { diff --git a/src/6_GameOver.cpp b/src/Scene/6_GameOver.cpp similarity index 100% rename from src/6_GameOver.cpp rename to src/Scene/6_GameOver.cpp diff --git a/src/Scene/6_GameOver.h b/src/Scene/6_GameOver.h index 8762ac4..141f5dd 100644 --- a/src/Scene/6_GameOver.h +++ b/src/Scene/6_GameOver.h @@ -5,12 +5,12 @@ #include #include -#include "../UI/Button.h" -#include "../Functions/Color.h" -#include "../GenerateDungeon/Const.h" -#include "../GenerateDungeon/Enum.h" +#include "UI/Button.h" +#include "Utils/Color.h" +#include "GenerateDungeon/Const.h" +#include "GenerateDungeon/Enum.h" -#include "../Game.h" +#include "Core/Game.h" class GameOver { diff --git a/src/AStar.cpp b/src/System/AStar.cpp similarity index 99% rename from src/AStar.cpp rename to src/System/AStar.cpp index 51ae5b2..9109ccb 100644 --- a/src/AStar.cpp +++ b/src/System/AStar.cpp @@ -1,4 +1,4 @@ -#include "GenerateDungeon/AStar.h" +#include "System/AStar.h" namespace AStar { diff --git a/src/GenerateDungeon/AStar.h b/src/System/AStar.h similarity index 86% rename from src/GenerateDungeon/AStar.h rename to src/System/AStar.h index 87f9997..9865e4d 100644 --- a/src/GenerateDungeon/AStar.h +++ b/src/System/AStar.h @@ -1,31 +1,31 @@ -#pragma once - -#include - -#include "../../Ivec2.h" - -#include "Enum.h" -#include "Const.h" - -namespace AStar{ - // マンハッタン距離を求める - int GetDistance(int from_x, int from_y); - - // スタート位置から現在地までのコスト集計 - int BackTrace(int x, int y); - - // A*で経路探査する - int Search(); - - // ゴールから逆算 - void TraceRoute(int x, int y); - - std::deque AStar(CELL_TYPE def_data[FLOOR_H][FLOOR_W], Ivec2 _start, Ivec2 _goal); - - // 4方向のベクトル設定 - extern Ivec2 CheckMatrix[4]; - - extern MAPCELL astar_map_data[FLOOR_H][FLOOR_W]; - extern Ivec2 start, goal; - extern std::deque astar_route; -} +#pragma once + +#include + +#include "Utils/Ivec2.h" + +#include "GenerateDungeon/Enum.h" +#include "GenerateDungeon/Const.h" + +namespace AStar{ + // マンハッタン距離を求める + int GetDistance(int from_x, int from_y); + + // スタート位置から現在地までのコスト集計 + int BackTrace(int x, int y); + + // A*で経路探査する + int Search(); + + // ゴールから逆算 + void TraceRoute(int x, int y); + + std::deque AStar(CELL_TYPE def_data[FLOOR_H][FLOOR_W], Ivec2 _start, Ivec2 _goal); + + // 4方向のベクトル設定 + extern Ivec2 CheckMatrix[4]; + + extern MAPCELL astar_map_data[FLOOR_H][FLOOR_W]; + extern Ivec2 start, goal; + extern std::deque astar_route; +} diff --git a/src/LTexture.cpp b/src/System/LTexture.cpp similarity index 94% rename from src/LTexture.cpp rename to src/System/LTexture.cpp index afcc2ab..515736c 100644 --- a/src/LTexture.cpp +++ b/src/System/LTexture.cpp @@ -1,169 +1,169 @@ -#include "GenerateDungeon/LTexture.h" - -extern SDL_Renderer *gRenderer; - -LTexture::LTexture() -{ - //初期化 - mTexture = NULL; - mWidth = 0; - mHeight = 0; -} - -LTexture::~LTexture() -{ - //割り当て解除 - free(); -} - -bool LTexture::loadFromFile( std::string path ) -{ - //既存のテクスチャを取り除く - free(); - - //返り値のテクスチャ - SDL_Texture* newTexture = NULL; - - //指定パスから画像を読み込み - SDL_Surface* loadedSurface = IMG_Load( path.c_str() ); - if( loadedSurface == NULL ) - { - SDL_Log( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() ); - } - else - { - //画像のキーカラー - SDL_SetColorKey( loadedSurface, SDL_TRUE, SDL_MapRGB( loadedSurface->format, 0, 0xFF, 0xFF ) ); - - //表層ピクセルからテクスチャを作成 - newTexture = SDL_CreateTextureFromSurface( gRenderer, loadedSurface ); - if( newTexture == NULL ) - { - SDL_Log( "Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError() ); - } - else - { - //画像の寸法取得 - mWidth = loadedSurface->w; - mHeight = loadedSurface->h; - } - - //読み込んだSurfaceを開放 - SDL_FreeSurface( loadedSurface ); - } - - //成功したか返す - mTexture = newTexture; - return mTexture != NULL; -} - -#if defined(SDL_TTF_MAJOR_VERSION) -bool LTexture::loadFromRenderedText( std::string textureText, SDL_Color textColor ) -{ - //既存のテクスチャを取り除く - free(); - - //テキストをレンダリング - SDL_Surface* textSurface = TTF_RenderText_Solid( dungeon_g->getFontN(), textureText.c_str(), textColor ); - if( textSurface != NULL ) - { - //表層ピクセルからテクスチャを作成 - mTexture = SDL_CreateTextureFromSurface( dungeon_g->getRenderer(), textSurface ); - if( mTexture == NULL ) - { - SDL_Log( "Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError() ); - } - else - { - //画像の寸法取得 - mWidth = textSurface->w; - mHeight = textSurface->h; - } - - //Surfaceを開放 - SDL_FreeSurface( textSurface ); - } - else - { - SDL_Log( "Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError() ); - } - - - //成功したか返す - return mTexture != NULL; -} -#endif - -void LTexture::free() -{ - //テクスチャがあるときは開放 - if( mTexture != NULL ) - { - SDL_DestroyTexture( mTexture ); - mTexture = NULL; - mWidth = 0; - mHeight = 0; - } -} - -void LTexture::setColor( Uint8 red, Uint8 green, Uint8 blue ) -{ - //テクスチャRGBを調整する - SDL_SetTextureColorMod( mTexture, red, green, blue ); -} - -void LTexture::setBlendMode( SDL_BlendMode blending ) -{ - //ブレンド関数の設定 - SDL_SetTextureBlendMode( mTexture, blending ); -} - -void LTexture::setAlpha( Uint8 alpha ) -{ - //テクスチャアルファを調整する - SDL_SetTextureAlphaMod( mTexture, alpha ); -} - -void LTexture::setW( int width ) -{ - mWidth = width; -} - -void LTexture::setH( int height ) -{ - mHeight = height; -} - -void LTexture::render( int x, int y, SDL_Rect* clip, bool filter, double angle, SDL_Point* center, SDL_RendererFlip flip ) -{ - //レンダリングスペースを設定し、画面にレンダリング - SDL_Rect renderQuad = { x, y, mWidth, mHeight }; - - //クリップのレンダリング寸法を設定する - if( clip != NULL ) - { - renderQuad.w = clip->w; - renderQuad.h = clip->h; - } - //画面にレンダリングする - SDL_RenderCopyEx( gRenderer, mTexture, clip, &renderQuad, angle, center, flip ); - -//REVIEW デバッグ用 - // if( filter ) - // { - // SDL_SetRenderDrawColor(gRenderer, 0xFF, 0x00, 0x00, 0xAA); - // SDL_RenderFillRect(gRenderer, &renderQuad); - // } - // SDL_SetRenderDrawColor(gRenderer, 0xFF, 0x00, 0x00, 0xFF); - // SDL_RenderDrawRect(gRenderer, &renderQuad); -} - -int LTexture::getWidth() -{ - return mWidth; -} - -int LTexture::getHeight() -{ - return mHeight; -} +#include "System/LTexture.h" + +extern SDL_Renderer *gRenderer; + +LTexture::LTexture() +{ + //初期化 + mTexture = NULL; + mWidth = 0; + mHeight = 0; +} + +LTexture::~LTexture() +{ + //割り当て解除 + free(); +} + +bool LTexture::loadFromFile( std::string path ) +{ + //既存のテクスチャを取り除く + free(); + + //返り値のテクスチャ + SDL_Texture* newTexture = NULL; + + //指定パスから画像を読み込み + SDL_Surface* loadedSurface = IMG_Load( path.c_str() ); + if( loadedSurface == NULL ) + { + SDL_Log( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() ); + } + else + { + //画像のキーカラー + SDL_SetColorKey( loadedSurface, SDL_TRUE, SDL_MapRGB( loadedSurface->format, 0, 0xFF, 0xFF ) ); + + //表層ピクセルからテクスチャを作成 + newTexture = SDL_CreateTextureFromSurface( gRenderer, loadedSurface ); + if( newTexture == NULL ) + { + SDL_Log( "Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError() ); + } + else + { + //画像の寸法取得 + mWidth = loadedSurface->w; + mHeight = loadedSurface->h; + } + + //読み込んだSurfaceを開放 + SDL_FreeSurface( loadedSurface ); + } + + //成功したか返す + mTexture = newTexture; + return mTexture != NULL; +} + +#if defined(SDL_TTF_MAJOR_VERSION) +bool LTexture::loadFromRenderedText( std::string textureText, SDL_Color textColor ) +{ + //既存のテクスチャを取り除く + free(); + + //テキストをレンダリング + SDL_Surface* textSurface = TTF_RenderText_Solid( dungeon_g->getFontN(), textureText.c_str(), textColor ); + if( textSurface != NULL ) + { + //表層ピクセルからテクスチャを作成 + mTexture = SDL_CreateTextureFromSurface( dungeon_g->getRenderer(), textSurface ); + if( mTexture == NULL ) + { + SDL_Log( "Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError() ); + } + else + { + //画像の寸法取得 + mWidth = textSurface->w; + mHeight = textSurface->h; + } + + //Surfaceを開放 + SDL_FreeSurface( textSurface ); + } + else + { + SDL_Log( "Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError() ); + } + + + //成功したか返す + return mTexture != NULL; +} +#endif + +void LTexture::free() +{ + //テクスチャがあるときは開放 + if( mTexture != NULL ) + { + SDL_DestroyTexture( mTexture ); + mTexture = NULL; + mWidth = 0; + mHeight = 0; + } +} + +void LTexture::setColor( Uint8 red, Uint8 green, Uint8 blue ) +{ + //テクスチャRGBを調整する + SDL_SetTextureColorMod( mTexture, red, green, blue ); +} + +void LTexture::setBlendMode( SDL_BlendMode blending ) +{ + //ブレンド関数の設定 + SDL_SetTextureBlendMode( mTexture, blending ); +} + +void LTexture::setAlpha( Uint8 alpha ) +{ + //テクスチャアルファを調整する + SDL_SetTextureAlphaMod( mTexture, alpha ); +} + +void LTexture::setW( int width ) +{ + mWidth = width; +} + +void LTexture::setH( int height ) +{ + mHeight = height; +} + +void LTexture::render( int x, int y, SDL_Rect* clip, bool filter, double angle, SDL_Point* center, SDL_RendererFlip flip ) +{ + //レンダリングスペースを設定し、画面にレンダリング + SDL_Rect renderQuad = { x, y, mWidth, mHeight }; + + //クリップのレンダリング寸法を設定する + if( clip != NULL ) + { + renderQuad.w = clip->w; + renderQuad.h = clip->h; + } + //画面にレンダリングする + SDL_RenderCopyEx( gRenderer, mTexture, clip, &renderQuad, angle, center, flip ); + +//REVIEW デバッグ用 + // if( filter ) + // { + // SDL_SetRenderDrawColor(gRenderer, 0xFF, 0x00, 0x00, 0xAA); + // SDL_RenderFillRect(gRenderer, &renderQuad); + // } + // SDL_SetRenderDrawColor(gRenderer, 0xFF, 0x00, 0x00, 0xFF); + // SDL_RenderDrawRect(gRenderer, &renderQuad); +} + +int LTexture::getWidth() +{ + return mWidth; +} + +int LTexture::getHeight() +{ + return mHeight; +} diff --git a/src/GenerateDungeon/LTexture.h b/src/System/LTexture.h similarity index 93% rename from src/GenerateDungeon/LTexture.h rename to src/System/LTexture.h index d992689..9cf6836 100644 --- a/src/GenerateDungeon/LTexture.h +++ b/src/System/LTexture.h @@ -1,7 +1,7 @@ #pragma once #include -#include "../../include/SDL2/SDL_image.h" +#include //テクスチャーラッパークラス class LTexture diff --git a/src/UI/Button.h b/src/UI/Button.h index a61e9ff..a537a77 100644 --- a/src/UI/Button.h +++ b/src/UI/Button.h @@ -1,93 +1,93 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "../Functions/Color.h" - -class Button -{ -public: - void create( - SDL_Renderer *renderer, - int x, int y, int w, int h, std::string text, TTF_Font *font, - SDL_Color buttonColor, SDL_Color textColor) - { - mRenderer = renderer; - SDL_Surface *surface = TTF_RenderUTF8_Blended(font, text.c_str(), textColor); - - mButtonColor = buttonColor; - mButtonRect = {x, y+diffLevel*hierarchy, w-diffLevel*hierarchy*2, h-diffLevel*hierarchy*2}; - - mTexture = SDL_CreateTextureFromSurface(mRenderer, surface); - - SDL_FreeSurface(surface); - } - - void Draw() - { - SDL_Color buffColor; - buffColor.r = 100; - buffColor.g = 100; - buffColor.b = 100; - buffColor.a = 255; - SDL_Color diffColor; - diffColor.r = (mButtonColor.r - buffColor.r) / (hierarchy+2); - diffColor.g = (mButtonColor.g - buffColor.g) / (hierarchy+2); - diffColor.b = (mButtonColor.b - buffColor.b) / (hierarchy+2); - SDL_Rect buffRect = mButtonRect; - - for(int i=0; i +#include +#include +#include +#include + +#include "Utils/Color.h" + +class Button +{ +public: + void create( + SDL_Renderer *renderer, + int x, int y, int w, int h, std::string text, TTF_Font *font, + SDL_Color buttonColor, SDL_Color textColor) + { + mRenderer = renderer; + SDL_Surface *surface = TTF_RenderUTF8_Blended(font, text.c_str(), textColor); + + mButtonColor = buttonColor; + mButtonRect = {x, y+diffLevel*hierarchy, w-diffLevel*hierarchy*2, h-diffLevel*hierarchy*2}; + + mTexture = SDL_CreateTextureFromSurface(mRenderer, surface); + + SDL_FreeSurface(surface); + } + + void Draw() + { + SDL_Color buffColor; + buffColor.r = 100; + buffColor.g = 100; + buffColor.b = 100; + buffColor.a = 255; + SDL_Color diffColor; + diffColor.r = (mButtonColor.r - buffColor.r) / (hierarchy+2); + diffColor.g = (mButtonColor.g - buffColor.g) / (hierarchy+2); + diffColor.b = (mButtonColor.b - buffColor.b) / (hierarchy+2); + SDL_Rect buffRect = mButtonRect; + + for(int i=0; i #include -#include "../GenerateDungeon/Const.h" -#include "../Functions/Util.h" +#include "GenerateDungeon/Const.h" +#include "Utils/Util.h" class Log { diff --git a/src/Functions/Color.h b/src/Utils/Color.h similarity index 100% rename from src/Functions/Color.h rename to src/Utils/Color.h diff --git a/Ivec2.h b/src/Utils/Ivec2.h similarity index 100% rename from Ivec2.h rename to src/Utils/Ivec2.h diff --git a/src/Functions/RectUtils.h b/src/Utils/RectUtils.h similarity index 100% rename from src/Functions/RectUtils.h rename to src/Utils/RectUtils.h diff --git a/src/Functions/Texture.h b/src/Utils/Texture.h similarity index 91% rename from src/Functions/Texture.h rename to src/Utils/Texture.h index 051f4c2..4d17b4b 100644 --- a/src/Functions/Texture.h +++ b/src/Utils/Texture.h @@ -2,7 +2,7 @@ #include #include -#include "../../include/SDL2/SDL_image.h" +#include SDL_Texture* loadTexture(std::string path, SDL_Renderer* renderer) { //The return texture diff --git a/src/Functions/Util.h b/src/Utils/Util.h similarity index 78% rename from src/Functions/Util.h rename to src/Utils/Util.h index cd59e1f..d1fe7a8 100644 --- a/src/Functions/Util.h +++ b/src/Utils/Util.h @@ -5,13 +5,14 @@ inline std::string resource_path(const char* relative_path) { const char* appdir = getenv("APPDIR"); + std::string full_path; if (appdir) { // AppImage内で実行されている場合 - return std::string(appdir) + "/usr/share/rogue/assets/" + relative_path; + full_path = std::string(appdir) + "/usr/share/rogue/assets/" + relative_path; } else { // 通常の実行の場合 - return std::string("assets/") + relative_path; + full_path = std::string("assets/") + relative_path; } return full_path; diff --git a/test.cpp b/test.cpp index 4236741..767a7e7 100644 --- a/test.cpp +++ b/test.cpp @@ -1,6 +1,6 @@ #include #include -#include "src/GenerateDungeon/Character.h" +#include "src/Characters/Character.h" #include // Stubs for global/static variables needed by Character.cpp and Tile.cpp diff --git a/tests/test_AinB.cpp b/tests/test_AinB.cpp index 52530ed..1cef556 100644 --- a/tests/test_AinB.cpp +++ b/tests/test_AinB.cpp @@ -5,7 +5,7 @@ // Mock necessary SDL types before including headers that use them #include "SDL2/SDL.h" -#include "Functions/RectUtils.h" +#include "Utils/RectUtils.h" struct TestCase { std::string name;