diff --git a/tutorials/flappy-bird/step_1/CMakeLists.txt b/tutorials/flappy-bird/step_1/CMakeLists.txt new file mode 100644 index 00000000..3336581e --- /dev/null +++ b/tutorials/flappy-bird/step_1/CMakeLists.txt @@ -0,0 +1,78 @@ +if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) + message(FATAL_ERROR "Prevented in-tree build. Please create a build directory outside of the source code and call cmake from there") +endif () + +##! Minimum version of the CMake. +cmake_minimum_required(VERSION 3.14) + +##! C++ Standard needed by the SDK is 17 +set(CMAKE_CXX_STANDARD 17) + +##! Our Project title, here flappy-bird. +project(flappy-bird DESCRIPTION "An awesome flappy-bird" LANGUAGES CXX) + +##! The SDK need's clang as main compiler. +if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") + message(FATAL_ERROR "Only Clang is supported (minimum LLVM 8.0)") + endif() +endif () + +##! We will let know the SDK if our on Linux +if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + set(LINUX TRUE) +endif () + +##! We include the module from CMake for fetching dependencies +include(FetchContent) + +##! We declare information about the dependance that we want to fetch. +FetchContent_Declare( + antara-gaming-sdk + URL https://github.com/KomodoPlatform/antara-gaming-sdk/archive/master.zip +) + +##! We set extras modules from the SDK that we want to use, here we will use the SFML module. +set(USE_SFML_ANTARA_WRAPPER ON) + +##! We fetch our dependence +FetchContent_MakeAvailable(antara-gaming-sdk) + +##! Calling this macros provided by the sdk will if you are on Apple init the environment for this OS (std::filesystem). +init_apple_env() + +##! Osx bundle icon +set(ICON) +configure_icon_osx(data/osx/kmd_logo.icns ICON kmd_logo.icns) + +##! We create the executable with the project name +add_executable(${PROJECT_NAME} MACOSX_BUNDLE ${ICON} flappy-bird.cpp) + +##! Setting output directory +set_target_properties(${PROJECT_NAME} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/" + ) + +##! We link the SDK modules that we want to use to our executable +target_link_libraries(${PROJECT_NAME} PUBLIC antara::world antara::sfml antara::collisions) + +##! Move assets +if (WIN32) + file(COPY assets DESTINATION ${CMAKE_BINARY_DIR}/bin/) + ADD_CUSTOM_COMMAND(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory "${SFML_BINARY_DIR}/lib" "${CMAKE_BINARY_DIR}/bin/" + COMMENT "copying dlls …" + $ + ) + + ADD_CUSTOM_COMMAND(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy "${SFML_SOURCE_DIR}/extlibs/bin/x64/openal32.dll" "${CMAKE_BINARY_DIR}/bin/openal32.dll" + COMMENT "copying dlls …" + $ + ) +endif () + +if (APPLE) + file(COPY assets DESTINATION ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME}.app/Contents/Resources) +endif() \ No newline at end of file diff --git a/tutorials/flappy-bird/step_1/assets/config/game.config.maker.json b/tutorials/flappy-bird/step_1/assets/config/game.config.maker.json new file mode 100644 index 00000000..6690ed44 --- /dev/null +++ b/tutorials/flappy-bird/step_1/assets/config/game.config.maker.json @@ -0,0 +1 @@ +{"background_color":[0,0,0,255],"canvas_height":1080.0,"canvas_width":1920.0,"custom_canvas_height":true,"custom_canvas_width":true,"native_desktop_mode":false,"scale_mode":"fit","window_height":1080.0,"window_title":"game title","window_width":1920.0} \ No newline at end of file diff --git a/tutorials/flappy-bird/step_1/assets/fonts/sansation.ttf b/tutorials/flappy-bird/step_1/assets/fonts/sansation.ttf new file mode 100644 index 00000000..d85fbc81 Binary files /dev/null and b/tutorials/flappy-bird/step_1/assets/fonts/sansation.ttf differ diff --git a/tutorials/flappy-bird/step_1/data/linux/komodo_icon.png b/tutorials/flappy-bird/step_1/data/linux/komodo_icon.png new file mode 100644 index 00000000..89e5dd28 Binary files /dev/null and b/tutorials/flappy-bird/step_1/data/linux/komodo_icon.png differ diff --git a/tutorials/flappy-bird/step_1/data/linux/org.antara.gaming.sfml.flappybird.appdata.xml b/tutorials/flappy-bird/step_1/data/linux/org.antara.gaming.sfml.flappybird.appdata.xml new file mode 100644 index 00000000..7e6a1046 --- /dev/null +++ b/tutorials/flappy-bird/step_1/data/linux/org.antara.gaming.sfml.flappybird.appdata.xml @@ -0,0 +1,20 @@ + + org.antara.gaming.sfml.flappybird.desktop + MIT + MIT + flappy-bird + flappy-bird tutorial antara gaming sdk + +

Written in c++17

+
+ org.antara.gaming.sfml.flappybird.desktop + https://github.com/KomodoPlatform/antara-gaming-sdk + + + https://www.freedesktop.org/software/appstream/docs/images/scr-examples/geany-good.png + + + + org.antara.gaming.sfml.flappybird.desktop + +
\ No newline at end of file diff --git a/tutorials/flappy-bird/step_1/data/linux/org.antara.gaming.sfml.flappybird.desktop b/tutorials/flappy-bird/step_1/data/linux/org.antara.gaming.sfml.flappybird.desktop new file mode 100644 index 00000000..d525c088 --- /dev/null +++ b/tutorials/flappy-bird/step_1/data/linux/org.antara.gaming.sfml.flappybird.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +Type=Application +Name=flappy-bird +Exec=flappy-bird +Icon=komodo_icon +Categories=Game; \ No newline at end of file diff --git a/tutorials/flappy-bird/step_1/data/osx/Packaging_CMakeDMGBackground.tif b/tutorials/flappy-bird/step_1/data/osx/Packaging_CMakeDMGBackground.tif new file mode 100644 index 00000000..91c4b130 Binary files /dev/null and b/tutorials/flappy-bird/step_1/data/osx/Packaging_CMakeDMGBackground.tif differ diff --git a/tutorials/flappy-bird/step_1/data/osx/Packaging_CMakeDMGSetup.scpt b/tutorials/flappy-bird/step_1/data/osx/Packaging_CMakeDMGSetup.scpt new file mode 100644 index 00000000..2bea22d8 --- /dev/null +++ b/tutorials/flappy-bird/step_1/data/osx/Packaging_CMakeDMGSetup.scpt @@ -0,0 +1,57 @@ +on run argv + set image_name to item 1 of argv + + tell application "Finder" + tell disk image_name + + -- wait for the image to finish mounting + set open_attempts to 0 + repeat while open_attempts < 4 + try + open + delay 1 + set open_attempts to 5 + close + on error errStr number errorNumber + set open_attempts to open_attempts + 1 + delay 10 + end try + end repeat + delay 5 + + -- open the image the first time and save a DS_Store with just + -- background and icon setup + open + set current view of container window to icon view + set theViewOptions to the icon view options of container window + set background picture of theViewOptions to file ".background:background.tif" + set arrangement of theViewOptions to not arranged + set icon size of theViewOptions to 128 + delay 5 + close + + -- next setup the position of the app and Applications symlink + -- plus hide all the window decorationPackaging_CMakeDMGBackground.tif + open + update without registering applications + tell container window + set sidebar width to 0 + set statusbar visible to false + set toolbar visible to false + set the bounds to { 400, 100, 900, 465 } + set position of item "flappy-bird.app" to { 133, 200 } + set position of item "Applications" to { 378, 200 } + end tell + update without registering applications + delay 5 + close + + -- one last open and close so you can see everything looks correct + open + delay 5 + close + + end tell + delay 1 +end tell +end run \ No newline at end of file diff --git a/tutorials/flappy-bird/step_1/data/osx/kmd_logo.icns b/tutorials/flappy-bird/step_1/data/osx/kmd_logo.icns new file mode 100644 index 00000000..5977224d Binary files /dev/null and b/tutorials/flappy-bird/step_1/data/osx/kmd_logo.icns differ diff --git a/tutorials/flappy-bird/step_1/data/osx/sfml_flappybird_install.cmake b/tutorials/flappy-bird/step_1/data/osx/sfml_flappybird_install.cmake new file mode 100644 index 00000000..2bda51ae --- /dev/null +++ b/tutorials/flappy-bird/step_1/data/osx/sfml_flappybird_install.cmake @@ -0,0 +1,35 @@ +if (APPLE) + set_target_properties(${PROJECT_NAME} PROPERTIES + MACOSX_BUNDLE_BUNDLE_NAME "${PROJECT_NAME}" + RESOURCE data/osx/${PROJECT_NAME}.icns + MACOSX_BUNDLE_ICON_FILE ${PROJECT_NAME} + MACOSX_BUNDLE_SHORT_VERSION_STRING 0.0.1 + MACOSX_BUNDLE_LONG_VERSION_STRING 0.0.1 + MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/cmake/MacOSXBundleInfo.plist.in") + add_custom_command(TARGET ${PROJECT_NAME} + POST_BUILD COMMAND + ${CMAKE_INSTALL_NAME_TOOL} -add_rpath "@executable_path/../Frameworks/" + $) +endif () + +if (APPLE) + install(TARGETS ${PROJECT_NAME} + BUNDLE DESTINATION . COMPONENT Runtime + RUNTIME DESTINATION bin COMPONENT Runtime + ) + + # Note Mac specific extension .app + set(APPS "\${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app") + + # Directories to look for dependencies + set(DIRS ${CMAKE_BINARY_DIR}) + + install(CODE "include(BundleUtilities) + fixup_bundle(\"${APPS}\" \"\" \"${DIRS}\")") + + set(CPACK_GENERATOR "DRAGNDROP") + set(CPACK_DMG_DS_STORE_SETUP_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/data/osx/Packaging_CMakeDMGSetup.scpt") + set(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_CURRENT_SOURCE_DIR}/data/osx/Packaging_CMakeDMGBackground.tif") + set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") + include(CPack) +endif () \ No newline at end of file diff --git a/tutorials/flappy-bird/step_1/flappy-bird.cpp b/tutorials/flappy-bird/step_1/flappy-bird.cpp new file mode 100644 index 00000000..7f10f83f --- /dev/null +++ b/tutorials/flappy-bird/step_1/flappy-bird.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include +#include + +// For convenience +using namespace antara::gaming; +using namespace std::string_literals; + +// Game Scene +class game_scene final : public scenes::base_scene { +public: + game_scene(entt::registry ®istry) noexcept : base_scene(registry) { + } + + // Scene name + std::string scene_name() noexcept final { + return "game_scene"; + } + +private: + // Update the game every tick + void update() noexcept final { + } +}; + +// Game world +struct flappy_bird_world : world::app { + // Game entry point + flappy_bird_world() noexcept { + // Load the graphical system + auto &graphic_system = system_manager_.create_system(); + + // Load the resources system + entity_registry_.set(entity_registry_); + + // Load the input system with the window from the graphical system + system_manager_.create_system(graphic_system.get_window()); + + // Load the scenes manager + auto &scene_manager = system_manager_.create_system(); + + // Change the current_scene to "game_scene" by pushing it. + scene_manager.change_scene(std::make_unique(entity_registry_), true); + } +}; + +int main() { + // Declare the world + flappy_bird_world game; + + // Run the game + return game.run(); +} \ No newline at end of file