├── .gitignore ├── game.hpp ├── assets ├── no-icon.png └── no-image.png ├── assets.yml ├── metadata.yml ├── LICENSE ├── CMakeLists.txt ├── README.md ├── game.cpp └── .github └── workflows └── build.yml /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | build.*/ 3 | -------------------------------------------------------------------------------- /game.hpp: -------------------------------------------------------------------------------- 1 | #include "32blit.hpp" 2 | -------------------------------------------------------------------------------- /assets/no-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/32blit/32blit-boilerplate/HEAD/assets/no-icon.png -------------------------------------------------------------------------------- /assets/no-image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/32blit/32blit-boilerplate/HEAD/assets/no-image.png -------------------------------------------------------------------------------- /assets.yml: -------------------------------------------------------------------------------- 1 | # All these assets will be created in assets.cpp, which CMake will 2 | # link automagically. 3 | # References can be picked up by including assets.hpp 4 | 5 | assets.cpp: 6 | assets/no-image.png: 7 | name: asset_no_image 8 | 9 | -------------------------------------------------------------------------------- /metadata.yml: -------------------------------------------------------------------------------- 1 | title: game title 2 | description: game description 3 | author: you 4 | splash: 5 | file: assets/no-image.png 6 | icon: 7 | file: assets/no-icon.png 8 | version: v0.0.1 9 | category: game # game, demo, utility, ... 10 | url: https://github.com/32blit/32blit-boilerplate 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Basic parameters; check that these match your project / environment 2 | cmake_minimum_required(VERSION 3.9) 3 | 4 | # Replace "game" with a name for your project (this is used the name of the output) 5 | project(game) 6 | 7 | # Add your sources here (adding headers is optional, but helps some CMake generators) 8 | set(PROJECT_SOURCE game.cpp game.hpp) 9 | 10 | # ... and any other files you want in the release here 11 | set(PROJECT_DISTRIBS LICENSE README.md) 12 | 13 | # Build configuration; approach this with caution! 14 | if(MSVC) 15 | add_compile_options("/W4" "/wd4244" "/wd4324" "/wd4458" "/wd4100") 16 | else() 17 | add_compile_options("-Wall" "-Wextra" "-Wdouble-promotion" "-Wno-unused-parameter") 18 | endif() 19 | 20 | find_package (32BLIT CONFIG REQUIRED PATHS ../32blit-sdk $ENV{PATH_32BLIT_SDK}) 21 | 22 | blit_executable (${PROJECT_NAME} ${PROJECT_SOURCE}) 23 | blit_assets_yaml (${PROJECT_NAME} assets.yml) 24 | blit_metadata (${PROJECT_NAME} metadata.yml) 25 | add_custom_target (flash DEPENDS ${PROJECT_NAME}.flash) 26 | 27 | # setup release packages 28 | install (FILES ${PROJECT_DISTRIBS} DESTINATION .) 29 | set (CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF) 30 | set (CPACK_GENERATOR "ZIP" "TGZ") 31 | include (CPack) 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 32Blit Boilerplate 2 | 3 | ![Build](https://github.com/32blit/32blit-boilerplate/workflows/Build/badge.svg) 4 | 5 | This is a basic template for starting 32blit projects. It shows the basic 6 | code layout and asset pipeline, hopefully giving folk a starting point for 7 | any new projects. 8 | 9 | It's based on the original `template` project from the 10 | [32Blit SDK](https://github.com/32blit/32blit-sdk), with added asset 11 | handling, and some tidying up to fit in with how I do things. 12 | 13 | ## Usage 14 | 15 | [Use this template](https://github.com/32blit/32blit-boilerplate/generate) to 16 | generate your own project. 17 | 18 | * Edit the CMakeList.txt file to set the name of your project 19 | * Edit the metadata.yml file to set the information for your project 20 | * Edit the LICENSE file to set your name on the license 21 | * Write lots of super cool code! 22 | 23 | You should then be able to follow the usual build instructions. 24 | 25 | For local builds this is: 26 | ``` 27 | mkdir build 28 | cd build 29 | cmake -D32BLIT_DIR=/path/to/32blit-sdk/ .. 30 | ``` 31 | 32 | Platform/Editor specific insctuctions [can be found in the main 32blit repo](https://github.com/32blit/32blit-sdk#you-will-need) 33 | (For Visual Studio, you should follow the "Option 2" instructions, as the boilerplate does not contain a solution file) 34 | -------------------------------------------------------------------------------- /game.cpp: -------------------------------------------------------------------------------- 1 | #include "game.hpp" 2 | 3 | using namespace blit; 4 | 5 | /////////////////////////////////////////////////////////////////////////// 6 | // 7 | // init() 8 | // 9 | // setup your game here 10 | // 11 | void init() { 12 | set_screen_mode(ScreenMode::hires); 13 | } 14 | 15 | /////////////////////////////////////////////////////////////////////////// 16 | // 17 | // render(time) 18 | // 19 | // This function is called to perform rendering of the game. time is the 20 | // amount if milliseconds elapsed since the start of your game 21 | // 22 | void render(uint32_t time) { 23 | 24 | // clear the screen -- screen is a reference to the frame buffer and can be used to draw all things with the 32blit 25 | screen.clear(); 26 | 27 | // draw some text at the top of the screen 28 | screen.alpha = 255; 29 | screen.mask = nullptr; 30 | screen.pen = Pen(255, 255, 255); 31 | screen.rectangle(Rect(0, 0, 320, 14)); 32 | screen.pen = Pen(0, 0, 0); 33 | screen.text("Hello 32blit!", minimal_font, Point(5, 4)); 34 | } 35 | 36 | /////////////////////////////////////////////////////////////////////////// 37 | // 38 | // update(time) 39 | // 40 | // This is called to update your game state. time is the 41 | // amount if milliseconds elapsed since the start of your game 42 | // 43 | void update(uint32_t time) { 44 | } -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # Build Github Action, to run a test build on all targets 2 | # (Linux, Blit, MacOS, Visual Studio) when the project is checked in. 3 | # 4 | # Thanks in large part to the phenomenal examples of DaftFreak. 5 | 6 | name: Build 7 | 8 | on: 9 | push: 10 | branches: 11 | - '**' # only run on branches 12 | pull_request: 13 | release: 14 | types: [published] 15 | 16 | env: 17 | BUILD_TYPE: Release 18 | EM_VERSION: 2.0.18 # Emscripten version 19 | EM_CACHE_FOLDER: 'emsdk-cache' # Cache for Emscripten libs 20 | 21 | jobs: 22 | 23 | build: 24 | 25 | name: ${{matrix.name}} 26 | strategy: 27 | matrix: 28 | include: 29 | - os: ubuntu-22.04 30 | name: Linux 31 | release-suffix: LIN64 32 | cmake-args: -D32BLIT_DIR=$GITHUB_WORKSPACE/32blit-sdk 33 | apt-packages: libsdl2-dev libsdl2-image-dev libsdl2-net-dev python3-setuptools 34 | 35 | - os: ubuntu-22.04 36 | name: STM32 37 | release-suffix: STM32 38 | cmake-args: -DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/32blit-sdk/32blit.toolchain 39 | apt-packages: gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib python3-setuptools 40 | 41 | - os: ubuntu-22.04 42 | name: Emscripten 43 | release-suffix: WEB 44 | cmake-args: -D32BLIT_DIR=$GITHUB_WORKSPACE/32blit-sdk 45 | cmake-prefix: emcmake 46 | apt-packages: python3-setuptools 47 | 48 | - os: macos-latest 49 | name: macOS 50 | release-suffix: MACOS 51 | cmake-args: -D32BLIT_DIR=$GITHUB_WORKSPACE/32blit-sdk 52 | brew-packages: sdl2 sdl2_image sdl2_net pipx 53 | 54 | - os: windows-latest 55 | name: Visual Studio 56 | release-suffix: WIN64 57 | cmake-args: -D32BLIT_DIR=$GITHUB_WORKSPACE/32blit-sdk 58 | 59 | runs-on: ${{matrix.os}} 60 | 61 | env: 62 | RELEASE_FILE: ${{github.event.repository.name}}-${{github.event.release.tag_name}}-${{matrix.release-suffix}} 63 | 64 | steps: 65 | # Check out the main repo 66 | - name: Checkout 67 | uses: actions/checkout@v4 68 | with: 69 | path: main 70 | 71 | # Check out the 32Blit API we build against 72 | - name: Checkout 32Blit API 73 | uses: actions/checkout@v4 74 | with: 75 | repository: 32blit/32blit-sdk 76 | path: 32blit-sdk 77 | 78 | # Linux dependencies 79 | - name: Install Linux deps 80 | if: runner.os == 'Linux' 81 | run: | 82 | sudo apt update && sudo apt install ${{matrix.apt-packages}} 83 | pip3 install 32blit 84 | 85 | # MacOS dependencies 86 | - name: Install macOS deps 87 | if: runner.os == 'macOS' 88 | run: | 89 | brew install ${{matrix.brew-packages}} 90 | pipx install 32blit 91 | 92 | # Windows dependencies 93 | - name: Install Windows deps 94 | if: runner.os == 'Windows' 95 | shell: bash 96 | run: | 97 | python -m pip install 32blit 98 | 99 | # Emscripten SDK setup 100 | - name: Setup Emscripten cache 101 | if: matrix.name == 'Emscripten' 102 | id: cache-system-libraries 103 | uses: actions/cache@v3 104 | with: 105 | path: ${{env.EM_CACHE_FOLDER}} 106 | key: ${{env.EM_VERSION}}-${{runner.os}} 107 | 108 | - name: Setup Emscripten 109 | if: matrix.name == 'Emscripten' 110 | uses: mymindstorm/setup-emsdk@v14 111 | with: 112 | version: ${{env.EM_VERSION}} 113 | actions-cache-folder: ${{env.EM_CACHE_FOLDER}} 114 | 115 | - name: Pre-build Emscripten ports 116 | if: matrix.name == 'Emscripten' 117 | run: embuilder.py build sdl2 sdl2-image-jpg sdl2-net 118 | 119 | # Set up the cmake build environment 120 | - name: Create Build Environment 121 | run: cmake -E make_directory ${{runner.workspace}}/main/build 122 | 123 | # Ask cmake to build the makefiles 124 | - name: Configure CMake 125 | shell: bash 126 | working-directory: ${{runner.workspace}}/main/build 127 | run: ${{matrix.cmake-prefix}} cmake $GITHUB_WORKSPACE/main -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCPACK_PACKAGE_FILE_NAME=${{env.RELEASE_FILE}} ${{matrix.cmake-args}} 128 | 129 | # And then run the build itself 130 | - name: Build 131 | working-directory: ${{runner.workspace}}/main/build 132 | shell: bash 133 | run: | 134 | cmake --build . --config $BUILD_TYPE -j 2 135 | 136 | # When it's a release, generate tar/zip files of the build 137 | - name: Package Release 138 | if: github.event_name == 'release' && matrix.release-suffix != '' 139 | shell: bash 140 | working-directory: ${{runner.workspace}}/main/build 141 | run: | 142 | cmake --build . --config $BUILD_TYPE --target package 143 | 144 | # Push the tar file to the release 145 | - name: Upload tar 146 | if: github.event_name == 'release' && matrix.release-suffix != '' 147 | uses: softprops/action-gh-release@v1 148 | with: 149 | files: ${{runner.workspace}}/main/build/${{env.RELEASE_FILE}}.tar.gz 150 | 151 | # Push the zip file to the release 152 | - name: Upload zip 153 | if: github.event_name == 'release' && matrix.release-suffix != '' 154 | uses: softprops/action-gh-release@v1 155 | with: 156 | files: ${{runner.workspace}}/main/build/${{env.RELEASE_FILE}}.zip 157 | --------------------------------------------------------------------------------