├── Chapter1 ├── bin │ └── SDL2.dll ├── lib │ ├── SDL2.lib │ ├── SDL2_ttf.lib │ ├── SDL2main.lib │ ├── SDL2_image.lib │ └── SDL2_mixer.lib ├── include │ ├── SDL │ │ ├── SDL_revision.h │ │ ├── SDL_copying.h │ │ ├── SDL_types.h │ │ ├── SDL_name.h │ │ ├── close_code.h │ │ └── SDL_test_memory.h │ └── Game.h ├── src │ ├── main.cpp │ └── Game.cpp ├── Dungeon.vcxproj.user └── Dungeon.vcxproj.filters ├── Chapter10 ├── bin │ ├── SDL2.dll │ ├── zlib1.dll │ ├── libjpeg-9.dll │ ├── SDL2_image.dll │ └── libpng16-16.dll ├── lib │ ├── SDL2.lib │ ├── SDL2_ttf.lib │ ├── SDL2main.lib │ ├── SDL2_image.lib │ └── SDL2_mixer.lib ├── sprites │ ├── wall.png │ ├── chrA07.png │ └── ground.png ├── include │ ├── SDL │ │ ├── SDL_revision.h │ │ ├── SDL_copying.h │ │ ├── SDL_types.h │ │ ├── SDL_name.h │ │ ├── close_code.h │ │ └── SDL_test_memory.h │ ├── Timer.h │ ├── Player.h │ ├── Dungeon.h │ ├── InputComponent.h │ ├── MapComponent.h │ ├── Component.h │ ├── MoveComponent.h │ ├── SpriteComponent.h │ ├── Math │ │ └── Math.h │ ├── GameObject.h │ └── Game.h ├── src │ ├── Timer.cpp │ ├── main.cpp │ ├── Dungeon.cpp │ ├── Player.cpp │ ├── Component.cpp │ ├── InputComponent.cpp │ ├── Math.cpp │ ├── MapComponent.cpp │ ├── SpriteComponent.cpp │ └── MoveComponent.cpp └── Dungeon.vcxproj.user ├── Chapter2 ├── bin │ └── SDL2.dll ├── lib │ ├── SDL2.lib │ ├── SDL2_ttf.lib │ ├── SDL2main.lib │ ├── SDL2_image.lib │ └── SDL2_mixer.lib ├── include │ ├── SDL │ │ ├── SDL_revision.h │ │ ├── SDL_copying.h │ │ ├── SDL_types.h │ │ ├── SDL_name.h │ │ ├── close_code.h │ │ └── SDL_test_memory.h │ └── Game.h ├── src │ └── main.cpp ├── Dungeon.vcxproj.user └── Dungeon.vcxproj.filters ├── Chapter3 ├── bin │ ├── SDL2.dll │ ├── SDL2_image.dll │ ├── libjpeg-9.dll │ └── libpng16-16.dll ├── lib │ ├── SDL2.lib │ ├── SDL2_ttf.lib │ ├── SDL2main.lib │ ├── SDL2_image.lib │ └── SDL2_mixer.lib ├── sprites │ └── yajyuu.jpg ├── include │ ├── SDL │ │ ├── SDL_revision.h │ │ ├── SDL_copying.h │ │ ├── SDL_types.h │ │ ├── SDL_name.h │ │ ├── close_code.h │ │ └── SDL_test_memory.h │ └── Game.h ├── src │ └── main.cpp ├── Dungeon.vcxproj.user └── Dungeon.vcxproj.filters ├── Chapter4 ├── bin │ ├── SDL2.dll │ ├── SDL2_image.dll │ ├── libjpeg-9.dll │ └── libpng16-16.dll ├── lib │ ├── SDL2.lib │ ├── SDL2_ttf.lib │ ├── SDL2main.lib │ ├── SDL2_image.lib │ └── SDL2_mixer.lib ├── sprites │ └── yajyuu.jpg ├── include │ ├── SDL │ │ ├── SDL_revision.h │ │ ├── SDL_copying.h │ │ ├── SDL_types.h │ │ ├── SDL_name.h │ │ ├── close_code.h │ │ └── SDL_test_memory.h │ ├── Component.h │ ├── GameObject.h │ └── Game.h ├── src │ ├── main.cpp │ ├── Component.cpp │ └── GameObject.cpp ├── Dungeon.vcxproj.user └── Dungeon.vcxproj.filters ├── Chapter5 ├── bin │ ├── SDL2.dll │ ├── SDL2_image.dll │ ├── libjpeg-9.dll │ └── libpng16-16.dll ├── lib │ ├── SDL2.lib │ ├── SDL2_ttf.lib │ ├── SDL2main.lib │ ├── SDL2_image.lib │ └── SDL2_mixer.lib ├── sprites │ └── yajyuu.jpg ├── include │ ├── SDL │ │ ├── SDL_revision.h │ │ ├── SDL_copying.h │ │ ├── SDL_types.h │ │ ├── SDL_name.h │ │ ├── close_code.h │ │ └── SDL_test_memory.h │ ├── Component.h │ ├── Math │ │ └── Math.h │ ├── Game.h │ └── GameObject.h ├── src │ ├── main.cpp │ ├── Component.cpp │ └── Math.cpp ├── Dungeon.vcxproj.user └── Dungeon.vcxproj.filters ├── Chapter6 ├── bin │ ├── SDL2.dll │ ├── zlib1.dll │ ├── SDL2_image.dll │ ├── libjpeg-9.dll │ └── libpng16-16.dll ├── lib │ ├── SDL2.lib │ ├── SDL2_ttf.lib │ ├── SDL2main.lib │ ├── SDL2_image.lib │ └── SDL2_mixer.lib ├── sprites │ └── chrA07.png ├── include │ ├── SDL │ │ ├── SDL_revision.h │ │ ├── SDL_copying.h │ │ ├── SDL_types.h │ │ ├── SDL_name.h │ │ ├── close_code.h │ │ └── SDL_test_memory.h │ ├── Player.h │ ├── Component.h │ ├── SpriteComponent.h │ ├── Math │ │ └── Math.h │ ├── GameObject.h │ └── Game.h ├── src │ ├── main.cpp │ ├── Player.cpp │ ├── Component.cpp │ ├── Math.cpp │ └── SpriteComponent.cpp └── Dungeon.vcxproj.user ├── Chapter7 ├── bin │ ├── SDL2.dll │ ├── zlib1.dll │ ├── SDL2_image.dll │ ├── libjpeg-9.dll │ └── libpng16-16.dll ├── lib │ ├── SDL2.lib │ ├── SDL2_ttf.lib │ ├── SDL2main.lib │ ├── SDL2_image.lib │ └── SDL2_mixer.lib ├── sprites │ └── chrA07.png ├── include │ ├── SDL │ │ ├── SDL_revision.h │ │ ├── SDL_copying.h │ │ ├── SDL_types.h │ │ ├── SDL_name.h │ │ ├── close_code.h │ │ └── SDL_test_memory.h │ ├── Timer.h │ ├── Player.h │ ├── MoveComponent.h │ ├── Component.h │ ├── SpriteComponent.h │ ├── Math │ │ └── Math.h │ ├── GameObject.h │ └── Game.h ├── src │ ├── Timer.cpp │ ├── main.cpp │ ├── MoveComponent.cpp │ ├── Player.cpp │ ├── Component.cpp │ ├── Math.cpp │ └── SpriteComponent.cpp └── Dungeon.vcxproj.user ├── Chapter8 ├── bin │ ├── SDL2.dll │ ├── zlib1.dll │ ├── SDL2_image.dll │ ├── libjpeg-9.dll │ └── libpng16-16.dll ├── lib │ ├── SDL2.lib │ ├── SDL2_ttf.lib │ ├── SDL2main.lib │ ├── SDL2_image.lib │ └── SDL2_mixer.lib ├── sprites │ └── chrA07.png ├── include │ ├── SDL │ │ ├── SDL_revision.h │ │ ├── SDL_copying.h │ │ ├── SDL_types.h │ │ ├── SDL_name.h │ │ ├── close_code.h │ │ └── SDL_test_memory.h │ ├── Timer.h │ ├── Player.h │ ├── InputComponent.h │ ├── MoveComponent.h │ ├── Component.h │ ├── SpriteComponent.h │ ├── Math │ │ └── Math.h │ ├── Game.h │ └── GameObject.h ├── src │ ├── Timer.cpp │ ├── main.cpp │ ├── Player.cpp │ ├── MoveComponent.cpp │ ├── Component.cpp │ ├── InputComponent.cpp │ ├── Math.cpp │ └── SpriteComponent.cpp └── Dungeon.vcxproj.user └── Chapter9 ├── bin ├── SDL2.dll ├── zlib1.dll ├── SDL2_image.dll ├── libjpeg-9.dll └── libpng16-16.dll ├── lib ├── SDL2.lib ├── SDL2_ttf.lib ├── SDL2main.lib ├── SDL2_image.lib └── SDL2_mixer.lib ├── sprites ├── wall.png ├── chrA07.png └── ground.png ├── include ├── SDL │ ├── SDL_revision.h │ ├── SDL_copying.h │ ├── SDL_types.h │ ├── SDL_name.h │ ├── close_code.h │ └── SDL_test_memory.h ├── Timer.h ├── Player.h ├── Dungeon.h ├── InputComponent.h ├── MoveComponent.h ├── MapComponent.h ├── Component.h ├── SpriteComponent.h ├── Math │ └── Math.h ├── GameObject.h └── Game.h ├── src ├── Timer.cpp ├── main.cpp ├── Dungeon.cpp ├── Player.cpp ├── MoveComponent.cpp ├── Component.cpp ├── InputComponent.cpp ├── MapComponent.cpp ├── Math.cpp └── SpriteComponent.cpp └── Dungeon.vcxproj.user /Chapter1/bin/SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter1/bin/SDL2.dll -------------------------------------------------------------------------------- /Chapter1/lib/SDL2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter1/lib/SDL2.lib -------------------------------------------------------------------------------- /Chapter10/bin/SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter10/bin/SDL2.dll -------------------------------------------------------------------------------- /Chapter10/lib/SDL2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter10/lib/SDL2.lib -------------------------------------------------------------------------------- /Chapter2/bin/SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter2/bin/SDL2.dll -------------------------------------------------------------------------------- /Chapter2/lib/SDL2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter2/lib/SDL2.lib -------------------------------------------------------------------------------- /Chapter3/bin/SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter3/bin/SDL2.dll -------------------------------------------------------------------------------- /Chapter3/lib/SDL2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter3/lib/SDL2.lib -------------------------------------------------------------------------------- /Chapter4/bin/SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter4/bin/SDL2.dll -------------------------------------------------------------------------------- /Chapter4/lib/SDL2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter4/lib/SDL2.lib -------------------------------------------------------------------------------- /Chapter5/bin/SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter5/bin/SDL2.dll -------------------------------------------------------------------------------- /Chapter5/lib/SDL2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter5/lib/SDL2.lib -------------------------------------------------------------------------------- /Chapter6/bin/SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter6/bin/SDL2.dll -------------------------------------------------------------------------------- /Chapter6/bin/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter6/bin/zlib1.dll -------------------------------------------------------------------------------- /Chapter6/lib/SDL2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter6/lib/SDL2.lib -------------------------------------------------------------------------------- /Chapter7/bin/SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter7/bin/SDL2.dll -------------------------------------------------------------------------------- /Chapter7/bin/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter7/bin/zlib1.dll -------------------------------------------------------------------------------- /Chapter7/lib/SDL2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter7/lib/SDL2.lib -------------------------------------------------------------------------------- /Chapter8/bin/SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter8/bin/SDL2.dll -------------------------------------------------------------------------------- /Chapter8/bin/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter8/bin/zlib1.dll -------------------------------------------------------------------------------- /Chapter8/lib/SDL2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter8/lib/SDL2.lib -------------------------------------------------------------------------------- /Chapter9/bin/SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter9/bin/SDL2.dll -------------------------------------------------------------------------------- /Chapter9/bin/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter9/bin/zlib1.dll -------------------------------------------------------------------------------- /Chapter9/lib/SDL2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter9/lib/SDL2.lib -------------------------------------------------------------------------------- /Chapter1/lib/SDL2_ttf.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter1/lib/SDL2_ttf.lib -------------------------------------------------------------------------------- /Chapter1/lib/SDL2main.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter1/lib/SDL2main.lib -------------------------------------------------------------------------------- /Chapter10/bin/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter10/bin/zlib1.dll -------------------------------------------------------------------------------- /Chapter2/lib/SDL2_ttf.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter2/lib/SDL2_ttf.lib -------------------------------------------------------------------------------- /Chapter2/lib/SDL2main.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter2/lib/SDL2main.lib -------------------------------------------------------------------------------- /Chapter3/lib/SDL2_ttf.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter3/lib/SDL2_ttf.lib -------------------------------------------------------------------------------- /Chapter3/lib/SDL2main.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter3/lib/SDL2main.lib -------------------------------------------------------------------------------- /Chapter4/lib/SDL2_ttf.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter4/lib/SDL2_ttf.lib -------------------------------------------------------------------------------- /Chapter4/lib/SDL2main.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter4/lib/SDL2main.lib -------------------------------------------------------------------------------- /Chapter5/lib/SDL2_ttf.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter5/lib/SDL2_ttf.lib -------------------------------------------------------------------------------- /Chapter5/lib/SDL2main.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter5/lib/SDL2main.lib -------------------------------------------------------------------------------- /Chapter6/lib/SDL2_ttf.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter6/lib/SDL2_ttf.lib -------------------------------------------------------------------------------- /Chapter6/lib/SDL2main.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter6/lib/SDL2main.lib -------------------------------------------------------------------------------- /Chapter7/lib/SDL2_ttf.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter7/lib/SDL2_ttf.lib -------------------------------------------------------------------------------- /Chapter7/lib/SDL2main.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter7/lib/SDL2main.lib -------------------------------------------------------------------------------- /Chapter8/lib/SDL2_ttf.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter8/lib/SDL2_ttf.lib -------------------------------------------------------------------------------- /Chapter8/lib/SDL2main.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter8/lib/SDL2main.lib -------------------------------------------------------------------------------- /Chapter9/lib/SDL2_ttf.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter9/lib/SDL2_ttf.lib -------------------------------------------------------------------------------- /Chapter9/lib/SDL2main.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter9/lib/SDL2main.lib -------------------------------------------------------------------------------- /Chapter9/sprites/wall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter9/sprites/wall.png -------------------------------------------------------------------------------- /Chapter1/lib/SDL2_image.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter1/lib/SDL2_image.lib -------------------------------------------------------------------------------- /Chapter1/lib/SDL2_mixer.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter1/lib/SDL2_mixer.lib -------------------------------------------------------------------------------- /Chapter10/bin/libjpeg-9.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter10/bin/libjpeg-9.dll -------------------------------------------------------------------------------- /Chapter10/lib/SDL2_ttf.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter10/lib/SDL2_ttf.lib -------------------------------------------------------------------------------- /Chapter10/lib/SDL2main.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter10/lib/SDL2main.lib -------------------------------------------------------------------------------- /Chapter10/sprites/wall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter10/sprites/wall.png -------------------------------------------------------------------------------- /Chapter2/lib/SDL2_image.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter2/lib/SDL2_image.lib -------------------------------------------------------------------------------- /Chapter2/lib/SDL2_mixer.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter2/lib/SDL2_mixer.lib -------------------------------------------------------------------------------- /Chapter3/bin/SDL2_image.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter3/bin/SDL2_image.dll -------------------------------------------------------------------------------- /Chapter3/bin/libjpeg-9.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter3/bin/libjpeg-9.dll -------------------------------------------------------------------------------- /Chapter3/lib/SDL2_image.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter3/lib/SDL2_image.lib -------------------------------------------------------------------------------- /Chapter3/lib/SDL2_mixer.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter3/lib/SDL2_mixer.lib -------------------------------------------------------------------------------- /Chapter3/sprites/yajyuu.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter3/sprites/yajyuu.jpg -------------------------------------------------------------------------------- /Chapter4/bin/SDL2_image.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter4/bin/SDL2_image.dll -------------------------------------------------------------------------------- /Chapter4/bin/libjpeg-9.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter4/bin/libjpeg-9.dll -------------------------------------------------------------------------------- /Chapter4/lib/SDL2_image.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter4/lib/SDL2_image.lib -------------------------------------------------------------------------------- /Chapter4/lib/SDL2_mixer.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter4/lib/SDL2_mixer.lib -------------------------------------------------------------------------------- /Chapter4/sprites/yajyuu.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter4/sprites/yajyuu.jpg -------------------------------------------------------------------------------- /Chapter5/bin/SDL2_image.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter5/bin/SDL2_image.dll -------------------------------------------------------------------------------- /Chapter5/bin/libjpeg-9.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter5/bin/libjpeg-9.dll -------------------------------------------------------------------------------- /Chapter5/lib/SDL2_image.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter5/lib/SDL2_image.lib -------------------------------------------------------------------------------- /Chapter5/lib/SDL2_mixer.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter5/lib/SDL2_mixer.lib -------------------------------------------------------------------------------- /Chapter5/sprites/yajyuu.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter5/sprites/yajyuu.jpg -------------------------------------------------------------------------------- /Chapter6/bin/SDL2_image.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter6/bin/SDL2_image.dll -------------------------------------------------------------------------------- /Chapter6/bin/libjpeg-9.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter6/bin/libjpeg-9.dll -------------------------------------------------------------------------------- /Chapter6/lib/SDL2_image.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter6/lib/SDL2_image.lib -------------------------------------------------------------------------------- /Chapter6/lib/SDL2_mixer.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter6/lib/SDL2_mixer.lib -------------------------------------------------------------------------------- /Chapter6/sprites/chrA07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter6/sprites/chrA07.png -------------------------------------------------------------------------------- /Chapter7/bin/SDL2_image.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter7/bin/SDL2_image.dll -------------------------------------------------------------------------------- /Chapter7/bin/libjpeg-9.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter7/bin/libjpeg-9.dll -------------------------------------------------------------------------------- /Chapter7/lib/SDL2_image.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter7/lib/SDL2_image.lib -------------------------------------------------------------------------------- /Chapter7/lib/SDL2_mixer.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter7/lib/SDL2_mixer.lib -------------------------------------------------------------------------------- /Chapter7/sprites/chrA07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter7/sprites/chrA07.png -------------------------------------------------------------------------------- /Chapter8/bin/SDL2_image.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter8/bin/SDL2_image.dll -------------------------------------------------------------------------------- /Chapter8/bin/libjpeg-9.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter8/bin/libjpeg-9.dll -------------------------------------------------------------------------------- /Chapter8/lib/SDL2_image.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter8/lib/SDL2_image.lib -------------------------------------------------------------------------------- /Chapter8/lib/SDL2_mixer.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter8/lib/SDL2_mixer.lib -------------------------------------------------------------------------------- /Chapter8/sprites/chrA07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter8/sprites/chrA07.png -------------------------------------------------------------------------------- /Chapter9/bin/SDL2_image.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter9/bin/SDL2_image.dll -------------------------------------------------------------------------------- /Chapter9/bin/libjpeg-9.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter9/bin/libjpeg-9.dll -------------------------------------------------------------------------------- /Chapter9/lib/SDL2_image.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter9/lib/SDL2_image.lib -------------------------------------------------------------------------------- /Chapter9/lib/SDL2_mixer.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter9/lib/SDL2_mixer.lib -------------------------------------------------------------------------------- /Chapter9/sprites/chrA07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter9/sprites/chrA07.png -------------------------------------------------------------------------------- /Chapter9/sprites/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter9/sprites/ground.png -------------------------------------------------------------------------------- /Chapter1/include/SDL/SDL_revision.h: -------------------------------------------------------------------------------- 1 | #define SDL_REVISION "hg-14525:e52d96ea04fc" 2 | #define SDL_REVISION_NUMBER 14525 3 | -------------------------------------------------------------------------------- /Chapter10/bin/SDL2_image.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter10/bin/SDL2_image.dll -------------------------------------------------------------------------------- /Chapter10/bin/libpng16-16.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter10/bin/libpng16-16.dll -------------------------------------------------------------------------------- /Chapter10/include/SDL/SDL_revision.h: -------------------------------------------------------------------------------- 1 | #define SDL_REVISION "hg-14525:e52d96ea04fc" 2 | #define SDL_REVISION_NUMBER 14525 3 | -------------------------------------------------------------------------------- /Chapter10/lib/SDL2_image.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter10/lib/SDL2_image.lib -------------------------------------------------------------------------------- /Chapter10/lib/SDL2_mixer.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter10/lib/SDL2_mixer.lib -------------------------------------------------------------------------------- /Chapter10/sprites/chrA07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter10/sprites/chrA07.png -------------------------------------------------------------------------------- /Chapter10/sprites/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter10/sprites/ground.png -------------------------------------------------------------------------------- /Chapter2/include/SDL/SDL_revision.h: -------------------------------------------------------------------------------- 1 | #define SDL_REVISION "hg-14525:e52d96ea04fc" 2 | #define SDL_REVISION_NUMBER 14525 3 | -------------------------------------------------------------------------------- /Chapter3/bin/libpng16-16.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter3/bin/libpng16-16.dll -------------------------------------------------------------------------------- /Chapter3/include/SDL/SDL_revision.h: -------------------------------------------------------------------------------- 1 | #define SDL_REVISION "hg-14525:e52d96ea04fc" 2 | #define SDL_REVISION_NUMBER 14525 3 | -------------------------------------------------------------------------------- /Chapter4/bin/libpng16-16.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter4/bin/libpng16-16.dll -------------------------------------------------------------------------------- /Chapter4/include/SDL/SDL_revision.h: -------------------------------------------------------------------------------- 1 | #define SDL_REVISION "hg-14525:e52d96ea04fc" 2 | #define SDL_REVISION_NUMBER 14525 3 | -------------------------------------------------------------------------------- /Chapter5/bin/libpng16-16.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter5/bin/libpng16-16.dll -------------------------------------------------------------------------------- /Chapter5/include/SDL/SDL_revision.h: -------------------------------------------------------------------------------- 1 | #define SDL_REVISION "hg-14525:e52d96ea04fc" 2 | #define SDL_REVISION_NUMBER 14525 3 | -------------------------------------------------------------------------------- /Chapter6/bin/libpng16-16.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter6/bin/libpng16-16.dll -------------------------------------------------------------------------------- /Chapter6/include/SDL/SDL_revision.h: -------------------------------------------------------------------------------- 1 | #define SDL_REVISION "hg-14525:e52d96ea04fc" 2 | #define SDL_REVISION_NUMBER 14525 3 | -------------------------------------------------------------------------------- /Chapter7/bin/libpng16-16.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter7/bin/libpng16-16.dll -------------------------------------------------------------------------------- /Chapter7/include/SDL/SDL_revision.h: -------------------------------------------------------------------------------- 1 | #define SDL_REVISION "hg-14525:e52d96ea04fc" 2 | #define SDL_REVISION_NUMBER 14525 3 | -------------------------------------------------------------------------------- /Chapter8/bin/libpng16-16.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter8/bin/libpng16-16.dll -------------------------------------------------------------------------------- /Chapter8/include/SDL/SDL_revision.h: -------------------------------------------------------------------------------- 1 | #define SDL_REVISION "hg-14525:e52d96ea04fc" 2 | #define SDL_REVISION_NUMBER 14525 3 | -------------------------------------------------------------------------------- /Chapter9/bin/libpng16-16.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assbee0/Cplus-Game-Tutorial/HEAD/Chapter9/bin/libpng16-16.dll -------------------------------------------------------------------------------- /Chapter9/include/SDL/SDL_revision.h: -------------------------------------------------------------------------------- 1 | #define SDL_REVISION "hg-14525:e52d96ea04fc" 2 | #define SDL_REVISION_NUMBER 14525 3 | -------------------------------------------------------------------------------- /Chapter10/src/Timer.cpp: -------------------------------------------------------------------------------- 1 | //! @file Timer.cpp 2 | 3 | #include 4 | 5 | namespace Dungeon 6 | { 7 | float Timer::deltaTime = 0; 8 | unsigned int Timer::ticksCount = 0; 9 | } -------------------------------------------------------------------------------- /Chapter7/src/Timer.cpp: -------------------------------------------------------------------------------- 1 | //! @file Timer.cpp 2 | 3 | #include 4 | 5 | namespace Dungeon 6 | { 7 | float Timer::deltaTime = 0; 8 | unsigned int Timer::ticksCount = 0; 9 | } -------------------------------------------------------------------------------- /Chapter8/src/Timer.cpp: -------------------------------------------------------------------------------- 1 | //! @file Timer.cpp 2 | 3 | #include 4 | 5 | namespace Dungeon 6 | { 7 | float Timer::deltaTime = 0; 8 | unsigned int Timer::ticksCount = 0; 9 | } -------------------------------------------------------------------------------- /Chapter9/src/Timer.cpp: -------------------------------------------------------------------------------- 1 | //! @file Timer.cpp 2 | 3 | #include 4 | 5 | namespace Dungeon 6 | { 7 | float Timer::deltaTime = 0; 8 | unsigned int Timer::ticksCount = 0; 9 | } -------------------------------------------------------------------------------- /Chapter10/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char* argv[]) 5 | { 6 | Dungeon::Game game; 7 | bool success = game.Initialize(); 8 | if (success) 9 | { 10 | game.Loop(); 11 | } 12 | game.Shutdown(); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Chapter6/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char* argv[]) 5 | { 6 | Dungeon::Game game; 7 | bool success = game.Initialize(); 8 | if (success) 9 | { 10 | game.Loop(); 11 | } 12 | game.Shutdown(); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Chapter7/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char* argv[]) 5 | { 6 | Dungeon::Game game; 7 | bool success = game.Initialize(); 8 | if (success) 9 | { 10 | game.Loop(); 11 | } 12 | game.Shutdown(); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Chapter8/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char* argv[]) 5 | { 6 | Dungeon::Game game; 7 | bool success = game.Initialize(); 8 | if (success) 9 | { 10 | game.Loop(); 11 | } 12 | game.Shutdown(); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Chapter9/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char* argv[]) 5 | { 6 | Dungeon::Game game; 7 | bool success = game.Initialize(); 8 | if (success) 9 | { 10 | game.Loop(); 11 | } 12 | game.Shutdown(); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Chapter1/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char* argv[]) 5 | { 6 | Dungeon::Game game; 7 | bool success = game.Initialize(); 8 | if (success) 9 | { 10 | game.Loop(); 11 | } 12 | game.Shutdown(); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Chapter2/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char* argv[]) 5 | { 6 | Dungeon::Game game; 7 | bool success = game.Initialize(); 8 | if (success) 9 | { 10 | game.Loop(); 11 | } 12 | game.Shutdown(); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Chapter3/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char* argv[]) 5 | { 6 | Dungeon::Game game; 7 | bool success = game.Initialize(); 8 | if (success) 9 | { 10 | game.Loop(); 11 | } 12 | game.Shutdown(); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Chapter4/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char* argv[]) 5 | { 6 | Dungeon::Game game; 7 | bool success = game.Initialize(); 8 | if (success) 9 | { 10 | game.Loop(); 11 | } 12 | game.Shutdown(); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Chapter5/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char* argv[]) 5 | { 6 | Dungeon::Game game; 7 | bool success = game.Initialize(); 8 | if (success) 9 | { 10 | game.Loop(); 11 | } 12 | game.Shutdown(); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Chapter8/include/Timer.h: -------------------------------------------------------------------------------- 1 | //! @file Timer.h 2 | 3 | #ifndef __Dungeon_Timer__ 4 | #define __Dungeon_Timer__ 5 | 6 | namespace Dungeon 7 | { 8 | class Timer 9 | { 10 | public: 11 | static float deltaTime; //!< 增量时间 12 | static unsigned int ticksCount; //!< 总共经过的时间 13 | }; 14 | } 15 | 16 | #endif // __Dungeon_Timer__ -------------------------------------------------------------------------------- /Chapter9/include/Timer.h: -------------------------------------------------------------------------------- 1 | //! @file Timer.h 2 | 3 | #ifndef __Dungeon_Timer__ 4 | #define __Dungeon_Timer__ 5 | 6 | namespace Dungeon 7 | { 8 | class Timer 9 | { 10 | public: 11 | static float deltaTime; //!< 增量时间 12 | static unsigned int ticksCount; //!< 总共经过的时间 13 | }; 14 | } 15 | 16 | #endif // __Dungeon_Timer__ -------------------------------------------------------------------------------- /Chapter10/include/Timer.h: -------------------------------------------------------------------------------- 1 | //! @file Timer.h 2 | 3 | #ifndef __Dungeon_Timer__ 4 | #define __Dungeon_Timer__ 5 | 6 | namespace Dungeon 7 | { 8 | class Timer 9 | { 10 | public: 11 | static float deltaTime; //!< 增量时间 12 | static unsigned int ticksCount; //!< 总共经过的时间 13 | }; 14 | } 15 | 16 | #endif // __Dungeon_Timer__ -------------------------------------------------------------------------------- /Chapter7/include/Timer.h: -------------------------------------------------------------------------------- 1 | //! @file Timer.h 2 | 3 | #ifndef __Dungeon_Timer__ 4 | #define __Dungeon_Timer__ 5 | 6 | namespace Dungeon 7 | { 8 | class Timer 9 | { 10 | public: 11 | // 增量时间 12 | static float deltaTime; 13 | // 总共经过的时间 14 | static unsigned int ticksCount; 15 | }; 16 | } 17 | 18 | #endif // __Dungeon_Timer__ -------------------------------------------------------------------------------- /Chapter10/include/Player.h: -------------------------------------------------------------------------------- 1 | //! @file Player.h 2 | 3 | #ifndef __Dungeon_Player__ 4 | #define __Dungeon_Player__ 5 | 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | class Player : public GameObject 11 | { 12 | public: 13 | //! 构造函数 14 | Player(class Game* game); 15 | }; 16 | } 17 | 18 | #endif // __Dungeon_Player__ -------------------------------------------------------------------------------- /Chapter6/include/Player.h: -------------------------------------------------------------------------------- 1 | //! @file Player.h 2 | 3 | #ifndef __Dungeon_Player__ 4 | #define __Dungeon_Player__ 5 | 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | class Player : public GameObject 11 | { 12 | public: 13 | //! 构造函数 14 | Player(class Game* game); 15 | }; 16 | } 17 | 18 | #endif // __Dungeon_Player__ -------------------------------------------------------------------------------- /Chapter7/include/Player.h: -------------------------------------------------------------------------------- 1 | //! @file Player.h 2 | 3 | #ifndef __Dungeon_Player__ 4 | #define __Dungeon_Player__ 5 | 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | class Player : public GameObject 11 | { 12 | public: 13 | //! 构造函数 14 | Player(class Game* game); 15 | }; 16 | } 17 | 18 | #endif // __Dungeon_Player__ -------------------------------------------------------------------------------- /Chapter8/include/Player.h: -------------------------------------------------------------------------------- 1 | //! @file Player.h 2 | 3 | #ifndef __Dungeon_Player__ 4 | #define __Dungeon_Player__ 5 | 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | class Player : public GameObject 11 | { 12 | public: 13 | //! 构造函数 14 | Player(class Game* game); 15 | }; 16 | } 17 | 18 | #endif // __Dungeon_Player__ -------------------------------------------------------------------------------- /Chapter9/include/Player.h: -------------------------------------------------------------------------------- 1 | //! @file Player.h 2 | 3 | #ifndef __Dungeon_Player__ 4 | #define __Dungeon_Player__ 5 | 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | class Player : public GameObject 11 | { 12 | public: 13 | //! 构造函数 14 | Player(class Game* game); 15 | }; 16 | } 17 | 18 | #endif // __Dungeon_Player__ -------------------------------------------------------------------------------- /Chapter9/include/Dungeon.h: -------------------------------------------------------------------------------- 1 | //! @file Dungeon.h 2 | 3 | #ifndef __Dungeon_Dungeon__ 4 | #define __Dungeon_Dungeon__ 5 | 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | class Dungeon : public GameObject 11 | { 12 | public: 13 | //! 构造函数 14 | Dungeon(class Game* game); 15 | }; 16 | } 17 | 18 | #endif // __Dungeon_Dungeon__ -------------------------------------------------------------------------------- /Chapter10/include/Dungeon.h: -------------------------------------------------------------------------------- 1 | //! @file Dungeon.h 2 | 3 | #ifndef __Dungeon_Dungeon__ 4 | #define __Dungeon_Dungeon__ 5 | 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | class Dungeon : public GameObject 11 | { 12 | public: 13 | //! 构造函数 14 | Dungeon(class Game* game); 15 | }; 16 | } 17 | 18 | #endif // __Dungeon_Dungeon__ -------------------------------------------------------------------------------- /Chapter6/src/Player.cpp: -------------------------------------------------------------------------------- 1 | //! @file Player.h 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Dungeon 8 | { 9 | Player::Player(Game* game): 10 | GameObject(game) 11 | { 12 | SpriteComponent* sprite = new SpriteComponent(this, 100); 13 | sprite->SetTexture(GetGame()->GetTexture("player")); 14 | SetPosition(Vector2(288, 240)); 15 | } 16 | } -------------------------------------------------------------------------------- /Chapter10/src/Dungeon.cpp: -------------------------------------------------------------------------------- 1 | //! @file Dungeon.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Dungeon 8 | { 9 | Dungeon::Dungeon(Game* game): 10 | GameObject(game) 11 | { 12 | MapComponent* mapComponent = new MapComponent(this); 13 | mapComponent->SetTexture(game->GetTexture("ground"), 0); 14 | mapComponent->SetTexture(game->GetTexture("wall"), 1); 15 | } 16 | } -------------------------------------------------------------------------------- /Chapter9/src/Dungeon.cpp: -------------------------------------------------------------------------------- 1 | //! @file Dungeon.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Dungeon 8 | { 9 | Dungeon::Dungeon(Game* game): 10 | GameObject(game) 11 | { 12 | MapComponent* mapComponent = new MapComponent(this); 13 | mapComponent->SetTexture(game->GetTexture("ground"), 0); 14 | mapComponent->SetTexture(game->GetTexture("wall"), 1); 15 | } 16 | } -------------------------------------------------------------------------------- /Chapter1/Dungeon.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PATH=bin 5 | $(LocalDebuggerEnvironment) 6 | WindowsLocalDebugger 7 | 8 | -------------------------------------------------------------------------------- /Chapter7/include/MoveComponent.h: -------------------------------------------------------------------------------- 1 | //! @file MoveComponent.h 2 | 3 | #ifndef __Dungeon_MoveComponent__ 4 | #define __Dungeon_MoveComponent__ 5 | 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | class GameObject; 11 | 12 | class MoveComponent : public Component 13 | { 14 | public: 15 | //! 构造函数 16 | MoveComponent(GameObject* gameObject); 17 | 18 | //! 每帧更新(重写) 19 | void Update() override; 20 | }; 21 | } 22 | 23 | #endif // __Dungeon_MoveComponent__ -------------------------------------------------------------------------------- /Chapter7/src/MoveComponent.cpp: -------------------------------------------------------------------------------- 1 | //! @file MoveComponent.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Dungeon 8 | { 9 | MoveComponent::MoveComponent(GameObject* gameObject): 10 | Component(gameObject) 11 | { 12 | } 13 | 14 | void MoveComponent::Update() 15 | { 16 | Vector2 curPos = mGameObject->GetPosition(); 17 | mGameObject->SetPosition(curPos + Vector2::X /*方向*/ * 50 /*速度*/ * Timer::deltaTime /*增量时间*/); 18 | } 19 | } -------------------------------------------------------------------------------- /Chapter7/src/Player.cpp: -------------------------------------------------------------------------------- 1 | //! @file Player.h 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | Player::Player(Game* game): 11 | GameObject(game) 12 | { 13 | SpriteComponent* sprite = new SpriteComponent(this, 100); 14 | sprite->SetTexture(GetGame()->GetTexture("player")); 15 | SetPosition(Vector2(288, 240)); 16 | MoveComponent* moveComponent = new MoveComponent(this); 17 | } 18 | } -------------------------------------------------------------------------------- /Chapter10/include/InputComponent.h: -------------------------------------------------------------------------------- 1 | //! @file InputComponent.h 2 | 3 | #ifndef __Dungeon_InputComponent__ 4 | #define __Dungeon_InputComponent__ 5 | 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | class GameObject; 11 | 12 | class InputComponent : public Component 13 | { 14 | public: 15 | //! 构造函数 16 | InputComponent(GameObject* gameObject); 17 | 18 | //! 处理输入(重写) 19 | void ProcessInput(const uint8_t* state) override; 20 | }; 21 | } 22 | 23 | #endif // __Dungeon_InputComponent__ -------------------------------------------------------------------------------- /Chapter8/include/InputComponent.h: -------------------------------------------------------------------------------- 1 | //! @file InputComponent.h 2 | 3 | #ifndef __Dungeon_InputComponent__ 4 | #define __Dungeon_InputComponent__ 5 | 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | class GameObject; 11 | 12 | class InputComponent : public Component 13 | { 14 | public: 15 | //! 构造函数 16 | InputComponent(GameObject* gameObject); 17 | 18 | //! 处理输入(重写) 19 | void ProcessInput(const uint8_t* state) override; 20 | }; 21 | } 22 | 23 | #endif // __Dungeon_InputComponent__ -------------------------------------------------------------------------------- /Chapter9/include/InputComponent.h: -------------------------------------------------------------------------------- 1 | //! @file InputComponent.h 2 | 3 | #ifndef __Dungeon_InputComponent__ 4 | #define __Dungeon_InputComponent__ 5 | 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | class GameObject; 11 | 12 | class InputComponent : public Component 13 | { 14 | public: 15 | //! 构造函数 16 | InputComponent(GameObject* gameObject); 17 | 18 | //! 处理输入(重写) 19 | void ProcessInput(const uint8_t* state) override; 20 | }; 21 | } 22 | 23 | #endif // __Dungeon_InputComponent__ -------------------------------------------------------------------------------- /Chapter10/src/Player.cpp: -------------------------------------------------------------------------------- 1 | //! @file Player.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | Player::Player(Game* game): 12 | GameObject(game) 13 | { 14 | SpriteComponent* sprite = new SpriteComponent(this, 100); 15 | sprite->SetTexture(GetGame()->GetTexture("player")); 16 | SetPosition(Vector2(288, 224)); 17 | MoveComponent* moveComponent = new MoveComponent(this); 18 | InputComponent* inputComponent = new InputComponent(this); 19 | } 20 | } -------------------------------------------------------------------------------- /Chapter8/src/Player.cpp: -------------------------------------------------------------------------------- 1 | //! @file Player.h 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | Player::Player(Game* game): 12 | GameObject(game) 13 | { 14 | SpriteComponent* sprite = new SpriteComponent(this, 100); 15 | sprite->SetTexture(GetGame()->GetTexture("player")); 16 | SetPosition(Vector2(288, 240)); 17 | MoveComponent* moveComponent = new MoveComponent(this); 18 | InputComponent* inputComponent = new InputComponent(this); 19 | } 20 | } -------------------------------------------------------------------------------- /Chapter9/src/Player.cpp: -------------------------------------------------------------------------------- 1 | //! @file Player.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | Player::Player(Game* game): 12 | GameObject(game) 13 | { 14 | SpriteComponent* sprite = new SpriteComponent(this, 100); 15 | sprite->SetTexture(GetGame()->GetTexture("player")); 16 | SetPosition(Vector2(288, 240)); 17 | MoveComponent* moveComponent = new MoveComponent(this); 18 | InputComponent* inputComponent = new InputComponent(this); 19 | } 20 | } -------------------------------------------------------------------------------- /Chapter1/include/Game.h: -------------------------------------------------------------------------------- 1 | //! @file Game.h 2 | 3 | #ifndef __Dungeon_Game__ 4 | #define __Dungeon_Game__ 5 | 6 | namespace Dungeon 7 | { 8 | class Game 9 | { 10 | public: 11 | //! 构造函数 12 | Game(); 13 | 14 | //! 初始化 15 | bool Initialize(); 16 | //! 主循环 17 | void Loop(); 18 | //! 游戏结束 19 | void Shutdown(); 20 | 21 | private: 22 | //! 处理事件 23 | void Event(); 24 | //! 更新各种状态 25 | void Update(); 26 | //! 渲染 27 | void Draw(); 28 | 29 | class SDL_Window* mWindow; //!< 窗口 30 | bool mIsRunning; //!< 运行状态 31 | }; 32 | } 33 | 34 | #endif // __Dungeon_Game__ -------------------------------------------------------------------------------- /Chapter8/src/MoveComponent.cpp: -------------------------------------------------------------------------------- 1 | //! @file MoveComponent.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Dungeon 8 | { 9 | MoveComponent::MoveComponent(GameObject* gameObject): 10 | Component(gameObject), 11 | mSpeed(100), 12 | mDir(Vector2::Zero) 13 | { 14 | } 15 | 16 | void MoveComponent::Update() 17 | { 18 | Vector2 curPos = mGameObject->GetPosition(); 19 | Vector2 newPos = curPos + mDir * mSpeed * Timer::deltaTime; 20 | mGameObject->SetPosition(newPos); 21 | } 22 | 23 | void MoveComponent::SetDir(const Vector2& dir) 24 | { 25 | mDir = dir; 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter9/src/MoveComponent.cpp: -------------------------------------------------------------------------------- 1 | //! @file MoveComponent.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Dungeon 8 | { 9 | MoveComponent::MoveComponent(GameObject* gameObject): 10 | Component(gameObject), 11 | mSpeed(100), 12 | mDir(Vector2::Zero) 13 | { 14 | } 15 | 16 | void MoveComponent::Update() 17 | { 18 | Vector2 curPos = mGameObject->GetPosition(); 19 | Vector2 newPos = curPos + mDir * mSpeed * Timer::deltaTime; 20 | mGameObject->SetPosition(newPos); 21 | } 22 | 23 | void MoveComponent::SetDir(const Vector2& dir) 24 | { 25 | mDir = dir; 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter8/include/MoveComponent.h: -------------------------------------------------------------------------------- 1 | //! @file MoveComponent.h 2 | 3 | #ifndef __Dungeon_MoveComponent__ 4 | #define __Dungeon_MoveComponent__ 5 | 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | class GameObject; 12 | 13 | class MoveComponent : public Component 14 | { 15 | public: 16 | //! 构造函数 17 | MoveComponent(GameObject* gameObject); 18 | 19 | //! 每帧更新(重写) 20 | void Update() override; 21 | 22 | //! 移动方向的set 23 | void SetDir(const Vector2& dir); 24 | 25 | private: 26 | float mSpeed; //!< 移动速度 27 | Vector2 mDir; //!< 移动方向 28 | }; 29 | } 30 | 31 | #endif // __Dungeon_MoveComponent__ -------------------------------------------------------------------------------- /Chapter9/include/MoveComponent.h: -------------------------------------------------------------------------------- 1 | //! @file MoveComponent.h 2 | 3 | #ifndef __Dungeon_MoveComponent__ 4 | #define __Dungeon_MoveComponent__ 5 | 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | class GameObject; 12 | 13 | class MoveComponent : public Component 14 | { 15 | public: 16 | //! 构造函数 17 | MoveComponent(GameObject* gameObject); 18 | 19 | //! 每帧更新(重写) 20 | void Update() override; 21 | 22 | //! 移动方向的set 23 | void SetDir(const Vector2& dir); 24 | 25 | private: 26 | float mSpeed; //!< 移动速度 27 | Vector2 mDir; //!< 移动方向 28 | }; 29 | } 30 | 31 | #endif // __Dungeon_MoveComponent__ -------------------------------------------------------------------------------- /Chapter2/include/Game.h: -------------------------------------------------------------------------------- 1 | //! @file Game.h 2 | 3 | #ifndef __Dungeon_Game__ 4 | #define __Dungeon_Game__ 5 | 6 | namespace Dungeon 7 | { 8 | class Game 9 | { 10 | public: 11 | //! 构造函数 12 | Game(); 13 | 14 | //! 初始化 15 | bool Initialize(); 16 | //! 主循环 17 | void Loop(); 18 | //! 游戏结束 19 | void Shutdown(); 20 | 21 | private: 22 | //! 处理事件 23 | void Event(); 24 | //! 更新各种状态 25 | void Update(); 26 | //! 渲染 27 | void Draw(); 28 | 29 | class SDL_Window* mWindow; //!< 窗口 30 | class SDL_Renderer* mRenderer; //!< 渲染器 31 | bool mIsRunning; //!< 运行状态 32 | }; 33 | } 34 | 35 | #endif // __Dungeon_Game__ -------------------------------------------------------------------------------- /Chapter10/Dungeon.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PATH=bin 5 | $(LocalDebuggerEnvironment) 6 | WindowsLocalDebugger 7 | 8 | 9 | PATH=bin 10 | $(LocalDebuggerEnvironment) 11 | WindowsLocalDebugger 12 | 13 | -------------------------------------------------------------------------------- /Chapter6/Dungeon.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PATH=bin 5 | $(LocalDebuggerEnvironment) 6 | WindowsLocalDebugger 7 | 8 | 9 | PATH=bin 10 | $(LocalDebuggerEnvironment) 11 | WindowsLocalDebugger 12 | 13 | -------------------------------------------------------------------------------- /Chapter7/Dungeon.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PATH=bin 5 | $(LocalDebuggerEnvironment) 6 | WindowsLocalDebugger 7 | 8 | 9 | PATH=bin 10 | $(LocalDebuggerEnvironment) 11 | WindowsLocalDebugger 12 | 13 | -------------------------------------------------------------------------------- /Chapter8/Dungeon.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PATH=bin 5 | $(LocalDebuggerEnvironment) 6 | WindowsLocalDebugger 7 | 8 | 9 | PATH=bin 10 | $(LocalDebuggerEnvironment) 11 | WindowsLocalDebugger 12 | 13 | -------------------------------------------------------------------------------- /Chapter9/Dungeon.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PATH=bin 5 | $(LocalDebuggerEnvironment) 6 | WindowsLocalDebugger 7 | 8 | 9 | PATH=bin 10 | $(LocalDebuggerEnvironment) 11 | WindowsLocalDebugger 12 | 13 | -------------------------------------------------------------------------------- /Chapter2/Dungeon.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PATH=bin 5 | $(LocalDebuggerEnvironment) 6 | WindowsLocalDebugger 7 | 8 | 9 | PATH=bin 10 | $(LocalDebuggerEnvironment) 11 | WindowsLocalDebugger 12 | 13 | -------------------------------------------------------------------------------- /Chapter3/Dungeon.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PATH=bin 5 | $(LocalDebuggerEnvironment) 6 | WindowsLocalDebugger 7 | 8 | 9 | PATH=bin 10 | $(LocalDebuggerEnvironment) 11 | WindowsLocalDebugger 12 | 13 | -------------------------------------------------------------------------------- /Chapter4/Dungeon.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PATH=bin 5 | $(LocalDebuggerEnvironment) 6 | WindowsLocalDebugger 7 | 8 | 9 | PATH=bin 10 | $(LocalDebuggerEnvironment) 11 | WindowsLocalDebugger 12 | 13 | -------------------------------------------------------------------------------- /Chapter5/Dungeon.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PATH=bin 5 | $(LocalDebuggerEnvironment) 6 | WindowsLocalDebugger 7 | 8 | 9 | PATH=bin 10 | $(LocalDebuggerEnvironment) 11 | WindowsLocalDebugger 12 | 13 | -------------------------------------------------------------------------------- /Chapter6/src/Component.cpp: -------------------------------------------------------------------------------- 1 | //! @file Component.cpp 2 | 3 | #include 4 | #include 5 | 6 | namespace Dungeon 7 | { 8 | Component::Component(GameObject* gameObject) : 9 | mGameObject(gameObject), 10 | mUpdateOrder(100) 11 | { 12 | mGameObject->AddComponent(this); 13 | } 14 | 15 | Component::~Component() 16 | { 17 | mGameObject->RemoveComponent(this); 18 | } 19 | 20 | void Component::Update() 21 | { 22 | 23 | } 24 | 25 | int Component::GetUpdateOrder() const 26 | { 27 | return mUpdateOrder; 28 | } 29 | 30 | void Component::SetUpdateOrder(int order) 31 | { 32 | mUpdateOrder = order; 33 | } 34 | 35 | GameObject* Component::GetGameObject() 36 | { 37 | return mGameObject; 38 | } 39 | } -------------------------------------------------------------------------------- /Chapter7/src/Component.cpp: -------------------------------------------------------------------------------- 1 | //! @file Component.cpp 2 | 3 | #include 4 | #include 5 | 6 | namespace Dungeon 7 | { 8 | Component::Component(GameObject* gameObject) : 9 | mGameObject(gameObject), 10 | mUpdateOrder(100) 11 | { 12 | mGameObject->AddComponent(this); 13 | } 14 | 15 | Component::~Component() 16 | { 17 | mGameObject->RemoveComponent(this); 18 | } 19 | 20 | void Component::Update() 21 | { 22 | 23 | } 24 | 25 | int Component::GetUpdateOrder() const 26 | { 27 | return mUpdateOrder; 28 | } 29 | 30 | void Component::SetUpdateOrder(int order) 31 | { 32 | mUpdateOrder = order; 33 | } 34 | 35 | GameObject* Component::GetGameObject() 36 | { 37 | return mGameObject; 38 | } 39 | } -------------------------------------------------------------------------------- /Chapter9/include/MapComponent.h: -------------------------------------------------------------------------------- 1 | //! @file MapComponent.h 2 | 3 | #ifndef __Dungeon_MapComponent__ 4 | #define __Dungeon_MapComponent__ 5 | 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | class MapComponent : public SpriteComponent 12 | { 13 | public: 14 | //! 构造函数 15 | MapComponent(class GameObject* gameObject); 16 | //! 析构函数 17 | ~MapComponent(); 18 | 19 | //! 绘制(重写) 20 | void Draw(SDL_Renderer* renderer) override; 21 | //! 设置贴图 22 | void SetTexture(SDL_Texture* texture, int number); 23 | 24 | private: 25 | int* mMapArray; //!< 地图数组 26 | std::unordered_map mTextures; //!< 贴图存储 27 | }; 28 | } 29 | 30 | #endif // __Dungeon_MapComponent__ -------------------------------------------------------------------------------- /Chapter6/include/Component.h: -------------------------------------------------------------------------------- 1 | //! @file Component.h 2 | 3 | #ifndef __Dungeon_Component__ 4 | #define __Dungeon_Component__ 5 | 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | class Component 12 | { 13 | public: 14 | //! 构造函数 15 | Component(class GameObject* gameObject); 16 | //! 析构函数 17 | virtual ~Component(); 18 | 19 | //! 每帧更新 20 | virtual void Update(); 21 | 22 | //! 更新顺序的get和set 23 | int GetUpdateOrder() const; 24 | void SetUpdateOrder(int order); 25 | //! 游戏物体的get 26 | class GameObject* GetGameObject(); 27 | 28 | protected: 29 | class GameObject* mGameObject; //!< 自身附着的游戏物体 30 | int mUpdateOrder; //!< 更新顺序 31 | }; 32 | } 33 | 34 | #endif // __Dungeon_Component__ -------------------------------------------------------------------------------- /Chapter7/include/Component.h: -------------------------------------------------------------------------------- 1 | //! @file Component.h 2 | 3 | #ifndef __Dungeon_Component__ 4 | #define __Dungeon_Component__ 5 | 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | class Component 12 | { 13 | public: 14 | //! 构造函数 15 | Component(class GameObject* gameObject); 16 | //! 析构函数 17 | virtual ~Component(); 18 | 19 | //! 每帧更新 20 | virtual void Update(); 21 | 22 | //! 更新顺序的get和set 23 | int GetUpdateOrder() const; 24 | void SetUpdateOrder(int order); 25 | //! 游戏物体的get 26 | class GameObject* GetGameObject(); 27 | 28 | protected: 29 | class GameObject* mGameObject; //!< 自身附着的游戏物体 30 | int mUpdateOrder; //!< 更新顺序 31 | }; 32 | } 33 | 34 | #endif // __Dungeon_Component__ -------------------------------------------------------------------------------- /Chapter4/include/Component.h: -------------------------------------------------------------------------------- 1 | //! @file Component.h 2 | 3 | #ifndef __Dungeon_Component__ 4 | #define __Dungeon_Component__ 5 | 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | class Component 12 | { 13 | public: 14 | //! 构造函数 15 | Component(class GameObject* gameObject); 16 | //! 析构函数 17 | virtual ~Component(); 18 | 19 | //! 每帧更新 20 | virtual void Update(); 21 | 22 | //! 更新顺序的get和set 23 | int GetUpdateOrder() const; 24 | void SetUpdateOrder(int order); 25 | //! 游戏物体的get 26 | class GameObject* GetGameObject(); 27 | 28 | protected: 29 | class GameObject* mGameObject; //!< 自身附着的游戏物体 30 | int mUpdateOrder; //!< 更新顺序 31 | }; 32 | } 33 | 34 | #endif // __Dungeon_Component__ -------------------------------------------------------------------------------- /Chapter4/src/Component.cpp: -------------------------------------------------------------------------------- 1 | //! @file Component.cpp 2 | 3 | #include 4 | #include 5 | 6 | namespace Dungeon 7 | { 8 | Component::Component(GameObject* gameObject) : 9 | mGameObject(gameObject), 10 | mUpdateOrder(100) 11 | { 12 | mGameObject->AddComponent(this); 13 | } 14 | 15 | Component::~Component() 16 | { 17 | mGameObject->RemoveComponent(this); 18 | } 19 | 20 | void Component::Update() 21 | { 22 | 23 | } 24 | 25 | int Component::GetUpdateOrder() const 26 | { 27 | return mUpdateOrder; 28 | } 29 | 30 | void Component::SetUpdateOrder(int order) 31 | { 32 | mUpdateOrder = order; 33 | } 34 | 35 | GameObject* Component::GetGameObject() 36 | { 37 | return mGameObject; 38 | } 39 | } -------------------------------------------------------------------------------- /Chapter5/include/Component.h: -------------------------------------------------------------------------------- 1 | //! @file Component.h 2 | 3 | #ifndef __Dungeon_Component__ 4 | #define __Dungeon_Component__ 5 | 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | class Component 12 | { 13 | public: 14 | //! 构造函数 15 | Component(class GameObject* gameObject); 16 | //! 析构函数 17 | virtual ~Component(); 18 | 19 | //! 每帧更新 20 | virtual void Update(); 21 | 22 | //! 更新顺序的get和set 23 | int GetUpdateOrder() const; 24 | void SetUpdateOrder(int order); 25 | //! 游戏物体的get 26 | class GameObject* GetGameObject(); 27 | 28 | protected: 29 | class GameObject* mGameObject; //!< 自身附着的游戏物体 30 | int mUpdateOrder; //!< 更新顺序 31 | }; 32 | } 33 | 34 | #endif // __Dungeon_Component__ -------------------------------------------------------------------------------- /Chapter5/src/Component.cpp: -------------------------------------------------------------------------------- 1 | //! @file Component.cpp 2 | 3 | #include 4 | #include 5 | 6 | namespace Dungeon 7 | { 8 | Component::Component(GameObject* gameObject) : 9 | mGameObject(gameObject), 10 | mUpdateOrder(100) 11 | { 12 | mGameObject->AddComponent(this); 13 | } 14 | 15 | Component::~Component() 16 | { 17 | mGameObject->RemoveComponent(this); 18 | } 19 | 20 | void Component::Update() 21 | { 22 | 23 | } 24 | 25 | int Component::GetUpdateOrder() const 26 | { 27 | return mUpdateOrder; 28 | } 29 | 30 | void Component::SetUpdateOrder(int order) 31 | { 32 | mUpdateOrder = order; 33 | } 34 | 35 | GameObject* Component::GetGameObject() 36 | { 37 | return mGameObject; 38 | } 39 | } -------------------------------------------------------------------------------- /Chapter10/include/MapComponent.h: -------------------------------------------------------------------------------- 1 | //! @file MapComponent.h 2 | 3 | #ifndef __Dungeon_MapComponent__ 4 | #define __Dungeon_MapComponent__ 5 | 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | class MapComponent : public SpriteComponent 12 | { 13 | public: 14 | //! 构造函数 15 | MapComponent(class GameObject* gameObject); 16 | //! 析构函数 17 | ~MapComponent(); 18 | 19 | //! 绘制(重写) 20 | void Draw(SDL_Renderer* renderer) override; 21 | //! 设置贴图 22 | void SetTexture(SDL_Texture* texture, int number); 23 | 24 | //! 获取地图数组 25 | int* GetMap(); 26 | 27 | private: 28 | int* mMapArray; //!< 地图数组 29 | std::unordered_map mTextures; //!< 贴图存储 30 | }; 31 | } 32 | 33 | #endif // __Dungeon_MapComponent__ -------------------------------------------------------------------------------- /Chapter10/src/Component.cpp: -------------------------------------------------------------------------------- 1 | //! @file Component.cpp 2 | 3 | #include 4 | #include 5 | 6 | namespace Dungeon 7 | { 8 | Component::Component(GameObject* gameObject) : 9 | mGameObject(gameObject), 10 | mUpdateOrder(100) 11 | { 12 | mGameObject->AddComponent(this); 13 | } 14 | 15 | Component::~Component() 16 | { 17 | mGameObject->RemoveComponent(this); 18 | } 19 | 20 | void Component::ProcessInput(const uint8_t* state) 21 | { 22 | } 23 | 24 | void Component::Update() 25 | { 26 | } 27 | 28 | int Component::GetUpdateOrder() const 29 | { 30 | return mUpdateOrder; 31 | } 32 | 33 | void Component::SetUpdateOrder(int order) 34 | { 35 | mUpdateOrder = order; 36 | } 37 | 38 | GameObject* Component::GetGameObject() 39 | { 40 | return mGameObject; 41 | } 42 | } -------------------------------------------------------------------------------- /Chapter8/src/Component.cpp: -------------------------------------------------------------------------------- 1 | //! @file Component.cpp 2 | 3 | #include 4 | #include 5 | 6 | namespace Dungeon 7 | { 8 | Component::Component(GameObject* gameObject) : 9 | mGameObject(gameObject), 10 | mUpdateOrder(100) 11 | { 12 | mGameObject->AddComponent(this); 13 | } 14 | 15 | Component::~Component() 16 | { 17 | mGameObject->RemoveComponent(this); 18 | } 19 | 20 | void Component::ProcessInput(const uint8_t* state) 21 | { 22 | } 23 | 24 | void Component::Update() 25 | { 26 | } 27 | 28 | int Component::GetUpdateOrder() const 29 | { 30 | return mUpdateOrder; 31 | } 32 | 33 | void Component::SetUpdateOrder(int order) 34 | { 35 | mUpdateOrder = order; 36 | } 37 | 38 | GameObject* Component::GetGameObject() 39 | { 40 | return mGameObject; 41 | } 42 | } -------------------------------------------------------------------------------- /Chapter9/src/Component.cpp: -------------------------------------------------------------------------------- 1 | //! @file Component.cpp 2 | 3 | #include 4 | #include 5 | 6 | namespace Dungeon 7 | { 8 | Component::Component(GameObject* gameObject) : 9 | mGameObject(gameObject), 10 | mUpdateOrder(100) 11 | { 12 | mGameObject->AddComponent(this); 13 | } 14 | 15 | Component::~Component() 16 | { 17 | mGameObject->RemoveComponent(this); 18 | } 19 | 20 | void Component::ProcessInput(const uint8_t* state) 21 | { 22 | } 23 | 24 | void Component::Update() 25 | { 26 | } 27 | 28 | int Component::GetUpdateOrder() const 29 | { 30 | return mUpdateOrder; 31 | } 32 | 33 | void Component::SetUpdateOrder(int order) 34 | { 35 | mUpdateOrder = order; 36 | } 37 | 38 | GameObject* Component::GetGameObject() 39 | { 40 | return mGameObject; 41 | } 42 | } -------------------------------------------------------------------------------- /Chapter10/include/Component.h: -------------------------------------------------------------------------------- 1 | //! @file Component.h 2 | 3 | #ifndef __Dungeon_Component__ 4 | #define __Dungeon_Component__ 5 | 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | class GameObject; 12 | 13 | class Component 14 | { 15 | public: 16 | //! 构造函数 17 | Component(class GameObject* gameObject); 18 | //! 析构函数 19 | virtual ~Component(); 20 | 21 | //! 处理输入 22 | virtual void ProcessInput(const uint8_t* state); 23 | //! 每帧更新 24 | virtual void Update(); 25 | 26 | //! 更新顺序的get和set 27 | int GetUpdateOrder() const; 28 | void SetUpdateOrder(int order); 29 | //! 游戏物体的get 30 | GameObject* GetGameObject(); 31 | 32 | protected: 33 | GameObject* mGameObject; //!< 自身附着的游戏物体 34 | int mUpdateOrder; //!< 更新顺序 35 | }; 36 | } 37 | 38 | #endif // __Dungeon_Component__ -------------------------------------------------------------------------------- /Chapter8/include/Component.h: -------------------------------------------------------------------------------- 1 | //! @file Component.h 2 | 3 | #ifndef __Dungeon_Component__ 4 | #define __Dungeon_Component__ 5 | 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | class GameObject; 12 | 13 | class Component 14 | { 15 | public: 16 | //! 构造函数 17 | Component(class GameObject* gameObject); 18 | //! 析构函数 19 | virtual ~Component(); 20 | 21 | //! 处理输入 22 | virtual void ProcessInput(const uint8_t* state); 23 | //! 每帧更新 24 | virtual void Update(); 25 | 26 | //! 更新顺序的get和set 27 | int GetUpdateOrder() const; 28 | void SetUpdateOrder(int order); 29 | //! 游戏物体的get 30 | GameObject* GetGameObject(); 31 | 32 | protected: 33 | GameObject* mGameObject; //!< 自身附着的游戏物体 34 | int mUpdateOrder; //!< 更新顺序 35 | }; 36 | } 37 | 38 | #endif // __Dungeon_Component__ -------------------------------------------------------------------------------- /Chapter9/include/Component.h: -------------------------------------------------------------------------------- 1 | //! @file Component.h 2 | 3 | #ifndef __Dungeon_Component__ 4 | #define __Dungeon_Component__ 5 | 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | class GameObject; 12 | 13 | class Component 14 | { 15 | public: 16 | //! 构造函数 17 | Component(class GameObject* gameObject); 18 | //! 析构函数 19 | virtual ~Component(); 20 | 21 | //! 处理输入 22 | virtual void ProcessInput(const uint8_t* state); 23 | //! 每帧更新 24 | virtual void Update(); 25 | 26 | //! 更新顺序的get和set 27 | int GetUpdateOrder() const; 28 | void SetUpdateOrder(int order); 29 | //! 游戏物体的get 30 | GameObject* GetGameObject(); 31 | 32 | protected: 33 | GameObject* mGameObject; //!< 自身附着的游戏物体 34 | int mUpdateOrder; //!< 更新顺序 35 | }; 36 | } 37 | 38 | #endif // __Dungeon_Component__ -------------------------------------------------------------------------------- /Chapter3/include/Game.h: -------------------------------------------------------------------------------- 1 | //! @file Game.h 2 | 3 | #ifndef __Dungeon_Game__ 4 | #define __Dungeon_Game__ 5 | 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | class Game 11 | { 12 | public: 13 | //! 构造函数 14 | Game(); 15 | 16 | //! 初始化 17 | bool Initialize(); 18 | //! 主循环 19 | void Loop(); 20 | //! 游戏结束 21 | void Shutdown(); 22 | 23 | private: 24 | //! 处理事件 25 | void Event(); 26 | //! 更新各种状态 27 | void Update(); 28 | //! 渲染 29 | void Draw(); 30 | 31 | //! 加载数据 32 | void LoadData(); 33 | //! 释放数据 34 | void UnloadData(); 35 | //! 加载贴图 36 | void LoadTexture(const std::string fileName); 37 | 38 | class SDL_Window* mWindow; //!< 窗口 39 | class SDL_Renderer* mRenderer; //!< 渲染器 40 | bool mIsRunning; //!< 运行状态 41 | 42 | class SDL_Texture* mTexture; //!< 图片 43 | }; 44 | } 45 | 46 | #endif // __Dungeon_Game__ -------------------------------------------------------------------------------- /Chapter10/src/InputComponent.cpp: -------------------------------------------------------------------------------- 1 | //! @file InputComponent.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | InputComponent::InputComponent(GameObject* gameObject) : 11 | Component(gameObject) 12 | { 13 | } 14 | 15 | void InputComponent::ProcessInput(const uint8_t* state) 16 | { 17 | MoveComponent* mc = mGameObject->GetComponent(); 18 | if (state[SDL_SCANCODE_W] || state[SDL_SCANCODE_UP]) 19 | { 20 | mc->SetDir(Vector2::NY); 21 | } 22 | else if (state[SDL_SCANCODE_S] || state[SDL_SCANCODE_DOWN]) 23 | { 24 | mc->SetDir(Vector2::Y); 25 | } 26 | else if (state[SDL_SCANCODE_A] || state[SDL_SCANCODE_LEFT]) 27 | { 28 | mc->SetDir(Vector2::NX); 29 | } 30 | else if (state[SDL_SCANCODE_D] || state[SDL_SCANCODE_RIGHT]) 31 | { 32 | mc->SetDir(Vector2::X); 33 | } 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /Chapter4/include/GameObject.h: -------------------------------------------------------------------------------- 1 | //! @file GameObject.h 2 | 3 | #ifndef __Dungeon_GameObject__ 4 | #define __Dungeon_GameObject__ 5 | 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | class GameObject 12 | { 13 | public: 14 | //! 物体状态 15 | enum class State 16 | { 17 | EActive, 18 | EDead 19 | }; 20 | 21 | //! 构造函数 22 | GameObject(class Game* game); 23 | //! 析构函数 24 | virtual ~GameObject(); 25 | 26 | //! 每帧更新 27 | void Update(); 28 | //! 添加组件 29 | void AddComponent(class Component* component); 30 | //! 移除组件 31 | void RemoveComponent(class Component* component); 32 | 33 | //! 物体状态的get和set 34 | State GetState() const; 35 | void SetState(State state); 36 | 37 | protected: 38 | std::vector mComponents; //!< 组件数组 39 | 40 | private: 41 | class Game* mGame; //!< Game对象 42 | State mState; //!< 物体当前状态 43 | }; 44 | } 45 | 46 | #endif // __Dungeon_GameObject__ -------------------------------------------------------------------------------- /Chapter8/src/InputComponent.cpp: -------------------------------------------------------------------------------- 1 | //! @file InputComponent.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | InputComponent::InputComponent(GameObject* gameObject) : 11 | Component(gameObject) 12 | { 13 | } 14 | 15 | void InputComponent::ProcessInput(const uint8_t* state) 16 | { 17 | MoveComponent* mc = mGameObject->GetComponent(); 18 | if (state[SDL_SCANCODE_W] || state[SDL_SCANCODE_UP]) 19 | { 20 | mc->SetDir(Vector2::NY); 21 | } 22 | else if (state[SDL_SCANCODE_S] || state[SDL_SCANCODE_DOWN]) 23 | { 24 | mc->SetDir(Vector2::Y); 25 | } 26 | else if (state[SDL_SCANCODE_A] || state[SDL_SCANCODE_LEFT]) 27 | { 28 | mc->SetDir(Vector2::NX); 29 | } 30 | else if (state[SDL_SCANCODE_D] || state[SDL_SCANCODE_RIGHT]) 31 | { 32 | mc->SetDir(Vector2::X); 33 | } 34 | else 35 | { 36 | mc->SetDir(Vector2::Zero); 37 | } 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /Chapter9/src/InputComponent.cpp: -------------------------------------------------------------------------------- 1 | //! @file InputComponent.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | InputComponent::InputComponent(GameObject* gameObject) : 11 | Component(gameObject) 12 | { 13 | } 14 | 15 | void InputComponent::ProcessInput(const uint8_t* state) 16 | { 17 | MoveComponent* mc = mGameObject->GetComponent(); 18 | if (state[SDL_SCANCODE_W] || state[SDL_SCANCODE_UP]) 19 | { 20 | mc->SetDir(Vector2::NY); 21 | } 22 | else if (state[SDL_SCANCODE_S] || state[SDL_SCANCODE_DOWN]) 23 | { 24 | mc->SetDir(Vector2::Y); 25 | } 26 | else if (state[SDL_SCANCODE_A] || state[SDL_SCANCODE_LEFT]) 27 | { 28 | mc->SetDir(Vector2::NX); 29 | } 30 | else if (state[SDL_SCANCODE_D] || state[SDL_SCANCODE_RIGHT]) 31 | { 32 | mc->SetDir(Vector2::X); 33 | } 34 | else 35 | { 36 | mc->SetDir(Vector2::Zero); 37 | } 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /Chapter10/include/MoveComponent.h: -------------------------------------------------------------------------------- 1 | //! @file MoveComponent.h 2 | 3 | #ifndef __Dungeon_MoveComponent__ 4 | #define __Dungeon_MoveComponent__ 5 | 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | class GameObject; 12 | 13 | class MoveComponent : public Component 14 | { 15 | public: 16 | //! 构造函数 17 | MoveComponent(GameObject* gameObject); 18 | 19 | //! 每帧更新(重写) 20 | void Update() override; 21 | 22 | //! 设置移动方向并判断是否移动 23 | void SetDir(const Vector2& dir); 24 | //! 设置地图数据 25 | void SetMap(int* map); 26 | 27 | private: 28 | //! 处理移动过程中每帧的更新 29 | void ProcessMoving(); 30 | //! 检测与地图上墙的碰撞 31 | bool WallCheck(const Vector2& dst); 32 | //! 处理到达一个格子后的各种操作 33 | void ReachOneGrid(); 34 | 35 | float mSpeed; //!< 移动速度 36 | Vector2 mDir; //!< 移动方向 37 | Vector2 mDst; //!< 移动目的地 38 | bool mIsMoving; //!< 是否在运动中 39 | float mPixelsCount; //!< 已走过的像素数 40 | 41 | int* mMapArray; //!< 地图数组 42 | }; 43 | } 44 | 45 | #endif // __Dungeon_MoveComponent__ -------------------------------------------------------------------------------- /Chapter1/include/SDL/SDL_copying.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2017 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | -------------------------------------------------------------------------------- /Chapter10/include/SDL/SDL_copying.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2017 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | -------------------------------------------------------------------------------- /Chapter2/include/SDL/SDL_copying.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2017 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | -------------------------------------------------------------------------------- /Chapter3/include/SDL/SDL_copying.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2017 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | -------------------------------------------------------------------------------- /Chapter4/include/SDL/SDL_copying.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2017 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | -------------------------------------------------------------------------------- /Chapter5/include/SDL/SDL_copying.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2017 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | -------------------------------------------------------------------------------- /Chapter6/include/SDL/SDL_copying.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2017 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | -------------------------------------------------------------------------------- /Chapter7/include/SDL/SDL_copying.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2017 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | -------------------------------------------------------------------------------- /Chapter8/include/SDL/SDL_copying.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2017 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | -------------------------------------------------------------------------------- /Chapter9/include/SDL/SDL_copying.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2017 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | -------------------------------------------------------------------------------- /Chapter10/include/SpriteComponent.h: -------------------------------------------------------------------------------- 1 | //! @file SpriteComponent.h 2 | 3 | #ifndef __Dungeon_SpriteComponent__ 4 | #define __Dungeon_SpriteComponent__ 5 | 6 | #include 7 | 8 | struct SDL_Texture; 9 | struct SDL_Renderer; 10 | 11 | namespace Dungeon 12 | { 13 | class GameObject; 14 | 15 | class SpriteComponent : public Component 16 | { 17 | public: 18 | //! 构造函数 19 | SpriteComponent(GameObject* gameObject, int drawOrder); 20 | //! 析构函数 21 | ~SpriteComponent(); 22 | 23 | //! 绘制函数 24 | virtual void Draw(SDL_Renderer* renderer); 25 | //! 设置贴图 26 | virtual void SetTexture(SDL_Texture* texture); 27 | 28 | //! 贴图宽度的get 29 | int GetTexWidth() const; 30 | //! 贴图高度的get 31 | int GetTexHeight() const; 32 | //! 绘制顺序的get和set 33 | int GetDrawOrder() const; 34 | void SetDrawOrder(int order); 35 | 36 | protected: 37 | SDL_Texture* mTexture; //!< 贴图 38 | int mDrawOrder; //!< 绘制顺序 39 | int mTexWidth; //!< 贴图宽 40 | int mTexHeight; //!< 贴图高 41 | }; 42 | } 43 | 44 | #endif // __Dungeon_SpriteComponent__ -------------------------------------------------------------------------------- /Chapter6/include/SpriteComponent.h: -------------------------------------------------------------------------------- 1 | //! @file SpriteComponent.h 2 | 3 | #ifndef __Dungeon_SpriteComponent__ 4 | #define __Dungeon_SpriteComponent__ 5 | 6 | #include 7 | 8 | struct SDL_Texture; 9 | struct SDL_Renderer; 10 | 11 | namespace Dungeon 12 | { 13 | class GameObject; 14 | 15 | class SpriteComponent : public Component 16 | { 17 | public: 18 | //! 构造函数 19 | SpriteComponent(GameObject* gameObject, int drawOrder); 20 | //! 析构函数 21 | ~SpriteComponent(); 22 | 23 | //! 绘制函数 24 | virtual void Draw(SDL_Renderer* renderer); 25 | //! 设置贴图 26 | virtual void SetTexture(SDL_Texture* texture); 27 | 28 | //! 贴图宽度的get 29 | int GetTexWidth() const; 30 | //! 贴图高度的get 31 | int GetTexHeight() const; 32 | //! 绘制顺序的get和set 33 | int GetDrawOrder() const; 34 | void SetDrawOrder(int order); 35 | 36 | protected: 37 | SDL_Texture* mTexture; //!< 贴图 38 | int mDrawOrder; //!< 绘制顺序 39 | int mTexWidth; //!< 贴图宽 40 | int mTexHeight; //!< 贴图高 41 | }; 42 | } 43 | 44 | #endif // __Dungeon_SpriteComponent__ -------------------------------------------------------------------------------- /Chapter7/include/SpriteComponent.h: -------------------------------------------------------------------------------- 1 | //! @file SpriteComponent.h 2 | 3 | #ifndef __Dungeon_SpriteComponent__ 4 | #define __Dungeon_SpriteComponent__ 5 | 6 | #include 7 | 8 | struct SDL_Texture; 9 | struct SDL_Renderer; 10 | 11 | namespace Dungeon 12 | { 13 | class GameObject; 14 | 15 | class SpriteComponent : public Component 16 | { 17 | public: 18 | //! 构造函数 19 | SpriteComponent(GameObject* gameObject, int drawOrder); 20 | //! 析构函数 21 | ~SpriteComponent(); 22 | 23 | //! 绘制函数 24 | virtual void Draw(SDL_Renderer* renderer); 25 | //! 设置贴图 26 | virtual void SetTexture(SDL_Texture* texture); 27 | 28 | //! 贴图宽度的get 29 | int GetTexWidth() const; 30 | //! 贴图高度的get 31 | int GetTexHeight() const; 32 | //! 绘制顺序的get和set 33 | int GetDrawOrder() const; 34 | void SetDrawOrder(int order); 35 | 36 | protected: 37 | SDL_Texture* mTexture; //!< 贴图 38 | int mDrawOrder; //!< 绘制顺序 39 | int mTexWidth; //!< 贴图宽 40 | int mTexHeight; //!< 贴图高 41 | }; 42 | } 43 | 44 | #endif // __Dungeon_SpriteComponent__ -------------------------------------------------------------------------------- /Chapter8/include/SpriteComponent.h: -------------------------------------------------------------------------------- 1 | //! @file SpriteComponent.h 2 | 3 | #ifndef __Dungeon_SpriteComponent__ 4 | #define __Dungeon_SpriteComponent__ 5 | 6 | #include 7 | 8 | struct SDL_Texture; 9 | struct SDL_Renderer; 10 | 11 | namespace Dungeon 12 | { 13 | class GameObject; 14 | 15 | class SpriteComponent : public Component 16 | { 17 | public: 18 | //! 构造函数 19 | SpriteComponent(GameObject* gameObject, int drawOrder); 20 | //! 析构函数 21 | ~SpriteComponent(); 22 | 23 | //! 绘制函数 24 | virtual void Draw(SDL_Renderer* renderer); 25 | //! 设置贴图 26 | virtual void SetTexture(SDL_Texture* texture); 27 | 28 | //! 贴图宽度的get 29 | int GetTexWidth() const; 30 | //! 贴图高度的get 31 | int GetTexHeight() const; 32 | //! 绘制顺序的get和set 33 | int GetDrawOrder() const; 34 | void SetDrawOrder(int order); 35 | 36 | protected: 37 | SDL_Texture* mTexture; //!< 贴图 38 | int mDrawOrder; //!< 绘制顺序 39 | int mTexWidth; //!< 贴图宽 40 | int mTexHeight; //!< 贴图高 41 | }; 42 | } 43 | 44 | #endif // __Dungeon_SpriteComponent__ -------------------------------------------------------------------------------- /Chapter9/include/SpriteComponent.h: -------------------------------------------------------------------------------- 1 | //! @file SpriteComponent.h 2 | 3 | #ifndef __Dungeon_SpriteComponent__ 4 | #define __Dungeon_SpriteComponent__ 5 | 6 | #include 7 | 8 | struct SDL_Texture; 9 | struct SDL_Renderer; 10 | 11 | namespace Dungeon 12 | { 13 | class GameObject; 14 | 15 | class SpriteComponent : public Component 16 | { 17 | public: 18 | //! 构造函数 19 | SpriteComponent(GameObject* gameObject, int drawOrder); 20 | //! 析构函数 21 | ~SpriteComponent(); 22 | 23 | //! 绘制函数 24 | virtual void Draw(SDL_Renderer* renderer); 25 | //! 设置贴图 26 | virtual void SetTexture(SDL_Texture* texture); 27 | 28 | //! 贴图宽度的get 29 | int GetTexWidth() const; 30 | //! 贴图高度的get 31 | int GetTexHeight() const; 32 | //! 绘制顺序的get和set 33 | int GetDrawOrder() const; 34 | void SetDrawOrder(int order); 35 | 36 | protected: 37 | SDL_Texture* mTexture; //!< 贴图 38 | int mDrawOrder; //!< 绘制顺序 39 | int mTexWidth; //!< 贴图宽 40 | int mTexHeight; //!< 贴图高 41 | }; 42 | } 43 | 44 | #endif // __Dungeon_SpriteComponent__ -------------------------------------------------------------------------------- /Chapter10/include/Math/Math.h: -------------------------------------------------------------------------------- 1 | //! @file Math.h 2 | 3 | #ifndef __Dungeon_Math__ 4 | #define __Dungeon_Math__ 5 | 6 | namespace Dungeon 7 | { 8 | class Vector2 9 | { 10 | public: 11 | float x; 12 | float y; 13 | 14 | Vector2(); 15 | Vector2(float X, float Y); 16 | 17 | static const Vector2 Zero; //!< (0 , 0) 18 | static const Vector2 One; //!< (1 , 1) 19 | static const Vector2 X; //!< (1 , 0) 20 | static const Vector2 Y; //!< (0 , 1) 21 | static const Vector2 NX; //!< (-1, 0) 22 | static const Vector2 NY; //!< (0 ,-1) 23 | 24 | //! 向量加法 25 | friend Vector2 operator+(const Vector2& a, const Vector2& b); 26 | //! 向量减法 27 | friend Vector2 operator-(const Vector2& a, const Vector2& b); 28 | //! 向量乘法(均为向量,对应元素相乘) 29 | friend Vector2 operator*(const Vector2& a, const Vector2& b); 30 | //! 向量乘法(向量与标量相乘) 31 | friend Vector2 operator*(const Vector2& vec, float scalar); 32 | //! 向量乘法(标量与向量相乘) 33 | friend Vector2 operator*(float scalar, const Vector2& vec); 34 | //! 向量相等 35 | friend bool operator==(const Vector2& a, const Vector2& b); 36 | }; 37 | } 38 | 39 | #endif // __Dungeon_Math__ -------------------------------------------------------------------------------- /Chapter6/include/Math/Math.h: -------------------------------------------------------------------------------- 1 | //! @file Math.h 2 | 3 | #ifndef __Dungeon_Math__ 4 | #define __Dungeon_Math__ 5 | 6 | namespace Dungeon 7 | { 8 | class Vector2 9 | { 10 | public: 11 | float x; 12 | float y; 13 | 14 | Vector2(); 15 | Vector2(float X, float Y); 16 | 17 | static const Vector2 Zero; //!< (0 , 0) 18 | static const Vector2 One; //!< (1 , 1) 19 | static const Vector2 X; //!< (1 , 0) 20 | static const Vector2 Y; //!< (0 , 1) 21 | static const Vector2 NX; //!< (-1, 0) 22 | static const Vector2 NY; //!< (0 ,-1) 23 | 24 | //! 向量加法 25 | friend Vector2 operator+(const Vector2& a, const Vector2& b); 26 | //! 向量减法 27 | friend Vector2 operator-(const Vector2& a, const Vector2& b); 28 | //! 向量乘法(均为向量,对应元素相乘) 29 | friend Vector2 operator*(const Vector2& a, const Vector2& b); 30 | //! 向量乘法(向量与标量相乘) 31 | friend Vector2 operator*(const Vector2& vec, float scalar); 32 | //! 向量乘法(标量与向量相乘) 33 | friend Vector2 operator*(float scalar, const Vector2& vec); 34 | //! 向量相等 35 | friend bool operator==(const Vector2& a, const Vector2& b); 36 | }; 37 | } 38 | 39 | #endif // __Dungeon_Math__ -------------------------------------------------------------------------------- /Chapter7/include/Math/Math.h: -------------------------------------------------------------------------------- 1 | //! @file Math.h 2 | 3 | #ifndef __Dungeon_Math__ 4 | #define __Dungeon_Math__ 5 | 6 | namespace Dungeon 7 | { 8 | class Vector2 9 | { 10 | public: 11 | float x; 12 | float y; 13 | 14 | Vector2(); 15 | Vector2(float X, float Y); 16 | 17 | static const Vector2 Zero; //!< (0 , 0) 18 | static const Vector2 One; //!< (1 , 1) 19 | static const Vector2 X; //!< (1 , 0) 20 | static const Vector2 Y; //!< (0 , 1) 21 | static const Vector2 NX; //!< (-1, 0) 22 | static const Vector2 NY; //!< (0 ,-1) 23 | 24 | //! 向量加法 25 | friend Vector2 operator+(const Vector2& a, const Vector2& b); 26 | //! 向量减法 27 | friend Vector2 operator-(const Vector2& a, const Vector2& b); 28 | //! 向量乘法(均为向量,对应元素相乘) 29 | friend Vector2 operator*(const Vector2& a, const Vector2& b); 30 | //! 向量乘法(向量与标量相乘) 31 | friend Vector2 operator*(const Vector2& vec, float scalar); 32 | //! 向量乘法(标量与向量相乘) 33 | friend Vector2 operator*(float scalar, const Vector2& vec); 34 | //! 向量相等 35 | friend bool operator==(const Vector2& a, const Vector2& b); 36 | }; 37 | } 38 | 39 | #endif // __Dungeon_Math__ -------------------------------------------------------------------------------- /Chapter8/include/Math/Math.h: -------------------------------------------------------------------------------- 1 | //! @file Math.h 2 | 3 | #ifndef __Dungeon_Math__ 4 | #define __Dungeon_Math__ 5 | 6 | namespace Dungeon 7 | { 8 | class Vector2 9 | { 10 | public: 11 | float x; 12 | float y; 13 | 14 | Vector2(); 15 | Vector2(float X, float Y); 16 | 17 | static const Vector2 Zero; //!< (0 , 0) 18 | static const Vector2 One; //!< (1 , 1) 19 | static const Vector2 X; //!< (1 , 0) 20 | static const Vector2 Y; //!< (0 , 1) 21 | static const Vector2 NX; //!< (-1, 0) 22 | static const Vector2 NY; //!< (0 ,-1) 23 | 24 | //! 向量加法 25 | friend Vector2 operator+(const Vector2& a, const Vector2& b); 26 | //! 向量减法 27 | friend Vector2 operator-(const Vector2& a, const Vector2& b); 28 | //! 向量乘法(均为向量,对应元素相乘) 29 | friend Vector2 operator*(const Vector2& a, const Vector2& b); 30 | //! 向量乘法(向量与标量相乘) 31 | friend Vector2 operator*(const Vector2& vec, float scalar); 32 | //! 向量乘法(标量与向量相乘) 33 | friend Vector2 operator*(float scalar, const Vector2& vec); 34 | //! 向量相等 35 | friend bool operator==(const Vector2& a, const Vector2& b); 36 | }; 37 | } 38 | 39 | #endif // __Dungeon_Math__ -------------------------------------------------------------------------------- /Chapter9/include/Math/Math.h: -------------------------------------------------------------------------------- 1 | //! @file Math.h 2 | 3 | #ifndef __Dungeon_Math__ 4 | #define __Dungeon_Math__ 5 | 6 | namespace Dungeon 7 | { 8 | class Vector2 9 | { 10 | public: 11 | float x; 12 | float y; 13 | 14 | Vector2(); 15 | Vector2(float X, float Y); 16 | 17 | static const Vector2 Zero; //!< (0 , 0) 18 | static const Vector2 One; //!< (1 , 1) 19 | static const Vector2 X; //!< (1 , 0) 20 | static const Vector2 Y; //!< (0 , 1) 21 | static const Vector2 NX; //!< (-1, 0) 22 | static const Vector2 NY; //!< (0 ,-1) 23 | 24 | //! 向量加法 25 | friend Vector2 operator+(const Vector2& a, const Vector2& b); 26 | //! 向量减法 27 | friend Vector2 operator-(const Vector2& a, const Vector2& b); 28 | //! 向量乘法(均为向量,对应元素相乘) 29 | friend Vector2 operator*(const Vector2& a, const Vector2& b); 30 | //! 向量乘法(向量与标量相乘) 31 | friend Vector2 operator*(const Vector2& vec, float scalar); 32 | //! 向量乘法(标量与向量相乘) 33 | friend Vector2 operator*(float scalar, const Vector2& vec); 34 | //! 向量相等 35 | friend bool operator==(const Vector2& a, const Vector2& b); 36 | }; 37 | } 38 | 39 | #endif // __Dungeon_Math__ -------------------------------------------------------------------------------- /Chapter5/include/Math/Math.h: -------------------------------------------------------------------------------- 1 | //! @file Math.h 2 | 3 | #ifndef __Dungeon_Math__ 4 | #define __Dungeon_Math__ 5 | 6 | namespace Dungeon 7 | { 8 | class Vector2 9 | { 10 | public: 11 | float x; 12 | float y; 13 | 14 | Vector2(); 15 | Vector2(float X, float Y); 16 | 17 | static const Vector2 Zero; //!< (0 , 0) 18 | static const Vector2 One; //!< (1 , 1) 19 | static const Vector2 X; //!< (1 , 0) 20 | static const Vector2 Y; //!< (0 , 1) 21 | static const Vector2 NX; //!< (-1, 0) 22 | static const Vector2 NY; //!< (0 ,-1) 23 | 24 | //! 向量加法 25 | friend Vector2 operator+(const Vector2& a, const Vector2& b); 26 | //! 向量减法 27 | friend Vector2 operator-(const Vector2& a, const Vector2& b); 28 | //! 向量乘法(均为向量,对应元素相乘) 29 | friend Vector2 operator*(const Vector2& a, const Vector2& b); 30 | //! 向量乘法(向量与标量相乘) 31 | friend Vector2 operator*(const Vector2& vec, float scalar); 32 | //! 向量乘法(标量与向量相乘) 33 | friend Vector2 operator*(float scalar, const Vector2& vec); 34 | //! 向量相等 35 | friend bool operator==(const Vector2& a, const Vector2& b); 36 | }; 37 | } 38 | 39 | #endif // __Dungeon_Math__ -------------------------------------------------------------------------------- /Chapter1/include/SDL/SDL_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_types.h 24 | * 25 | * \deprecated 26 | */ 27 | 28 | /* DEPRECATED */ 29 | #include "SDL_stdinc.h" 30 | -------------------------------------------------------------------------------- /Chapter10/include/SDL/SDL_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_types.h 24 | * 25 | * \deprecated 26 | */ 27 | 28 | /* DEPRECATED */ 29 | #include "SDL_stdinc.h" 30 | -------------------------------------------------------------------------------- /Chapter2/include/SDL/SDL_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_types.h 24 | * 25 | * \deprecated 26 | */ 27 | 28 | /* DEPRECATED */ 29 | #include "SDL_stdinc.h" 30 | -------------------------------------------------------------------------------- /Chapter3/include/SDL/SDL_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_types.h 24 | * 25 | * \deprecated 26 | */ 27 | 28 | /* DEPRECATED */ 29 | #include "SDL_stdinc.h" 30 | -------------------------------------------------------------------------------- /Chapter4/include/SDL/SDL_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_types.h 24 | * 25 | * \deprecated 26 | */ 27 | 28 | /* DEPRECATED */ 29 | #include "SDL_stdinc.h" 30 | -------------------------------------------------------------------------------- /Chapter5/include/SDL/SDL_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_types.h 24 | * 25 | * \deprecated 26 | */ 27 | 28 | /* DEPRECATED */ 29 | #include "SDL_stdinc.h" 30 | -------------------------------------------------------------------------------- /Chapter6/include/SDL/SDL_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_types.h 24 | * 25 | * \deprecated 26 | */ 27 | 28 | /* DEPRECATED */ 29 | #include "SDL_stdinc.h" 30 | -------------------------------------------------------------------------------- /Chapter7/include/SDL/SDL_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_types.h 24 | * 25 | * \deprecated 26 | */ 27 | 28 | /* DEPRECATED */ 29 | #include "SDL_stdinc.h" 30 | -------------------------------------------------------------------------------- /Chapter8/include/SDL/SDL_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_types.h 24 | * 25 | * \deprecated 26 | */ 27 | 28 | /* DEPRECATED */ 29 | #include "SDL_stdinc.h" 30 | -------------------------------------------------------------------------------- /Chapter9/include/SDL/SDL_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_types.h 24 | * 25 | * \deprecated 26 | */ 27 | 28 | /* DEPRECATED */ 29 | #include "SDL_stdinc.h" 30 | -------------------------------------------------------------------------------- /Chapter4/include/Game.h: -------------------------------------------------------------------------------- 1 | //! @file Game.h 2 | 3 | #ifndef __Dungeon_Game__ 4 | #define __Dungeon_Game__ 5 | 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | class Game 12 | { 13 | public: 14 | //! 构造函数 15 | Game(); 16 | 17 | //! 初始化 18 | bool Initialize(); 19 | //! 主循环 20 | void Loop(); 21 | //! 游戏结束 22 | void Shutdown(); 23 | 24 | //! 创建并存储游戏物体 25 | void CreateGameObject(class GameObject* gameObject); 26 | //! 移除游戏对象 27 | void RemoveGameObject(class GameObject* gameObject); 28 | 29 | private: 30 | //! 处理事件 31 | void Event(); 32 | //! 更新各种状态 33 | void Update(); 34 | //! 渲染 35 | void Draw(); 36 | 37 | //! 加载数据 38 | void LoadData(); 39 | //! 释放数据 40 | void UnloadData(); 41 | //! 加载贴图 42 | void LoadTexture(const std::string fileName); 43 | 44 | std::vector mGameObjects; //!< 游戏物体容器 45 | std::vector mPendingObjects; //!< 等待状态的游戏物体容器 46 | 47 | class SDL_Window* mWindow; //!< 窗口 48 | class SDL_Renderer* mRenderer; //!< 渲染器 49 | bool mIsRunning; //!< 运行状态 50 | bool mIsUpdating; //!< 是否在更新状态 51 | 52 | class SDL_Texture* mTexture; //!< 图片 53 | }; 54 | } 55 | 56 | #endif // __Dungeon_Game__ -------------------------------------------------------------------------------- /Chapter1/Dungeon.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 26 | 27 | 头文件 28 | 29 | 30 | -------------------------------------------------------------------------------- /Chapter2/Dungeon.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 26 | 27 | 头文件 28 | 29 | 30 | -------------------------------------------------------------------------------- /Chapter3/Dungeon.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 26 | 27 | 头文件 28 | 29 | 30 | -------------------------------------------------------------------------------- /Chapter5/include/Game.h: -------------------------------------------------------------------------------- 1 | //! @file Game.h 2 | 3 | #ifndef __Dungeon_Game__ 4 | #define __Dungeon_Game__ 5 | 6 | #include 7 | #include 8 | 9 | namespace Dungeon 10 | { 11 | class Game 12 | { 13 | public: 14 | //! 构造函数 15 | Game(); 16 | 17 | //! 初始化 18 | bool Initialize(); 19 | //! 主循环 20 | void Loop(); 21 | //! 游戏结束 22 | void Shutdown(); 23 | 24 | //! 创建并存储游戏物体 25 | void CreateGameObject(class GameObject* gameObject); 26 | //! 移除游戏对象 27 | void RemoveGameObject(class GameObject* gameObject); 28 | 29 | private: 30 | //! 处理事件 31 | void Event(); 32 | //! 更新各种状态 33 | void Update(); 34 | //! 渲染 35 | void Draw(); 36 | 37 | //! 加载数据 38 | void LoadData(); 39 | //! 释放数据 40 | void UnloadData(); 41 | //! 加载贴图 42 | void LoadTexture(const std::string fileName); 43 | 44 | std::vector mGameObjects; //!< 游戏物体容器 45 | std::vector mPendingObjects; //!< 等待状态的游戏物体容器 46 | 47 | struct SDL_Window* mWindow; //!< 窗口 48 | struct SDL_Renderer* mRenderer; //!< 渲染器 49 | bool mIsRunning; //!< 运行状态 50 | bool mIsUpdating; //!< 是否在更新状态 51 | 52 | struct SDL_Texture* mTexture; //!< 图片 53 | }; 54 | } 55 | 56 | #endif // __Dungeon_Game__ -------------------------------------------------------------------------------- /Chapter1/include/SDL/SDL_name.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef SDLname_h_ 23 | #define SDLname_h_ 24 | 25 | #if defined(__STDC__) || defined(__cplusplus) 26 | #define NeedFunctionPrototypes 1 27 | #endif 28 | 29 | #define SDL_NAME(X) SDL_##X 30 | 31 | #endif /* SDLname_h_ */ 32 | 33 | /* vi: set ts=4 sw=4 expandtab: */ 34 | -------------------------------------------------------------------------------- /Chapter10/include/SDL/SDL_name.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef SDLname_h_ 23 | #define SDLname_h_ 24 | 25 | #if defined(__STDC__) || defined(__cplusplus) 26 | #define NeedFunctionPrototypes 1 27 | #endif 28 | 29 | #define SDL_NAME(X) SDL_##X 30 | 31 | #endif /* SDLname_h_ */ 32 | 33 | /* vi: set ts=4 sw=4 expandtab: */ 34 | -------------------------------------------------------------------------------- /Chapter2/include/SDL/SDL_name.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef SDLname_h_ 23 | #define SDLname_h_ 24 | 25 | #if defined(__STDC__) || defined(__cplusplus) 26 | #define NeedFunctionPrototypes 1 27 | #endif 28 | 29 | #define SDL_NAME(X) SDL_##X 30 | 31 | #endif /* SDLname_h_ */ 32 | 33 | /* vi: set ts=4 sw=4 expandtab: */ 34 | -------------------------------------------------------------------------------- /Chapter3/include/SDL/SDL_name.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef SDLname_h_ 23 | #define SDLname_h_ 24 | 25 | #if defined(__STDC__) || defined(__cplusplus) 26 | #define NeedFunctionPrototypes 1 27 | #endif 28 | 29 | #define SDL_NAME(X) SDL_##X 30 | 31 | #endif /* SDLname_h_ */ 32 | 33 | /* vi: set ts=4 sw=4 expandtab: */ 34 | -------------------------------------------------------------------------------- /Chapter4/include/SDL/SDL_name.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef SDLname_h_ 23 | #define SDLname_h_ 24 | 25 | #if defined(__STDC__) || defined(__cplusplus) 26 | #define NeedFunctionPrototypes 1 27 | #endif 28 | 29 | #define SDL_NAME(X) SDL_##X 30 | 31 | #endif /* SDLname_h_ */ 32 | 33 | /* vi: set ts=4 sw=4 expandtab: */ 34 | -------------------------------------------------------------------------------- /Chapter5/include/SDL/SDL_name.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef SDLname_h_ 23 | #define SDLname_h_ 24 | 25 | #if defined(__STDC__) || defined(__cplusplus) 26 | #define NeedFunctionPrototypes 1 27 | #endif 28 | 29 | #define SDL_NAME(X) SDL_##X 30 | 31 | #endif /* SDLname_h_ */ 32 | 33 | /* vi: set ts=4 sw=4 expandtab: */ 34 | -------------------------------------------------------------------------------- /Chapter6/include/SDL/SDL_name.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef SDLname_h_ 23 | #define SDLname_h_ 24 | 25 | #if defined(__STDC__) || defined(__cplusplus) 26 | #define NeedFunctionPrototypes 1 27 | #endif 28 | 29 | #define SDL_NAME(X) SDL_##X 30 | 31 | #endif /* SDLname_h_ */ 32 | 33 | /* vi: set ts=4 sw=4 expandtab: */ 34 | -------------------------------------------------------------------------------- /Chapter7/include/SDL/SDL_name.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef SDLname_h_ 23 | #define SDLname_h_ 24 | 25 | #if defined(__STDC__) || defined(__cplusplus) 26 | #define NeedFunctionPrototypes 1 27 | #endif 28 | 29 | #define SDL_NAME(X) SDL_##X 30 | 31 | #endif /* SDLname_h_ */ 32 | 33 | /* vi: set ts=4 sw=4 expandtab: */ 34 | -------------------------------------------------------------------------------- /Chapter8/include/SDL/SDL_name.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef SDLname_h_ 23 | #define SDLname_h_ 24 | 25 | #if defined(__STDC__) || defined(__cplusplus) 26 | #define NeedFunctionPrototypes 1 27 | #endif 28 | 29 | #define SDL_NAME(X) SDL_##X 30 | 31 | #endif /* SDLname_h_ */ 32 | 33 | /* vi: set ts=4 sw=4 expandtab: */ 34 | -------------------------------------------------------------------------------- /Chapter9/include/SDL/SDL_name.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef SDLname_h_ 23 | #define SDLname_h_ 24 | 25 | #if defined(__STDC__) || defined(__cplusplus) 26 | #define NeedFunctionPrototypes 1 27 | #endif 28 | 29 | #define SDL_NAME(X) SDL_##X 30 | 31 | #endif /* SDLname_h_ */ 32 | 33 | /* vi: set ts=4 sw=4 expandtab: */ 34 | -------------------------------------------------------------------------------- /Chapter9/src/MapComponent.cpp: -------------------------------------------------------------------------------- 1 | //! @file MapComponent.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Dungeon 8 | { 9 | MapComponent::MapComponent(GameObject* gameObject): 10 | SpriteComponent(gameObject, 0) 11 | { 12 | // 宽20高15的地图 13 | mMapArray = new int[20 * 15]; 14 | // 随便进行一下初始化 15 | for (int i = 0; i < 15; i++) 16 | { 17 | for (int j = 0; j < 20; j++) 18 | { 19 | if (i < 2 || j < 2 || i>12 || j>17) 20 | { 21 | mMapArray[i * 20 + j] = 1; 22 | } 23 | else 24 | { 25 | mMapArray[i * 20 + j] = 0; 26 | } 27 | } 28 | } 29 | } 30 | 31 | MapComponent::~MapComponent() 32 | { 33 | delete mMapArray; 34 | } 35 | 36 | void MapComponent::Draw(SDL_Renderer* renderer) 37 | { 38 | SDL_Rect dstRect{ 0, 0, 32, 32 }; 39 | for (int i = 0; i < 15; i++) 40 | { 41 | for (int j = 0; j < 20; j++) 42 | { 43 | // 实际在窗口中的位置 44 | dstRect.x = j * 32; 45 | dstRect.y = i * 32; 46 | // 该地图块的值 47 | int massNumber = mMapArray[i * 20 + j]; 48 | // 通过地图块的值去索引贴图并绘制 49 | SDL_RenderCopy(renderer, mTextures[massNumber], nullptr, &dstRect); 50 | } 51 | } 52 | } 53 | 54 | void MapComponent::SetTexture(SDL_Texture* texture, int number) 55 | { 56 | mTextures.emplace(number, texture); 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /Chapter1/src/Game.cpp: -------------------------------------------------------------------------------- 1 | //! @file Game.cpp 2 | 3 | #include 4 | #include 5 | 6 | namespace Dungeon 7 | { 8 | Game::Game(): 9 | mWindow(nullptr), 10 | mIsRunning(true) 11 | { 12 | 13 | } 14 | 15 | bool Game::Initialize() 16 | { 17 | // SDL库初始化 18 | if (SDL_Init(SDL_INIT_VIDEO) != 0) 19 | { 20 | SDL_Log("SDL库初始化失败: %s", SDL_GetError()); 21 | return false; 22 | } 23 | 24 | // 窗口初始化 25 | mWindow = SDL_CreateWindow("Dungeon", 400, 200, 600, 480, 0); 26 | if (!mWindow) 27 | { 28 | SDL_Log("窗口初始化失败: %s", SDL_GetError()); 29 | return false; 30 | } 31 | 32 | return true; 33 | } 34 | 35 | void Game::Loop() 36 | { 37 | while (mIsRunning) 38 | { 39 | Event(); 40 | Update(); 41 | Draw(); 42 | } 43 | } 44 | 45 | void Game::Shutdown() 46 | { 47 | SDL_DestroyWindow(mWindow); 48 | SDL_Quit(); 49 | } 50 | 51 | void Game::Event() 52 | { 53 | SDL_Event event; 54 | // 如果事件队列中有未处理的事件,按顺序处理 55 | while (SDL_PollEvent(&event)) 56 | { 57 | switch (event.type) 58 | { 59 | // 退出事件,按下窗口的叉 60 | case SDL_QUIT: 61 | mIsRunning = false; 62 | break; 63 | default: 64 | break; 65 | } 66 | } 67 | } 68 | 69 | void Game::Update() 70 | { 71 | } 72 | 73 | void Game::Draw() 74 | { 75 | } 76 | } -------------------------------------------------------------------------------- /Chapter10/src/Math.cpp: -------------------------------------------------------------------------------- 1 | //! @file Math.cpp 2 | 3 | #include 4 | 5 | namespace Dungeon 6 | { 7 | Vector2::Vector2() : 8 | x(0.0f), 9 | y(0.0f) 10 | { 11 | 12 | } 13 | 14 | Vector2::Vector2(float X, float Y) : 15 | x(X), 16 | y(Y) 17 | { 18 | 19 | } 20 | 21 | const Vector2 Vector2::Zero = Vector2(0.0f, 0.0f); 22 | const Vector2 Vector2::One = Vector2(1.0f, 1.0f); 23 | const Vector2 Vector2::X = Vector2(1.0f, 0.0f); 24 | const Vector2 Vector2::Y = Vector2(0.0f, 1.0f); 25 | const Vector2 Vector2::NX = Vector2(-1.0f, 0.0f); 26 | const Vector2 Vector2::NY = Vector2(0.0f, -1.0f); 27 | 28 | 29 | Vector2 operator+(const Vector2& a, const Vector2& b) 30 | { 31 | return Vector2(a.x + b.x, a.y + b.y); 32 | } 33 | 34 | Vector2 operator-(const Vector2& a, const Vector2& b) 35 | { 36 | return Vector2(a.x - b.x, a.y - b.y); 37 | } 38 | 39 | Vector2 operator*(const Vector2& a, const Vector2& b) 40 | { 41 | return Vector2(a.x * b.x, a.y * b.y); 42 | } 43 | 44 | Vector2 operator*(const Vector2& vec, float scalar) 45 | { 46 | return Vector2(vec.x * scalar, vec.y * scalar); 47 | } 48 | 49 | Vector2 operator*(float scalar, const Vector2& vec) 50 | { 51 | return Vector2(vec.x * scalar, vec.y * scalar); 52 | } 53 | 54 | bool operator==(const Vector2& a, const Vector2& b) 55 | { 56 | return (a.x == b.x && a.y == b.y); 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /Chapter6/src/Math.cpp: -------------------------------------------------------------------------------- 1 | //! @file Math.cpp 2 | 3 | #include 4 | 5 | namespace Dungeon 6 | { 7 | Vector2::Vector2() : 8 | x(0.0f), 9 | y(0.0f) 10 | { 11 | 12 | } 13 | 14 | Vector2::Vector2(float X, float Y) : 15 | x(X), 16 | y(Y) 17 | { 18 | 19 | } 20 | 21 | const Vector2 Vector2::Zero = Vector2(0.0f, 0.0f); 22 | const Vector2 Vector2::One = Vector2(1.0f, 1.0f); 23 | const Vector2 Vector2::X = Vector2(1.0f, 0.0f); 24 | const Vector2 Vector2::Y = Vector2(0.0f, 1.0f); 25 | const Vector2 Vector2::NX = Vector2(-1.0f, 0.0f); 26 | const Vector2 Vector2::NY = Vector2(0.0f, -1.0f); 27 | 28 | 29 | Vector2 operator+(const Vector2& a, const Vector2& b) 30 | { 31 | return Vector2(a.x + b.x, a.y + b.y); 32 | } 33 | 34 | Vector2 operator-(const Vector2& a, const Vector2& b) 35 | { 36 | return Vector2(a.x - b.x, a.y - b.y); 37 | } 38 | 39 | Vector2 operator*(const Vector2& a, const Vector2& b) 40 | { 41 | return Vector2(a.x * b.x, a.y * b.y); 42 | } 43 | 44 | Vector2 operator*(const Vector2& vec, float scalar) 45 | { 46 | return Vector2(vec.x * scalar, vec.y * scalar); 47 | } 48 | 49 | Vector2 operator*(float scalar, const Vector2& vec) 50 | { 51 | return Vector2(vec.x * scalar, vec.y * scalar); 52 | } 53 | 54 | bool operator==(const Vector2& a, const Vector2& b) 55 | { 56 | return (a.x == b.x && a.y == b.y); 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /Chapter7/src/Math.cpp: -------------------------------------------------------------------------------- 1 | //! @file Math.cpp 2 | 3 | #include 4 | 5 | namespace Dungeon 6 | { 7 | Vector2::Vector2() : 8 | x(0.0f), 9 | y(0.0f) 10 | { 11 | 12 | } 13 | 14 | Vector2::Vector2(float X, float Y) : 15 | x(X), 16 | y(Y) 17 | { 18 | 19 | } 20 | 21 | const Vector2 Vector2::Zero = Vector2(0.0f, 0.0f); 22 | const Vector2 Vector2::One = Vector2(1.0f, 1.0f); 23 | const Vector2 Vector2::X = Vector2(1.0f, 0.0f); 24 | const Vector2 Vector2::Y = Vector2(0.0f, 1.0f); 25 | const Vector2 Vector2::NX = Vector2(-1.0f, 0.0f); 26 | const Vector2 Vector2::NY = Vector2(0.0f, -1.0f); 27 | 28 | 29 | Vector2 operator+(const Vector2& a, const Vector2& b) 30 | { 31 | return Vector2(a.x + b.x, a.y + b.y); 32 | } 33 | 34 | Vector2 operator-(const Vector2& a, const Vector2& b) 35 | { 36 | return Vector2(a.x - b.x, a.y - b.y); 37 | } 38 | 39 | Vector2 operator*(const Vector2& a, const Vector2& b) 40 | { 41 | return Vector2(a.x * b.x, a.y * b.y); 42 | } 43 | 44 | Vector2 operator*(const Vector2& vec, float scalar) 45 | { 46 | return Vector2(vec.x * scalar, vec.y * scalar); 47 | } 48 | 49 | Vector2 operator*(float scalar, const Vector2& vec) 50 | { 51 | return Vector2(vec.x * scalar, vec.y * scalar); 52 | } 53 | 54 | bool operator==(const Vector2& a, const Vector2& b) 55 | { 56 | return (a.x == b.x && a.y == b.y); 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /Chapter8/src/Math.cpp: -------------------------------------------------------------------------------- 1 | //! @file Math.cpp 2 | 3 | #include 4 | 5 | namespace Dungeon 6 | { 7 | Vector2::Vector2() : 8 | x(0.0f), 9 | y(0.0f) 10 | { 11 | 12 | } 13 | 14 | Vector2::Vector2(float X, float Y) : 15 | x(X), 16 | y(Y) 17 | { 18 | 19 | } 20 | 21 | const Vector2 Vector2::Zero = Vector2(0.0f, 0.0f); 22 | const Vector2 Vector2::One = Vector2(1.0f, 1.0f); 23 | const Vector2 Vector2::X = Vector2(1.0f, 0.0f); 24 | const Vector2 Vector2::Y = Vector2(0.0f, 1.0f); 25 | const Vector2 Vector2::NX = Vector2(-1.0f, 0.0f); 26 | const Vector2 Vector2::NY = Vector2(0.0f, -1.0f); 27 | 28 | 29 | Vector2 operator+(const Vector2& a, const Vector2& b) 30 | { 31 | return Vector2(a.x + b.x, a.y + b.y); 32 | } 33 | 34 | Vector2 operator-(const Vector2& a, const Vector2& b) 35 | { 36 | return Vector2(a.x - b.x, a.y - b.y); 37 | } 38 | 39 | Vector2 operator*(const Vector2& a, const Vector2& b) 40 | { 41 | return Vector2(a.x * b.x, a.y * b.y); 42 | } 43 | 44 | Vector2 operator*(const Vector2& vec, float scalar) 45 | { 46 | return Vector2(vec.x * scalar, vec.y * scalar); 47 | } 48 | 49 | Vector2 operator*(float scalar, const Vector2& vec) 50 | { 51 | return Vector2(vec.x * scalar, vec.y * scalar); 52 | } 53 | 54 | bool operator==(const Vector2& a, const Vector2& b) 55 | { 56 | return (a.x == b.x && a.y == b.y); 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /Chapter9/src/Math.cpp: -------------------------------------------------------------------------------- 1 | //! @file Math.cpp 2 | 3 | #include 4 | 5 | namespace Dungeon 6 | { 7 | Vector2::Vector2() : 8 | x(0.0f), 9 | y(0.0f) 10 | { 11 | 12 | } 13 | 14 | Vector2::Vector2(float X, float Y) : 15 | x(X), 16 | y(Y) 17 | { 18 | 19 | } 20 | 21 | const Vector2 Vector2::Zero = Vector2(0.0f, 0.0f); 22 | const Vector2 Vector2::One = Vector2(1.0f, 1.0f); 23 | const Vector2 Vector2::X = Vector2(1.0f, 0.0f); 24 | const Vector2 Vector2::Y = Vector2(0.0f, 1.0f); 25 | const Vector2 Vector2::NX = Vector2(-1.0f, 0.0f); 26 | const Vector2 Vector2::NY = Vector2(0.0f, -1.0f); 27 | 28 | 29 | Vector2 operator+(const Vector2& a, const Vector2& b) 30 | { 31 | return Vector2(a.x + b.x, a.y + b.y); 32 | } 33 | 34 | Vector2 operator-(const Vector2& a, const Vector2& b) 35 | { 36 | return Vector2(a.x - b.x, a.y - b.y); 37 | } 38 | 39 | Vector2 operator*(const Vector2& a, const Vector2& b) 40 | { 41 | return Vector2(a.x * b.x, a.y * b.y); 42 | } 43 | 44 | Vector2 operator*(const Vector2& vec, float scalar) 45 | { 46 | return Vector2(vec.x * scalar, vec.y * scalar); 47 | } 48 | 49 | Vector2 operator*(float scalar, const Vector2& vec) 50 | { 51 | return Vector2(vec.x * scalar, vec.y * scalar); 52 | } 53 | 54 | bool operator==(const Vector2& a, const Vector2& b) 55 | { 56 | return (a.x == b.x && a.y == b.y); 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /Chapter10/src/MapComponent.cpp: -------------------------------------------------------------------------------- 1 | //! @file MapComponent.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Dungeon 8 | { 9 | MapComponent::MapComponent(GameObject* gameObject): 10 | SpriteComponent(gameObject, 0) 11 | { 12 | // 宽20高15的地图 13 | mMapArray = new int[20 * 15]; 14 | // 随便进行一下初始化 15 | for (int i = 0; i < 15; i++) 16 | { 17 | for (int j = 0; j < 20; j++) 18 | { 19 | if (i < 2 || j < 2 || i>12 || j>17) 20 | { 21 | mMapArray[i * 20 + j] = 1; 22 | } 23 | else 24 | { 25 | mMapArray[i * 20 + j] = 0; 26 | } 27 | } 28 | } 29 | } 30 | 31 | MapComponent::~MapComponent() 32 | { 33 | delete mMapArray; 34 | } 35 | 36 | void MapComponent::Draw(SDL_Renderer* renderer) 37 | { 38 | SDL_Rect dstRect{ 0, 0, 32, 32 }; 39 | for (int i = 0; i < 15; i++) 40 | { 41 | for (int j = 0; j < 20; j++) 42 | { 43 | // 实际在窗口中的位置 44 | dstRect.x = j * 32; 45 | dstRect.y = i * 32; 46 | // 该地图块的值 47 | int massNumber = mMapArray[i * 20 + j]; 48 | // 通过地图块的值去索引贴图并绘制 49 | SDL_RenderCopy(renderer, mTextures[massNumber], nullptr, &dstRect); 50 | } 51 | } 52 | } 53 | 54 | void MapComponent::SetTexture(SDL_Texture* texture, int number) 55 | { 56 | mTextures.emplace(number, texture); 57 | } 58 | 59 | int* MapComponent::GetMap() 60 | { 61 | return mMapArray; 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /Chapter5/src/Math.cpp: -------------------------------------------------------------------------------- 1 | //! @file Math.cpp 2 | 3 | #include 4 | 5 | namespace Dungeon 6 | { 7 | Vector2::Vector2() : 8 | x(0.0f), 9 | y(0.0f) 10 | { 11 | 12 | } 13 | 14 | Vector2::Vector2(float X, float Y) : 15 | x(X), 16 | y(Y) 17 | { 18 | 19 | } 20 | 21 | const Vector2 Vector2::Zero = Vector2(0.0f, 0.0f); 22 | const Vector2 Vector2::One = Vector2(1.0f, 1.0f); 23 | const Vector2 Vector2::X = Vector2(1.0f, 0.0f); 24 | const Vector2 Vector2::Y = Vector2(0.0f, 1.0f); 25 | const Vector2 Vector2::NX = Vector2(-1.0f, 0.0f); 26 | const Vector2 Vector2::NY = Vector2(0.0f, -1.0f); 27 | 28 | 29 | Vector2 operator+(const Vector2& a, const Vector2& b) 30 | { 31 | return Vector2(a.x + b.x, a.y + b.y); 32 | } 33 | 34 | Vector2 operator-(const Vector2& a, const Vector2& b) 35 | { 36 | return Vector2(a.x - b.x, a.y - b.y); 37 | } 38 | 39 | Vector2 operator*(const Vector2& a, const Vector2& b) 40 | { 41 | return Vector2(a.x * b.x, a.y * b.y); 42 | } 43 | 44 | Vector2 operator*(const Vector2& vec, float scalar) 45 | { 46 | return Vector2(vec.x * scalar, vec.y * scalar); 47 | } 48 | 49 | Vector2 operator*(float scalar, const Vector2& vec) 50 | { 51 | return Vector2(vec.x * scalar, vec.y * scalar); 52 | } 53 | 54 | bool operator==(const Vector2& a, const Vector2& b) 55 | { 56 | return (a.x == b.x && a.y == b.y); 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /Chapter4/src/GameObject.cpp: -------------------------------------------------------------------------------- 1 | //! @file GameObject.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Dungeon 8 | { 9 | GameObject::GameObject(Game* game) : 10 | mGame(game), 11 | mState(State::EActive) 12 | { 13 | mGame->CreateGameObject(this); 14 | } 15 | 16 | GameObject::~GameObject() 17 | { 18 | mGame->RemoveGameObject(this); 19 | while (!mComponents.empty()) 20 | { 21 | delete mComponents.back(); 22 | } 23 | } 24 | 25 | void GameObject::Update() 26 | { 27 | if (mState == State::EActive) 28 | { 29 | // 每帧执行,更新所有的组件 30 | for (auto component : mComponents) 31 | { 32 | component->Update(); 33 | } 34 | } 35 | } 36 | 37 | void GameObject::AddComponent(Component* component) 38 | { 39 | // 获取该组件的更新顺序 40 | int order = component->GetUpdateOrder(); 41 | auto iter = mComponents.begin(); 42 | // 新组件需要按顺序插入到对应位置 43 | for (; iter != mComponents.end(); ++iter) 44 | { 45 | if (order < (*iter)->GetUpdateOrder()) 46 | { 47 | break; 48 | } 49 | } 50 | mComponents.insert(iter, component); 51 | } 52 | 53 | void GameObject::RemoveComponent(Component* component) 54 | { 55 | auto iter = std::find(mComponents.begin(), mComponents.end(), component); 56 | if (iter != mComponents.end()) 57 | { 58 | mComponents.erase(iter); 59 | } 60 | } 61 | 62 | GameObject::State GameObject::GetState() const 63 | { 64 | return mState; 65 | } 66 | 67 | void GameObject::SetState(State state) 68 | { 69 | mState = state; 70 | } 71 | } -------------------------------------------------------------------------------- /Chapter1/include/SDL/close_code.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file close_code.h 24 | * 25 | * This file reverses the effects of begin_code.h and should be included 26 | * after you finish any function and structure declarations in your headers 27 | */ 28 | 29 | #ifndef _begin_code_h 30 | #error close_code.h included without matching begin_code.h 31 | #endif 32 | #undef _begin_code_h 33 | 34 | /* Reset structure packing at previous byte alignment */ 35 | #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) 36 | #ifdef __BORLANDC__ 37 | #pragma nopackwarning 38 | #endif 39 | #pragma pack(pop) 40 | #endif /* Compiler needs structure packing set */ 41 | -------------------------------------------------------------------------------- /Chapter10/include/SDL/close_code.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file close_code.h 24 | * 25 | * This file reverses the effects of begin_code.h and should be included 26 | * after you finish any function and structure declarations in your headers 27 | */ 28 | 29 | #ifndef _begin_code_h 30 | #error close_code.h included without matching begin_code.h 31 | #endif 32 | #undef _begin_code_h 33 | 34 | /* Reset structure packing at previous byte alignment */ 35 | #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) 36 | #ifdef __BORLANDC__ 37 | #pragma nopackwarning 38 | #endif 39 | #pragma pack(pop) 40 | #endif /* Compiler needs structure packing set */ 41 | -------------------------------------------------------------------------------- /Chapter2/include/SDL/close_code.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file close_code.h 24 | * 25 | * This file reverses the effects of begin_code.h and should be included 26 | * after you finish any function and structure declarations in your headers 27 | */ 28 | 29 | #ifndef _begin_code_h 30 | #error close_code.h included without matching begin_code.h 31 | #endif 32 | #undef _begin_code_h 33 | 34 | /* Reset structure packing at previous byte alignment */ 35 | #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) 36 | #ifdef __BORLANDC__ 37 | #pragma nopackwarning 38 | #endif 39 | #pragma pack(pop) 40 | #endif /* Compiler needs structure packing set */ 41 | -------------------------------------------------------------------------------- /Chapter3/include/SDL/close_code.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file close_code.h 24 | * 25 | * This file reverses the effects of begin_code.h and should be included 26 | * after you finish any function and structure declarations in your headers 27 | */ 28 | 29 | #ifndef _begin_code_h 30 | #error close_code.h included without matching begin_code.h 31 | #endif 32 | #undef _begin_code_h 33 | 34 | /* Reset structure packing at previous byte alignment */ 35 | #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) 36 | #ifdef __BORLANDC__ 37 | #pragma nopackwarning 38 | #endif 39 | #pragma pack(pop) 40 | #endif /* Compiler needs structure packing set */ 41 | -------------------------------------------------------------------------------- /Chapter4/include/SDL/close_code.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file close_code.h 24 | * 25 | * This file reverses the effects of begin_code.h and should be included 26 | * after you finish any function and structure declarations in your headers 27 | */ 28 | 29 | #ifndef _begin_code_h 30 | #error close_code.h included without matching begin_code.h 31 | #endif 32 | #undef _begin_code_h 33 | 34 | /* Reset structure packing at previous byte alignment */ 35 | #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) 36 | #ifdef __BORLANDC__ 37 | #pragma nopackwarning 38 | #endif 39 | #pragma pack(pop) 40 | #endif /* Compiler needs structure packing set */ 41 | -------------------------------------------------------------------------------- /Chapter5/include/SDL/close_code.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file close_code.h 24 | * 25 | * This file reverses the effects of begin_code.h and should be included 26 | * after you finish any function and structure declarations in your headers 27 | */ 28 | 29 | #ifndef _begin_code_h 30 | #error close_code.h included without matching begin_code.h 31 | #endif 32 | #undef _begin_code_h 33 | 34 | /* Reset structure packing at previous byte alignment */ 35 | #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) 36 | #ifdef __BORLANDC__ 37 | #pragma nopackwarning 38 | #endif 39 | #pragma pack(pop) 40 | #endif /* Compiler needs structure packing set */ 41 | -------------------------------------------------------------------------------- /Chapter6/include/SDL/close_code.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file close_code.h 24 | * 25 | * This file reverses the effects of begin_code.h and should be included 26 | * after you finish any function and structure declarations in your headers 27 | */ 28 | 29 | #ifndef _begin_code_h 30 | #error close_code.h included without matching begin_code.h 31 | #endif 32 | #undef _begin_code_h 33 | 34 | /* Reset structure packing at previous byte alignment */ 35 | #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) 36 | #ifdef __BORLANDC__ 37 | #pragma nopackwarning 38 | #endif 39 | #pragma pack(pop) 40 | #endif /* Compiler needs structure packing set */ 41 | -------------------------------------------------------------------------------- /Chapter7/include/SDL/close_code.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file close_code.h 24 | * 25 | * This file reverses the effects of begin_code.h and should be included 26 | * after you finish any function and structure declarations in your headers 27 | */ 28 | 29 | #ifndef _begin_code_h 30 | #error close_code.h included without matching begin_code.h 31 | #endif 32 | #undef _begin_code_h 33 | 34 | /* Reset structure packing at previous byte alignment */ 35 | #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) 36 | #ifdef __BORLANDC__ 37 | #pragma nopackwarning 38 | #endif 39 | #pragma pack(pop) 40 | #endif /* Compiler needs structure packing set */ 41 | -------------------------------------------------------------------------------- /Chapter8/include/SDL/close_code.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file close_code.h 24 | * 25 | * This file reverses the effects of begin_code.h and should be included 26 | * after you finish any function and structure declarations in your headers 27 | */ 28 | 29 | #ifndef _begin_code_h 30 | #error close_code.h included without matching begin_code.h 31 | #endif 32 | #undef _begin_code_h 33 | 34 | /* Reset structure packing at previous byte alignment */ 35 | #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) 36 | #ifdef __BORLANDC__ 37 | #pragma nopackwarning 38 | #endif 39 | #pragma pack(pop) 40 | #endif /* Compiler needs structure packing set */ 41 | -------------------------------------------------------------------------------- /Chapter9/include/SDL/close_code.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file close_code.h 24 | * 25 | * This file reverses the effects of begin_code.h and should be included 26 | * after you finish any function and structure declarations in your headers 27 | */ 28 | 29 | #ifndef _begin_code_h 30 | #error close_code.h included without matching begin_code.h 31 | #endif 32 | #undef _begin_code_h 33 | 34 | /* Reset structure packing at previous byte alignment */ 35 | #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) 36 | #ifdef __BORLANDC__ 37 | #pragma nopackwarning 38 | #endif 39 | #pragma pack(pop) 40 | #endif /* Compiler needs structure packing set */ 41 | -------------------------------------------------------------------------------- /Chapter4/Dungeon.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 源文件 29 | 30 | 31 | 32 | 33 | 头文件 34 | 35 | 36 | 头文件 37 | 38 | 39 | 头文件 40 | 41 | 42 | -------------------------------------------------------------------------------- /Chapter6/include/GameObject.h: -------------------------------------------------------------------------------- 1 | //! @file GameObject.h 2 | 3 | #ifndef __Dungeon_GameObject__ 4 | #define __Dungeon_GameObject__ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace Dungeon 11 | { 12 | class GameObject 13 | { 14 | public: 15 | //! 物体状态 16 | enum class State 17 | { 18 | EActive, 19 | EDead 20 | }; 21 | 22 | //! 构造函数 23 | GameObject(class Game* game); 24 | //! 析构函数 25 | virtual ~GameObject(); 26 | 27 | //! 每帧更新 28 | void Update(); 29 | //! 添加组件 30 | void AddComponent(class Component* component); 31 | //! 移除组件 32 | void RemoveComponent(class Component* component); 33 | 34 | //! 获取特定类型的组件,并得到该组件类型的指针 35 | template T* GetComponent() 36 | { 37 | for (auto com : mComponents) 38 | { 39 | T* component = dynamic_cast(com); 40 | if (component != nullptr) 41 | { 42 | return component; 43 | } 44 | } 45 | return nullptr; 46 | } 47 | 48 | //! game对象的get 49 | Game* GetGame() const; 50 | //! 物体状态的get和set 51 | State GetState() const; 52 | void SetState(State state); 53 | //! 位置的get和set 54 | Vector2 GetPosition() const; 55 | void SetPosition(const Vector2& p); 56 | //! 缩放大小的get和set 57 | Vector2 GetScale() const; 58 | void SetScale(Vector2 s); 59 | //! 旋转的get和set 60 | float GetRotation() const; 61 | void SetRotation(float r); 62 | 63 | protected: 64 | std::vector mComponents; //!< 组件数组 65 | 66 | private: 67 | Game* mGame; //!< Game对象 68 | State mState; //!< 物体当前状态 69 | Vector2 mPosition; //!< 位置坐标 70 | Vector2 mScale; //!< 缩放 71 | float mRotation; //!< 旋转 72 | }; 73 | } 74 | 75 | #endif // __Dungeon_GameObject__ -------------------------------------------------------------------------------- /Chapter7/include/GameObject.h: -------------------------------------------------------------------------------- 1 | //! @file GameObject.h 2 | 3 | #ifndef __Dungeon_GameObject__ 4 | #define __Dungeon_GameObject__ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace Dungeon 11 | { 12 | class GameObject 13 | { 14 | public: 15 | //! 物体状态 16 | enum class State 17 | { 18 | EActive, 19 | EDead 20 | }; 21 | 22 | //! 构造函数 23 | GameObject(class Game* game); 24 | //! 析构函数 25 | virtual ~GameObject(); 26 | 27 | //! 每帧更新 28 | void Update(); 29 | //! 添加组件 30 | void AddComponent(class Component* component); 31 | //! 移除组件 32 | void RemoveComponent(class Component* component); 33 | 34 | //! 获取特定类型的组件,并得到该组件类型的指针 35 | template T* GetComponent() 36 | { 37 | for (auto com : mComponents) 38 | { 39 | T* component = dynamic_cast(com); 40 | if (component != nullptr) 41 | { 42 | return component; 43 | } 44 | } 45 | return nullptr; 46 | } 47 | 48 | //! game对象的get 49 | Game* GetGame() const; 50 | //! 物体状态的get和set 51 | State GetState() const; 52 | void SetState(State state); 53 | //! 位置的get和set 54 | Vector2 GetPosition() const; 55 | void SetPosition(const Vector2& p); 56 | //! 缩放大小的get和set 57 | Vector2 GetScale() const; 58 | void SetScale(Vector2 s); 59 | //! 旋转的get和set 60 | float GetRotation() const; 61 | void SetRotation(float r); 62 | 63 | protected: 64 | std::vector mComponents; //!< 组件数组 65 | 66 | private: 67 | Game* mGame; //!< Game对象 68 | State mState; //!< 物体当前状态 69 | Vector2 mPosition; //!< 位置坐标 70 | Vector2 mScale; //!< 缩放 71 | float mRotation; //!< 旋转 72 | }; 73 | } 74 | 75 | #endif // __Dungeon_GameObject__ -------------------------------------------------------------------------------- /Chapter6/include/Game.h: -------------------------------------------------------------------------------- 1 | //! @file Game.h 2 | 3 | #ifndef __Dungeon_Game__ 4 | #define __Dungeon_Game__ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | struct SDL_Window; 11 | struct SDL_Renderer; 12 | struct SDL_Texture; 13 | 14 | namespace Dungeon 15 | { 16 | class GameObject; 17 | class SpriteComponent; 18 | class Player; 19 | 20 | class Game 21 | { 22 | public: 23 | //! 构造函数 24 | Game(); 25 | 26 | //! 初始化 27 | bool Initialize(); 28 | //! 主循环 29 | void Loop(); 30 | //! 游戏结束 31 | void Shutdown(); 32 | 33 | //! 创建并存储游戏物体 34 | void CreateGameObject(GameObject* gameObject); 35 | //! 移除游戏对象 36 | void RemoveGameObject(GameObject* gameObject); 37 | //! 创建并按绘制顺序存储精灵 38 | void CreateSprite(SpriteComponent* sprite); 39 | //! 移除精灵 40 | void RemoveSprite(SpriteComponent* sprite); 41 | //! 获取贴图 42 | SDL_Texture* GetTexture(const std::string& fileName); 43 | 44 | private: 45 | //! 处理事件 46 | void Event(); 47 | //! 更新各种状态 48 | void Update(); 49 | //! 渲染 50 | void Draw(); 51 | 52 | //! 加载数据 53 | void LoadData(); 54 | //! 释放数据 55 | void UnloadData(); 56 | //! 加载贴图并重命名 57 | void LoadTexture(const std::string& fileName, const std::string& newName); 58 | 59 | std::vector mGameObjects; //!< 游戏物体容器 60 | std::vector mPendingObjects; //!< 等待状态的游戏物体容器 61 | std::vector mSprites; //!< 存放精灵的容器 62 | 63 | std::unordered_map mTextures; //!< 存放贴图的容器 64 | 65 | SDL_Window* mWindow; //!< 窗口 66 | SDL_Renderer* mRenderer; //!< 渲染器 67 | bool mIsRunning; //!< 运行状态 68 | bool mIsUpdating; //!< 是否在更新状态 69 | 70 | Player* mPlayer; //!< 玩家角色 71 | }; 72 | } 73 | 74 | #endif // __Dungeon_Game__ -------------------------------------------------------------------------------- /Chapter5/include/GameObject.h: -------------------------------------------------------------------------------- 1 | //! @file GameObject.h 2 | 3 | #ifndef __Dungeon_GameObject__ 4 | #define __Dungeon_GameObject__ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace Dungeon 11 | { 12 | class GameObject 13 | { 14 | public: 15 | //! 物体状态 16 | enum class State 17 | { 18 | EActive, 19 | EDead 20 | }; 21 | 22 | //! 构造函数 23 | GameObject(class Game* game); 24 | //! 析构函数 25 | virtual ~GameObject(); 26 | 27 | //! 每帧更新 28 | void Update(); 29 | //! 添加组件 30 | void AddComponent(class Component* component); 31 | //! 移除组件 32 | void RemoveComponent(class Component* component); 33 | 34 | //! 获取特定类型的组件,并得到该组件类型的指针 35 | template T* GetComponent() 36 | { 37 | for (auto com : mComponents) 38 | { 39 | T* component = dynamic_cast(com); 40 | if (component != nullptr) 41 | { 42 | return component; 43 | } 44 | } 45 | return nullptr; 46 | } 47 | 48 | //! 物体状态的get和set 49 | State GetState() const; 50 | void SetState(State state); 51 | //! 位置的get和set 52 | Vector2 GetPosition() const; 53 | void SetPosition(const Vector2& p); 54 | //! 缩放大小的get和set 55 | Vector2 GetScale() const; 56 | void SetScale(Vector2 s); 57 | //! 旋转的get和set 58 | float GetRotation() const; 59 | void SetRotation(float r); 60 | 61 | protected: 62 | std::vector mComponents; //!< 组件数组 63 | 64 | private: 65 | class Game* mGame; //!< Game对象 66 | State mState; //!< 物体当前状态 67 | Vector2 mPosition; //!< 位置坐标 68 | Vector2 mScale; //!< 缩放 69 | float mRotation; //!< 旋转 70 | }; 71 | } 72 | 73 | #endif // __Dungeon_GameObject__ -------------------------------------------------------------------------------- /Chapter6/src/SpriteComponent.cpp: -------------------------------------------------------------------------------- 1 | //! @file SpriteComponent.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | SpriteComponent::SpriteComponent(GameObject* gameObject, int drawOrder) : 11 | Component(gameObject), 12 | mTexture(nullptr), 13 | mTexWidth(0), 14 | mTexHeight(0), 15 | mDrawOrder(drawOrder) 16 | { 17 | mGameObject->GetGame()->CreateSprite(this); 18 | } 19 | 20 | SpriteComponent::~SpriteComponent() 21 | { 22 | mGameObject->GetGame()->RemoveSprite(this); 23 | } 24 | 25 | void SpriteComponent::Draw(SDL_Renderer* renderer) 26 | { 27 | if (!mTexture) 28 | { 29 | return; 30 | } 31 | 32 | // 贴图即将被绘制的位置 33 | SDL_Rect dstrect; 34 | dstrect.w = static_cast(mTexWidth * mGameObject->GetScale().x); 35 | dstrect.h = static_cast(mTexHeight * mGameObject->GetScale().y); 36 | dstrect.x = static_cast(mGameObject->GetPosition().x); 37 | dstrect.y = static_cast(mGameObject->GetPosition().y); 38 | // 绘制贴图(考虑旋转) 39 | SDL_RenderCopyEx(renderer, mTexture, nullptr, &dstrect, mGameObject->GetRotation(), nullptr, SDL_FLIP_NONE); 40 | } 41 | 42 | void SpriteComponent::SetTexture(SDL_Texture* texture) 43 | { 44 | mTexture = texture; 45 | // 从贴图中查询贴图的宽和高 46 | SDL_QueryTexture(texture, nullptr, nullptr, &mTexWidth, &mTexHeight); 47 | } 48 | 49 | int SpriteComponent::GetTexWidth() const 50 | { 51 | return mTexWidth; 52 | } 53 | 54 | int SpriteComponent::GetTexHeight() const 55 | { 56 | return mTexHeight; 57 | } 58 | 59 | int SpriteComponent::GetDrawOrder() const 60 | { 61 | return mDrawOrder; 62 | } 63 | 64 | void SpriteComponent::SetDrawOrder(int order) 65 | { 66 | mDrawOrder = order; 67 | } 68 | 69 | 70 | } -------------------------------------------------------------------------------- /Chapter7/src/SpriteComponent.cpp: -------------------------------------------------------------------------------- 1 | //! @file SpriteComponent.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | SpriteComponent::SpriteComponent(GameObject* gameObject, int drawOrder) : 11 | Component(gameObject), 12 | mTexture(nullptr), 13 | mTexWidth(0), 14 | mTexHeight(0), 15 | mDrawOrder(drawOrder) 16 | { 17 | mGameObject->GetGame()->CreateSprite(this); 18 | } 19 | 20 | SpriteComponent::~SpriteComponent() 21 | { 22 | mGameObject->GetGame()->RemoveSprite(this); 23 | } 24 | 25 | void SpriteComponent::Draw(SDL_Renderer* renderer) 26 | { 27 | if (!mTexture) 28 | { 29 | return; 30 | } 31 | 32 | // 贴图即将被绘制的位置 33 | SDL_Rect dstrect; 34 | dstrect.w = static_cast(mTexWidth * mGameObject->GetScale().x); 35 | dstrect.h = static_cast(mTexHeight * mGameObject->GetScale().y); 36 | dstrect.x = static_cast(mGameObject->GetPosition().x); 37 | dstrect.y = static_cast(mGameObject->GetPosition().y); 38 | // 绘制贴图(考虑旋转) 39 | SDL_RenderCopyEx(renderer, mTexture, nullptr, &dstrect, mGameObject->GetRotation(), nullptr, SDL_FLIP_NONE); 40 | } 41 | 42 | void SpriteComponent::SetTexture(SDL_Texture* texture) 43 | { 44 | mTexture = texture; 45 | // 从贴图中查询贴图的宽和高 46 | SDL_QueryTexture(texture, nullptr, nullptr, &mTexWidth, &mTexHeight); 47 | } 48 | 49 | int SpriteComponent::GetTexWidth() const 50 | { 51 | return mTexWidth; 52 | } 53 | 54 | int SpriteComponent::GetTexHeight() const 55 | { 56 | return mTexHeight; 57 | } 58 | 59 | int SpriteComponent::GetDrawOrder() const 60 | { 61 | return mDrawOrder; 62 | } 63 | 64 | void SpriteComponent::SetDrawOrder(int order) 65 | { 66 | mDrawOrder = order; 67 | } 68 | 69 | 70 | } -------------------------------------------------------------------------------- /Chapter8/src/SpriteComponent.cpp: -------------------------------------------------------------------------------- 1 | //! @file SpriteComponent.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | SpriteComponent::SpriteComponent(GameObject* gameObject, int drawOrder) : 11 | Component(gameObject), 12 | mTexture(nullptr), 13 | mTexWidth(0), 14 | mTexHeight(0), 15 | mDrawOrder(drawOrder) 16 | { 17 | mGameObject->GetGame()->CreateSprite(this); 18 | } 19 | 20 | SpriteComponent::~SpriteComponent() 21 | { 22 | mGameObject->GetGame()->RemoveSprite(this); 23 | } 24 | 25 | void SpriteComponent::Draw(SDL_Renderer* renderer) 26 | { 27 | if (!mTexture) 28 | { 29 | return; 30 | } 31 | 32 | // 贴图即将被绘制的位置 33 | SDL_Rect dstrect; 34 | dstrect.w = static_cast(mTexWidth * mGameObject->GetScale().x); 35 | dstrect.h = static_cast(mTexHeight * mGameObject->GetScale().y); 36 | dstrect.x = static_cast(mGameObject->GetPosition().x); 37 | dstrect.y = static_cast(mGameObject->GetPosition().y); 38 | // 绘制贴图(考虑旋转) 39 | SDL_RenderCopyEx(renderer, mTexture, nullptr, &dstrect, mGameObject->GetRotation(), nullptr, SDL_FLIP_NONE); 40 | } 41 | 42 | void SpriteComponent::SetTexture(SDL_Texture* texture) 43 | { 44 | mTexture = texture; 45 | // 从贴图中查询贴图的宽和高 46 | SDL_QueryTexture(texture, nullptr, nullptr, &mTexWidth, &mTexHeight); 47 | } 48 | 49 | int SpriteComponent::GetTexWidth() const 50 | { 51 | return mTexWidth; 52 | } 53 | 54 | int SpriteComponent::GetTexHeight() const 55 | { 56 | return mTexHeight; 57 | } 58 | 59 | int SpriteComponent::GetDrawOrder() const 60 | { 61 | return mDrawOrder; 62 | } 63 | 64 | void SpriteComponent::SetDrawOrder(int order) 65 | { 66 | mDrawOrder = order; 67 | } 68 | 69 | 70 | } -------------------------------------------------------------------------------- /Chapter9/src/SpriteComponent.cpp: -------------------------------------------------------------------------------- 1 | //! @file SpriteComponent.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | SpriteComponent::SpriteComponent(GameObject* gameObject, int drawOrder) : 11 | Component(gameObject), 12 | mTexture(nullptr), 13 | mTexWidth(0), 14 | mTexHeight(0), 15 | mDrawOrder(drawOrder) 16 | { 17 | mGameObject->GetGame()->CreateSprite(this); 18 | } 19 | 20 | SpriteComponent::~SpriteComponent() 21 | { 22 | mGameObject->GetGame()->RemoveSprite(this); 23 | } 24 | 25 | void SpriteComponent::Draw(SDL_Renderer* renderer) 26 | { 27 | if (!mTexture) 28 | { 29 | return; 30 | } 31 | 32 | // 贴图即将被绘制的位置 33 | SDL_Rect dstrect; 34 | dstrect.w = static_cast(mTexWidth * mGameObject->GetScale().x); 35 | dstrect.h = static_cast(mTexHeight * mGameObject->GetScale().y); 36 | dstrect.x = static_cast(mGameObject->GetPosition().x); 37 | dstrect.y = static_cast(mGameObject->GetPosition().y); 38 | // 绘制贴图(考虑旋转) 39 | SDL_RenderCopyEx(renderer, mTexture, nullptr, &dstrect, mGameObject->GetRotation(), nullptr, SDL_FLIP_NONE); 40 | } 41 | 42 | void SpriteComponent::SetTexture(SDL_Texture* texture) 43 | { 44 | mTexture = texture; 45 | // 从贴图中查询贴图的宽和高 46 | SDL_QueryTexture(texture, nullptr, nullptr, &mTexWidth, &mTexHeight); 47 | } 48 | 49 | int SpriteComponent::GetTexWidth() const 50 | { 51 | return mTexWidth; 52 | } 53 | 54 | int SpriteComponent::GetTexHeight() const 55 | { 56 | return mTexHeight; 57 | } 58 | 59 | int SpriteComponent::GetDrawOrder() const 60 | { 61 | return mDrawOrder; 62 | } 63 | 64 | void SpriteComponent::SetDrawOrder(int order) 65 | { 66 | mDrawOrder = order; 67 | } 68 | 69 | 70 | } -------------------------------------------------------------------------------- /Chapter10/src/SpriteComponent.cpp: -------------------------------------------------------------------------------- 1 | //! @file SpriteComponent.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Dungeon 9 | { 10 | SpriteComponent::SpriteComponent(GameObject* gameObject, int drawOrder) : 11 | Component(gameObject), 12 | mTexture(nullptr), 13 | mTexWidth(0), 14 | mTexHeight(0), 15 | mDrawOrder(drawOrder) 16 | { 17 | mGameObject->GetGame()->CreateSprite(this); 18 | } 19 | 20 | SpriteComponent::~SpriteComponent() 21 | { 22 | mGameObject->GetGame()->RemoveSprite(this); 23 | } 24 | 25 | void SpriteComponent::Draw(SDL_Renderer* renderer) 26 | { 27 | if (!mTexture) 28 | { 29 | return; 30 | } 31 | 32 | // 贴图即将被绘制的位置 33 | SDL_Rect dstrect; 34 | dstrect.w = static_cast(mTexWidth * mGameObject->GetScale().x); 35 | dstrect.h = static_cast(mTexHeight * mGameObject->GetScale().y); 36 | dstrect.x = static_cast(mGameObject->GetPosition().x); 37 | dstrect.y = static_cast(mGameObject->GetPosition().y); 38 | // 绘制贴图(考虑旋转) 39 | SDL_RenderCopyEx(renderer, mTexture, nullptr, &dstrect, mGameObject->GetRotation(), nullptr, SDL_FLIP_NONE); 40 | } 41 | 42 | void SpriteComponent::SetTexture(SDL_Texture* texture) 43 | { 44 | mTexture = texture; 45 | // 从贴图中查询贴图的宽和高 46 | SDL_QueryTexture(texture, nullptr, nullptr, &mTexWidth, &mTexHeight); 47 | } 48 | 49 | int SpriteComponent::GetTexWidth() const 50 | { 51 | return mTexWidth; 52 | } 53 | 54 | int SpriteComponent::GetTexHeight() const 55 | { 56 | return mTexHeight; 57 | } 58 | 59 | int SpriteComponent::GetDrawOrder() const 60 | { 61 | return mDrawOrder; 62 | } 63 | 64 | void SpriteComponent::SetDrawOrder(int order) 65 | { 66 | mDrawOrder = order; 67 | } 68 | 69 | 70 | } -------------------------------------------------------------------------------- /Chapter7/include/Game.h: -------------------------------------------------------------------------------- 1 | //! @file Game.h 2 | 3 | #ifndef __Dungeon_Game__ 4 | #define __Dungeon_Game__ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | struct SDL_Window; 11 | struct SDL_Renderer; 12 | struct SDL_Texture; 13 | 14 | namespace Dungeon 15 | { 16 | class GameObject; 17 | class SpriteComponent; 18 | class Player; 19 | 20 | class Game 21 | { 22 | public: 23 | //! 构造函数 24 | Game(); 25 | 26 | //! 初始化 27 | bool Initialize(); 28 | //! 主循环 29 | void Loop(); 30 | //! 游戏结束 31 | void Shutdown(); 32 | 33 | //! 创建并存储游戏物体 34 | void CreateGameObject(GameObject* gameObject); 35 | //! 移除游戏对象 36 | void RemoveGameObject(GameObject* gameObject); 37 | //! 创建并按绘制顺序存储精灵 38 | void CreateSprite(SpriteComponent* sprite); 39 | //! 移除精灵 40 | void RemoveSprite(SpriteComponent* sprite); 41 | //! 获取贴图 42 | SDL_Texture* GetTexture(const std::string& fileName); 43 | 44 | private: 45 | //! 处理事件 46 | void Event(); 47 | //! 更新各种状态 48 | void Update(); 49 | //! 渲染 50 | void Draw(); 51 | 52 | //! 设置帧率 53 | void Tick(int fps); 54 | //! 加载数据 55 | void LoadData(); 56 | //! 释放数据 57 | void UnloadData(); 58 | //! 加载贴图并重命名 59 | void LoadTexture(const std::string& fileName, const std::string& newName); 60 | 61 | std::vector mGameObjects; //!< 游戏物体容器 62 | std::vector mPendingObjects; //!< 等待状态的游戏物体容器 63 | std::vector mSprites; //!< 存放精灵的容器 64 | 65 | std::unordered_map mTextures; //!< 存放贴图的容器 66 | 67 | SDL_Window* mWindow; //!< 窗口 68 | SDL_Renderer* mRenderer; //!< 渲染器 69 | bool mIsRunning; //!< 运行状态 70 | bool mIsUpdating; //!< 是否在更新状态 71 | 72 | Player* mPlayer; //!< 玩家角色 73 | }; 74 | } 75 | 76 | #endif // __Dungeon_Game__ -------------------------------------------------------------------------------- /Chapter8/include/Game.h: -------------------------------------------------------------------------------- 1 | //! @file Game.h 2 | 3 | #ifndef __Dungeon_Game__ 4 | #define __Dungeon_Game__ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | struct SDL_Window; 11 | struct SDL_Renderer; 12 | struct SDL_Texture; 13 | 14 | namespace Dungeon 15 | { 16 | class GameObject; 17 | class SpriteComponent; 18 | class Player; 19 | 20 | class Game 21 | { 22 | public: 23 | //! 构造函数 24 | Game(); 25 | 26 | //! 初始化 27 | bool Initialize(); 28 | //! 主循环 29 | void Loop(); 30 | //! 游戏结束 31 | void Shutdown(); 32 | 33 | //! 创建并存储游戏物体 34 | void CreateGameObject(GameObject* gameObject); 35 | //! 移除游戏对象 36 | void RemoveGameObject(GameObject* gameObject); 37 | //! 创建并按绘制顺序存储精灵 38 | void CreateSprite(SpriteComponent* sprite); 39 | //! 移除精灵 40 | void RemoveSprite(SpriteComponent* sprite); 41 | //! 获取贴图 42 | SDL_Texture* GetTexture(const std::string& fileName); 43 | 44 | private: 45 | //! 处理事件 46 | void Event(); 47 | //! 更新各种状态 48 | void Update(); 49 | //! 渲染 50 | void Draw(); 51 | 52 | //! 设置帧率 53 | void Tick(int fps); 54 | //! 加载数据 55 | void LoadData(); 56 | //! 释放数据 57 | void UnloadData(); 58 | //! 加载贴图并重命名 59 | void LoadTexture(const std::string& fileName, const std::string& newName); 60 | 61 | std::vector mGameObjects; //!< 游戏物体容器 62 | std::vector mPendingObjects; //!< 等待状态的游戏物体容器 63 | std::vector mSprites; //!< 存放精灵的容器 64 | 65 | std::unordered_map mTextures; //!< 存放贴图的容器 66 | 67 | SDL_Window* mWindow; //!< 窗口 68 | SDL_Renderer* mRenderer; //!< 渲染器 69 | bool mIsRunning; //!< 运行状态 70 | bool mIsUpdating; //!< 是否在更新状态 71 | 72 | Player* mPlayer; //!< 玩家角色 73 | }; 74 | } 75 | 76 | #endif // __Dungeon_Game__ -------------------------------------------------------------------------------- /Chapter10/include/GameObject.h: -------------------------------------------------------------------------------- 1 | //! @file GameObject.h 2 | 3 | #ifndef __Dungeon_GameObject__ 4 | #define __Dungeon_GameObject__ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace Dungeon 11 | { 12 | class GameObject 13 | { 14 | public: 15 | //! 物体状态 16 | enum class State 17 | { 18 | EActive, 19 | EDead 20 | }; 21 | 22 | //! 构造函数 23 | GameObject(class Game* game); 24 | //! 析构函数 25 | virtual ~GameObject(); 26 | 27 | //! 处理输入 28 | void ProcessInput(const uint8_t* state); 29 | //! 每帧更新 30 | void Update(); 31 | //! 添加组件 32 | void AddComponent(class Component* component); 33 | //! 移除组件 34 | void RemoveComponent(class Component* component); 35 | 36 | //! 获取特定类型的组件,并得到该组件类型的指针 37 | template T* GetComponent() 38 | { 39 | for (auto com : mComponents) 40 | { 41 | T* component = dynamic_cast(com); 42 | if (component != nullptr) 43 | { 44 | return component; 45 | } 46 | } 47 | return nullptr; 48 | } 49 | 50 | //! game对象的get 51 | Game* GetGame() const; 52 | //! 物体状态的get和set 53 | State GetState() const; 54 | void SetState(const State state); 55 | //! 位置的get和set 56 | Vector2 GetPosition() const; 57 | void SetPosition(const Vector2& p); 58 | //! 缩放大小的get和set 59 | Vector2 GetScale() const; 60 | void SetScale(const Vector2& s); 61 | //! 旋转的get和set 62 | float GetRotation() const; 63 | void SetRotation(float r); 64 | 65 | protected: 66 | std::vector mComponents; //!< 组件数组 67 | 68 | private: 69 | Game* mGame; //!< Game对象 70 | State mState; //!< 物体当前状态 71 | Vector2 mPosition; //!< 位置坐标 72 | Vector2 mScale; //!< 缩放 73 | float mRotation; //!< 旋转 74 | }; 75 | } 76 | 77 | #endif // __Dungeon_GameObject__ -------------------------------------------------------------------------------- /Chapter8/include/GameObject.h: -------------------------------------------------------------------------------- 1 | //! @file GameObject.h 2 | 3 | #ifndef __Dungeon_GameObject__ 4 | #define __Dungeon_GameObject__ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace Dungeon 11 | { 12 | class GameObject 13 | { 14 | public: 15 | //! 物体状态 16 | enum class State 17 | { 18 | EActive, 19 | EDead 20 | }; 21 | 22 | //! 构造函数 23 | GameObject(class Game* game); 24 | //! 析构函数 25 | virtual ~GameObject(); 26 | 27 | //! 处理输入 28 | void ProcessInput(const uint8_t* state); 29 | //! 每帧更新 30 | void Update(); 31 | //! 添加组件 32 | void AddComponent(class Component* component); 33 | //! 移除组件 34 | void RemoveComponent(class Component* component); 35 | 36 | //! 获取特定类型的组件,并得到该组件类型的指针 37 | template T* GetComponent() 38 | { 39 | for (auto com : mComponents) 40 | { 41 | T* component = dynamic_cast(com); 42 | if (component != nullptr) 43 | { 44 | return component; 45 | } 46 | } 47 | return nullptr; 48 | } 49 | 50 | //! game对象的get 51 | Game* GetGame() const; 52 | //! 物体状态的get和set 53 | State GetState() const; 54 | void SetState(const State state); 55 | //! 位置的get和set 56 | Vector2 GetPosition() const; 57 | void SetPosition(const Vector2& p); 58 | //! 缩放大小的get和set 59 | Vector2 GetScale() const; 60 | void SetScale(const Vector2& s); 61 | //! 旋转的get和set 62 | float GetRotation() const; 63 | void SetRotation(float r); 64 | 65 | protected: 66 | std::vector mComponents; //!< 组件数组 67 | 68 | private: 69 | Game* mGame; //!< Game对象 70 | State mState; //!< 物体当前状态 71 | Vector2 mPosition; //!< 位置坐标 72 | Vector2 mScale; //!< 缩放 73 | float mRotation; //!< 旋转 74 | }; 75 | } 76 | 77 | #endif // __Dungeon_GameObject__ -------------------------------------------------------------------------------- /Chapter9/include/GameObject.h: -------------------------------------------------------------------------------- 1 | //! @file GameObject.h 2 | 3 | #ifndef __Dungeon_GameObject__ 4 | #define __Dungeon_GameObject__ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace Dungeon 11 | { 12 | class GameObject 13 | { 14 | public: 15 | //! 物体状态 16 | enum class State 17 | { 18 | EActive, 19 | EDead 20 | }; 21 | 22 | //! 构造函数 23 | GameObject(class Game* game); 24 | //! 析构函数 25 | virtual ~GameObject(); 26 | 27 | //! 处理输入 28 | void ProcessInput(const uint8_t* state); 29 | //! 每帧更新 30 | void Update(); 31 | //! 添加组件 32 | void AddComponent(class Component* component); 33 | //! 移除组件 34 | void RemoveComponent(class Component* component); 35 | 36 | //! 获取特定类型的组件,并得到该组件类型的指针 37 | template T* GetComponent() 38 | { 39 | for (auto com : mComponents) 40 | { 41 | T* component = dynamic_cast(com); 42 | if (component != nullptr) 43 | { 44 | return component; 45 | } 46 | } 47 | return nullptr; 48 | } 49 | 50 | //! game对象的get 51 | Game* GetGame() const; 52 | //! 物体状态的get和set 53 | State GetState() const; 54 | void SetState(const State state); 55 | //! 位置的get和set 56 | Vector2 GetPosition() const; 57 | void SetPosition(const Vector2& p); 58 | //! 缩放大小的get和set 59 | Vector2 GetScale() const; 60 | void SetScale(const Vector2& s); 61 | //! 旋转的get和set 62 | float GetRotation() const; 63 | void SetRotation(float r); 64 | 65 | protected: 66 | std::vector mComponents; //!< 组件数组 67 | 68 | private: 69 | Game* mGame; //!< Game对象 70 | State mState; //!< 物体当前状态 71 | Vector2 mPosition; //!< 位置坐标 72 | Vector2 mScale; //!< 缩放 73 | float mRotation; //!< 旋转 74 | }; 75 | } 76 | 77 | #endif // __Dungeon_GameObject__ -------------------------------------------------------------------------------- /Chapter10/include/Game.h: -------------------------------------------------------------------------------- 1 | //! @file Game.h 2 | 3 | #ifndef __Dungeon_Game__ 4 | #define __Dungeon_Game__ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | struct SDL_Window; 11 | struct SDL_Renderer; 12 | struct SDL_Texture; 13 | 14 | namespace Dungeon 15 | { 16 | class GameObject; 17 | class SpriteComponent; 18 | class Player; 19 | class Dungeon; 20 | 21 | class Game 22 | { 23 | public: 24 | //! 构造函数 25 | Game(); 26 | 27 | //! 初始化 28 | bool Initialize(); 29 | //! 主循环 30 | void Loop(); 31 | //! 游戏结束 32 | void Shutdown(); 33 | 34 | //! 创建并存储游戏物体 35 | void CreateGameObject(GameObject* gameObject); 36 | //! 移除游戏对象 37 | void RemoveGameObject(GameObject* gameObject); 38 | //! 创建并按绘制顺序存储精灵 39 | void CreateSprite(SpriteComponent* sprite); 40 | //! 移除精灵 41 | void RemoveSprite(SpriteComponent* sprite); 42 | //! 获取贴图 43 | SDL_Texture* GetTexture(const std::string& fileName); 44 | 45 | private: 46 | //! 处理事件 47 | void Event(); 48 | //! 更新各种状态 49 | void Update(); 50 | //! 渲染 51 | void Draw(); 52 | 53 | //! 设置帧率 54 | void Tick(int fps); 55 | //! 加载数据 56 | void LoadData(); 57 | //! 释放数据 58 | void UnloadData(); 59 | //! 加载贴图并重命名 60 | void LoadTexture(const std::string& fileName, const std::string& newName); 61 | 62 | std::vector mGameObjects; //!< 游戏物体容器 63 | std::vector mPendingObjects; //!< 等待状态的游戏物体容器 64 | std::vector mSprites; //!< 存放精灵的容器 65 | 66 | std::unordered_map mTextures; //!< 存放贴图的容器 67 | 68 | SDL_Window* mWindow; //!< 窗口 69 | SDL_Renderer* mRenderer; //!< 渲染器 70 | bool mIsRunning; //!< 运行状态 71 | bool mIsUpdating; //!< 是否在更新状态 72 | 73 | Player* mPlayer; //!< 玩家角色 74 | Dungeon* mDungeon; //!< 地牢对象 75 | }; 76 | } 77 | 78 | #endif // __Dungeon_Game__ -------------------------------------------------------------------------------- /Chapter9/include/Game.h: -------------------------------------------------------------------------------- 1 | //! @file Game.h 2 | 3 | #ifndef __Dungeon_Game__ 4 | #define __Dungeon_Game__ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | struct SDL_Window; 11 | struct SDL_Renderer; 12 | struct SDL_Texture; 13 | 14 | namespace Dungeon 15 | { 16 | class GameObject; 17 | class SpriteComponent; 18 | class Player; 19 | class Dungeon; 20 | 21 | class Game 22 | { 23 | public: 24 | //! 构造函数 25 | Game(); 26 | 27 | //! 初始化 28 | bool Initialize(); 29 | //! 主循环 30 | void Loop(); 31 | //! 游戏结束 32 | void Shutdown(); 33 | 34 | //! 创建并存储游戏物体 35 | void CreateGameObject(GameObject* gameObject); 36 | //! 移除游戏对象 37 | void RemoveGameObject(GameObject* gameObject); 38 | //! 创建并按绘制顺序存储精灵 39 | void CreateSprite(SpriteComponent* sprite); 40 | //! 移除精灵 41 | void RemoveSprite(SpriteComponent* sprite); 42 | //! 获取贴图 43 | SDL_Texture* GetTexture(const std::string& fileName); 44 | 45 | private: 46 | //! 处理事件 47 | void Event(); 48 | //! 更新各种状态 49 | void Update(); 50 | //! 渲染 51 | void Draw(); 52 | 53 | //! 设置帧率 54 | void Tick(int fps); 55 | //! 加载数据 56 | void LoadData(); 57 | //! 释放数据 58 | void UnloadData(); 59 | //! 加载贴图并重命名 60 | void LoadTexture(const std::string& fileName, const std::string& newName); 61 | 62 | std::vector mGameObjects; //!< 游戏物体容器 63 | std::vector mPendingObjects; //!< 等待状态的游戏物体容器 64 | std::vector mSprites; //!< 存放精灵的容器 65 | 66 | std::unordered_map mTextures; //!< 存放贴图的容器 67 | 68 | SDL_Window* mWindow; //!< 窗口 69 | SDL_Renderer* mRenderer; //!< 渲染器 70 | bool mIsRunning; //!< 运行状态 71 | bool mIsUpdating; //!< 是否在更新状态 72 | 73 | Player* mPlayer; //!< 玩家角色 74 | Dungeon* mDungeon; //!< 地牢对象 75 | }; 76 | } 77 | 78 | #endif // __Dungeon_Game__ -------------------------------------------------------------------------------- /Chapter5/Dungeon.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 源文件 29 | 30 | 31 | 源文件 32 | 33 | 34 | 35 | 36 | 头文件 37 | 38 | 39 | 头文件 40 | 41 | 42 | 头文件 43 | 44 | 45 | 头文件 46 | 47 | 48 | -------------------------------------------------------------------------------- /Chapter1/include/SDL/SDL_test_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_memory.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | #ifndef SDL_test_memory_h_ 31 | #define SDL_test_memory_h_ 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | /** 41 | * \brief Start tracking SDL memory allocations 42 | * 43 | * \note This should be called before any other SDL functions for complete tracking coverage 44 | */ 45 | int SDLTest_TrackAllocations(void); 46 | 47 | /** 48 | * \brief Print a log of any outstanding allocations 49 | * 50 | * \note This can be called after SDL_Quit() 51 | */ 52 | void SDLTest_LogAllocations(void); 53 | 54 | 55 | /* Ends C function definitions when using C++ */ 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | #include "close_code.h" 60 | 61 | #endif /* SDL_test_memory_h_ */ 62 | 63 | /* vi: set ts=4 sw=4 expandtab: */ 64 | -------------------------------------------------------------------------------- /Chapter10/include/SDL/SDL_test_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_memory.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | #ifndef SDL_test_memory_h_ 31 | #define SDL_test_memory_h_ 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | /** 41 | * \brief Start tracking SDL memory allocations 42 | * 43 | * \note This should be called before any other SDL functions for complete tracking coverage 44 | */ 45 | int SDLTest_TrackAllocations(void); 46 | 47 | /** 48 | * \brief Print a log of any outstanding allocations 49 | * 50 | * \note This can be called after SDL_Quit() 51 | */ 52 | void SDLTest_LogAllocations(void); 53 | 54 | 55 | /* Ends C function definitions when using C++ */ 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | #include "close_code.h" 60 | 61 | #endif /* SDL_test_memory_h_ */ 62 | 63 | /* vi: set ts=4 sw=4 expandtab: */ 64 | -------------------------------------------------------------------------------- /Chapter2/include/SDL/SDL_test_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_memory.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | #ifndef SDL_test_memory_h_ 31 | #define SDL_test_memory_h_ 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | /** 41 | * \brief Start tracking SDL memory allocations 42 | * 43 | * \note This should be called before any other SDL functions for complete tracking coverage 44 | */ 45 | int SDLTest_TrackAllocations(void); 46 | 47 | /** 48 | * \brief Print a log of any outstanding allocations 49 | * 50 | * \note This can be called after SDL_Quit() 51 | */ 52 | void SDLTest_LogAllocations(void); 53 | 54 | 55 | /* Ends C function definitions when using C++ */ 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | #include "close_code.h" 60 | 61 | #endif /* SDL_test_memory_h_ */ 62 | 63 | /* vi: set ts=4 sw=4 expandtab: */ 64 | -------------------------------------------------------------------------------- /Chapter3/include/SDL/SDL_test_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_memory.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | #ifndef SDL_test_memory_h_ 31 | #define SDL_test_memory_h_ 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | /** 41 | * \brief Start tracking SDL memory allocations 42 | * 43 | * \note This should be called before any other SDL functions for complete tracking coverage 44 | */ 45 | int SDLTest_TrackAllocations(void); 46 | 47 | /** 48 | * \brief Print a log of any outstanding allocations 49 | * 50 | * \note This can be called after SDL_Quit() 51 | */ 52 | void SDLTest_LogAllocations(void); 53 | 54 | 55 | /* Ends C function definitions when using C++ */ 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | #include "close_code.h" 60 | 61 | #endif /* SDL_test_memory_h_ */ 62 | 63 | /* vi: set ts=4 sw=4 expandtab: */ 64 | -------------------------------------------------------------------------------- /Chapter4/include/SDL/SDL_test_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_memory.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | #ifndef SDL_test_memory_h_ 31 | #define SDL_test_memory_h_ 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | /** 41 | * \brief Start tracking SDL memory allocations 42 | * 43 | * \note This should be called before any other SDL functions for complete tracking coverage 44 | */ 45 | int SDLTest_TrackAllocations(void); 46 | 47 | /** 48 | * \brief Print a log of any outstanding allocations 49 | * 50 | * \note This can be called after SDL_Quit() 51 | */ 52 | void SDLTest_LogAllocations(void); 53 | 54 | 55 | /* Ends C function definitions when using C++ */ 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | #include "close_code.h" 60 | 61 | #endif /* SDL_test_memory_h_ */ 62 | 63 | /* vi: set ts=4 sw=4 expandtab: */ 64 | -------------------------------------------------------------------------------- /Chapter5/include/SDL/SDL_test_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_memory.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | #ifndef SDL_test_memory_h_ 31 | #define SDL_test_memory_h_ 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | /** 41 | * \brief Start tracking SDL memory allocations 42 | * 43 | * \note This should be called before any other SDL functions for complete tracking coverage 44 | */ 45 | int SDLTest_TrackAllocations(void); 46 | 47 | /** 48 | * \brief Print a log of any outstanding allocations 49 | * 50 | * \note This can be called after SDL_Quit() 51 | */ 52 | void SDLTest_LogAllocations(void); 53 | 54 | 55 | /* Ends C function definitions when using C++ */ 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | #include "close_code.h" 60 | 61 | #endif /* SDL_test_memory_h_ */ 62 | 63 | /* vi: set ts=4 sw=4 expandtab: */ 64 | -------------------------------------------------------------------------------- /Chapter6/include/SDL/SDL_test_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_memory.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | #ifndef SDL_test_memory_h_ 31 | #define SDL_test_memory_h_ 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | /** 41 | * \brief Start tracking SDL memory allocations 42 | * 43 | * \note This should be called before any other SDL functions for complete tracking coverage 44 | */ 45 | int SDLTest_TrackAllocations(void); 46 | 47 | /** 48 | * \brief Print a log of any outstanding allocations 49 | * 50 | * \note This can be called after SDL_Quit() 51 | */ 52 | void SDLTest_LogAllocations(void); 53 | 54 | 55 | /* Ends C function definitions when using C++ */ 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | #include "close_code.h" 60 | 61 | #endif /* SDL_test_memory_h_ */ 62 | 63 | /* vi: set ts=4 sw=4 expandtab: */ 64 | -------------------------------------------------------------------------------- /Chapter7/include/SDL/SDL_test_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_memory.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | #ifndef SDL_test_memory_h_ 31 | #define SDL_test_memory_h_ 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | /** 41 | * \brief Start tracking SDL memory allocations 42 | * 43 | * \note This should be called before any other SDL functions for complete tracking coverage 44 | */ 45 | int SDLTest_TrackAllocations(void); 46 | 47 | /** 48 | * \brief Print a log of any outstanding allocations 49 | * 50 | * \note This can be called after SDL_Quit() 51 | */ 52 | void SDLTest_LogAllocations(void); 53 | 54 | 55 | /* Ends C function definitions when using C++ */ 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | #include "close_code.h" 60 | 61 | #endif /* SDL_test_memory_h_ */ 62 | 63 | /* vi: set ts=4 sw=4 expandtab: */ 64 | -------------------------------------------------------------------------------- /Chapter8/include/SDL/SDL_test_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_memory.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | #ifndef SDL_test_memory_h_ 31 | #define SDL_test_memory_h_ 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | /** 41 | * \brief Start tracking SDL memory allocations 42 | * 43 | * \note This should be called before any other SDL functions for complete tracking coverage 44 | */ 45 | int SDLTest_TrackAllocations(void); 46 | 47 | /** 48 | * \brief Print a log of any outstanding allocations 49 | * 50 | * \note This can be called after SDL_Quit() 51 | */ 52 | void SDLTest_LogAllocations(void); 53 | 54 | 55 | /* Ends C function definitions when using C++ */ 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | #include "close_code.h" 60 | 61 | #endif /* SDL_test_memory_h_ */ 62 | 63 | /* vi: set ts=4 sw=4 expandtab: */ 64 | -------------------------------------------------------------------------------- /Chapter9/include/SDL/SDL_test_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2020 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_memory.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | #ifndef SDL_test_memory_h_ 31 | #define SDL_test_memory_h_ 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | /** 41 | * \brief Start tracking SDL memory allocations 42 | * 43 | * \note This should be called before any other SDL functions for complete tracking coverage 44 | */ 45 | int SDLTest_TrackAllocations(void); 46 | 47 | /** 48 | * \brief Print a log of any outstanding allocations 49 | * 50 | * \note This can be called after SDL_Quit() 51 | */ 52 | void SDLTest_LogAllocations(void); 53 | 54 | 55 | /* Ends C function definitions when using C++ */ 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | #include "close_code.h" 60 | 61 | #endif /* SDL_test_memory_h_ */ 62 | 63 | /* vi: set ts=4 sw=4 expandtab: */ 64 | -------------------------------------------------------------------------------- /Chapter10/src/MoveComponent.cpp: -------------------------------------------------------------------------------- 1 | //! @file MoveComponent.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Dungeon 8 | { 9 | MoveComponent::MoveComponent(GameObject* gameObject): 10 | Component(gameObject), 11 | mSpeed(150), 12 | mDir(Vector2::Zero), 13 | mDst(Vector2::Zero), 14 | mIsMoving(false), 15 | mPixelsCount(0), 16 | mMapArray(nullptr) 17 | { 18 | } 19 | 20 | void MoveComponent::Update() 21 | { 22 | if(mIsMoving) 23 | { 24 | ProcessMoving(); 25 | } 26 | } 27 | 28 | void MoveComponent::SetDir(const Vector2& dir) 29 | { 30 | // 角色处于移动状态中时跳过本函数 31 | if (mIsMoving) 32 | { 33 | return; 34 | } 35 | 36 | mDir = dir; 37 | Vector2 curPos = mGameObject->GetPosition(); 38 | // 计算临时的目的地 39 | Vector2 tempDst = curPos + mDir * 32; 40 | // 检测该目的地是否可以移动 41 | if (WallCheck(tempDst)) 42 | { 43 | // 使角色进入移动状态 44 | mIsMoving = true; 45 | mDst = tempDst; 46 | } 47 | } 48 | 49 | void MoveComponent::SetMap(int* map) 50 | { 51 | mMapArray = map; 52 | } 53 | 54 | void MoveComponent::ProcessMoving() 55 | { 56 | Vector2 curPos = mGameObject->GetPosition(); 57 | 58 | // 实际速度要乘上增量时间 59 | float realSpeed = mSpeed * Timer::deltaTime; 60 | // 计算出移动中的临时位置 61 | Vector2 tempPos = curPos + mDir * realSpeed; 62 | 63 | // 已经走过的像素数加上这帧即将走过的像素数 64 | mPixelsCount += realSpeed; 65 | // 还未走完一整格 66 | if (mPixelsCount < 32) 67 | { 68 | mGameObject->SetPosition(tempPos); 69 | } 70 | // 走完一整格 抵达目的地 71 | else 72 | { 73 | ReachOneGrid(); 74 | } 75 | } 76 | 77 | bool MoveComponent::WallCheck(const Vector2& dst) 78 | { 79 | // 将像素坐标转换成格子坐标 80 | int gridX = static_cast(dst.x / 32); 81 | int gridY = static_cast(dst.y / 32); 82 | 83 | // 地图数组内元素的值为1时说明不可通行 84 | if (mMapArray[gridY * 20 + gridX] == 1) 85 | { 86 | return false; 87 | } 88 | return true; 89 | } 90 | 91 | void MoveComponent::ReachOneGrid() 92 | { 93 | // 重置各种状态 94 | mIsMoving = false; 95 | mPixelsCount = 0; 96 | mDir = Vector2::Zero; 97 | 98 | // 将目的地设置为当前位置 99 | mGameObject->SetPosition(mDst); 100 | } 101 | } --------------------------------------------------------------------------------