### Simple Setup Template Source: https://github.com/alemart/opensurge/wiki/setup-scripts A minimal boilerplate for creating a new setup object. ```text // // Setup script // using SurgeEngine.Lang; using SurgeEngine.Level; using SurgeEngine.Player; using SurgeEngine.Vector2; using SurgeEngine.Audio.Music; using SurgeEngine.Audio.Sound; using SurgeEngine.Events.EventList; using SurgeEngine.Events.EventChain; using SurgeEngine.Events.EntityEvent; using SurgeEngine.Events.DelayedEvent; using SurgeEngine.Events.FunctionEvent; object "Simple Setup" { // // This is the configuration area. // You'll configure your entities here. // config = { // // all zones / acts // "*": { // configuring the Elevators "Elevator": { "anim": 2 } }, // // zone 1 only // "1": { // give the player 50 collectibles when pressing any Switch "Switch": { "onActivate": FunctionEvent("Give Lucky Bonus").withArgument(50) } }, // // zone 2 only // "2": { }, // // zone 3 only // "3": { } }; // ------------------------------------------------------------------------- // // Below you'll find the setup code. // You should keep it as it is in most cases. // state "main" { } // setup the entities fun constructor() { zone = String(Level.act); Level.setup(config["*"] || { }); Level.setup(config[zone] || { }); } } ``` -------------------------------- ### Configure Level Setup in .lev File Source: https://github.com/alemart/opensurge/wiki/setup-scripts Associate a custom setup object with a level by updating the setup field in the .lev file. ```text setup "Default Setup" "Example Setup" ``` -------------------------------- ### Event Configuration Examples Source: https://github.com/alemart/opensurge/wiki/setup-scripts Examples of defining event chains and lists for triggers, boss fights, and entity interactions. ```text FunctionEvent("Print").withArgument("Second time you pressed it"), FunctionEvent("Print").withArgument("Third time you pressed it"), FunctionEvent("Print").withArgument("Don't you get tired?"), FunctionEvent("Print").withArgument("Enough!") ]) }, // Example: trigger alternating events. Raise the water // level and then restore it back to its original level, // again and again, whenever the blue Switch is pressed. "ab5264eabc2564cc": { "color": "blue", "sticky": false, "onActivate": EventChain([ FunctionEvent("Change Water Level").withArgument(128), FunctionEvent("Change Water Level").withArgument(Level.waterlevel) ]).willLoop() } }, // // zone 3 only // "3": { // Example: start a boss fight! "Event Trigger 4": { "onTrigger": EventList([ FunctionEvent("Play Boss Music"), FunctionEvent("Lock Camera").withArgument(800) // lock camera with a space of 800 pixels to the right ]) }, // Example: extend the locked region after a boss fight. // "My Boss" is a hypothetical entity that triggers onDefeat. "My Boss": { "onDefeat": EventList([ FunctionEvent("Stop Boss Music"), FunctionEvent("Lock Camera").withArgument(512) // give more 512 pixels of space ]) }, // Example: unlock the camera after a mini-boss fight, // so the player can keep moving throughout the level. "My Mini Boss": { "onDefeat": EventList([ FunctionEvent("Stop Boss Music"), FunctionEvent("Unlock Camera") ]) }, // Example: when touching Event Trigger 3, give the player // a bonus of 50 collectibles to prepare for the boss fight! "Event Trigger 3": { "onTrigger": FunctionEvent("Give Lucky Bonus").withArgument(50) } } }; // ------------------------------------------------------------------------- // // Below you'll find the setup code. // You should keep it as it is in most cases. // state "main" { } // setup the entities fun constructor() { zone = String(Level.act); Level.setup(config["*"] || { }); Level.setup(config[zone] || { }); } ``` -------------------------------- ### Define Setup Objects Source: https://github.com/alemart/opensurge/wiki/level-specification Configures the objects created upon level load, typically including the Default Setup for HUD and camera management. ```text setup "Default Setup" ``` ```text setup "Default Setup" "Example Setup" ``` -------------------------------- ### Configure UNIX Installation Paths Source: https://github.com/alemart/opensurge/blob/master/CMakeLists.txt Sets platform-specific installation directories for binaries and data on UNIX systems. ```cmake if(UNIX) set(GAME_BINDIR "games" CACHE PATH "Installation directory of the executable. It will be appended to CMAKE_INSTALL_PREFIX if it's a relative path") set(GAME_DATADIR "share/games/${GAME_UNIXNAME}" CACHE PATH "Installation directory of the game data. It will be appended to CMAKE_INSTALL_PREFIX if it's a relative path") set(GAME_USERDIRNAME "${GAME_UNIXNAME}" CACHE PATH "Name of the user-modifiable asset directory") endif() ``` -------------------------------- ### Install Assets and Desktop Metadata Source: https://github.com/alemart/opensurge/blob/master/CMakeLists.txt Configures the installation of game assets and freedesktop.org metadata files to system directories. ```cmake # Assets install(FILES ${ASSET_FILES} DESTINATION "${GAME_DATADIR}") install(DIRECTORY ${ASSET_FOLDERS} DESTINATION "${GAME_DATADIR}" PATTERN ".git" EXCLUDE) # AppStream / freedesktop.org if(DEFINED DESKTOP_ENTRY_PATH) install(FILES src/misc/opensurge.png DESTINATION "${DESKTOP_ICON_PATH}") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/src/misc/opensurge.appdata.xml" DESTINATION "${DESKTOP_METAINFO_PATH}") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/src/misc/opensurge.desktop" DESTINATION "${DESKTOP_ENTRY_PATH}") endif() ``` -------------------------------- ### Install Portable Executable and Assets Source: https://github.com/alemart/opensurge/blob/master/CMakeLists.txt Defines installation rules for a portable build, placing the executable and assets into a single distribution directory. ```cmake elseif(GAME_RUNINPLACE) # Portable executable & assets install(TARGETS "${GAME_UNIXNAME}" RUNTIME DESTINATION "${GAME_DISTDIR}") install(FILES ${ASSET_FILES} DESTINATION "${GAME_DISTDIR}") install( DIRECTORY ${ASSET_FOLDERS} screenshots DESTINATION "${GAME_DISTDIR}" PATTERN ".git" EXCLUDE PATTERN "screenshots/*.png" EXCLUDE ) endif() ``` -------------------------------- ### Import and launch for repository-installed engine Source: https://github.com/alemart/opensurge/wiki/upgrading-the-engine Commands to run the import wizard and launch the engine for standard repository installations. ```sh OPENSURGE_USER_PATH="$HOME/path/to/the/source_release/I_just_downloaded" opensurge --import-wizard ``` ```sh opensurge --game-folder "$HOME/path/to/the/source_release/I_just_downloaded" ``` -------------------------------- ### Install Game Target Source: https://github.com/alemart/opensurge/blob/master/CMakeLists.txt Defines installation rules for the game executable on Unix systems when not running in-place. ```cmake install(TARGETS "${GAME_UNIXNAME}" RUNTIME DESTINATION "${GAME_BINDIR}" LIBRARY DESTINATION "${GAME_BINDIR}" ) ``` -------------------------------- ### Install cross-compiler dependencies Source: https://github.com/alemart/opensurge/wiki/compiling-the-source-code Install the necessary build tools on a Debian-based system. ```sh sudo apt-get install mingw-w64 cmake ``` -------------------------------- ### Configure Desktop Integration Paths Source: https://github.com/alemart/opensurge/blob/master/CMakeLists.txt Sets installation paths for desktop entry, icon, and metainfo files on non-Android UNIX systems. ```cmake if(UNIX AND NOT ANDROID) set(DESKTOP_ENTRY_PATH "/usr/share/applications" CACHE PATH "Installation directory of the .desktop file") set(DESKTOP_ICON_PATH "/usr/share/icons/hicolor/256x256/apps" CACHE PATH "Installation directory of the icon file") set(DESKTOP_METAINFO_PATH "/usr/share/metainfo" CACHE PATH "Installation directory of the metainfo file. You shouldn't change this (check the AppStream specfication)") endif() ``` -------------------------------- ### Define brick behavior Source: https://github.com/alemart/opensurge/wiki/bricksets Examples of setting basic brick properties and a full definition for a static brick. ```text // a regular brick type SOLID behavior DEFAULT ``` ```text // This is just an example brick 154 { type SOLID behavior DEFAULT zindex 0.5 mask "images/waterworks_mask.png" sprite { source_file "images/waterworks.png" source_rect 512 768 32 32 frame_size 32 32 animation { repeat TRUE fps 8 data 0 } } } ``` -------------------------------- ### Check Open Surge version Source: https://github.com/alemart/opensurge/wiki/upgrading-the-engine Verify the installed engine version via terminal. ```sh flatpak run org.opensurge2d.OpenSurge --version ``` ```sh opensurge --version ``` -------------------------------- ### Compile libjpeg-turbo and libjpeg Source: https://github.com/alemart/opensurge/wiki/compiling-the-source-code Commands to install nasm and compile either libjpeg-turbo or standard libjpeg. ```sh sudo apt-get install nasm ``` ```sh wget https://github.com/libjpeg-turbo/libjpeg-turbo/releases/download/3.1.2/libjpeg-turbo-3.1.2.tar.gz tar xvzf libjpeg-turbo-3.1.2.tar.gz && cd libjpeg-turbo-3.1.2 mkdir build && cd build cmake .. -DCMAKE_INSTALL_PREFIX=$ALLEGRO_DEPS_FOLDER \   -DCMAKE_TOOLCHAIN_FILE=$ALLEGRO_DEPS_FOLDER/toolchain-mingw.cmake \   -DENABLE_SHARED=off -DENABLE_STATIC=on make make install cd ../.. ``` ```sh wget https://www.ijg.org/files/jpegsrc.v9e.tar.gz tar xvzf jpegsrc.v9e.tar.gz && cd jpeg-9e ./configure --host=$TOOLSET --target=$TOOLSET --prefix=$ALLEGRO_DEPS_FOLDER --disable-shared --enable-static make make install cd .. ``` -------------------------------- ### SurgeScript Setup Script Template Source: https://github.com/alemart/opensurge/wiki/setup-scripts A standard template for defining level entities and properties. Ensure the object name is unique and syntax is preserved. ```surgescript // ----------------------------------------------------------------------------- // File: example_setup.ss // Description: example setup script // Author: Alexandre Martins // License: MIT // ----------------------------------------------------------------------------- using SurgeEngine.Lang; using SurgeEngine.Level; using SurgeEngine.Player; using SurgeEngine.Vector2; using SurgeEngine.Audio.Music; using SurgeEngine.Audio.Sound; using SurgeEngine.Events.EventList; using SurgeEngine.Events.EventChain; using SurgeEngine.Events.EntityEvent; using SurgeEngine.Events.DelayedEvent; using SurgeEngine.Events.FunctionEvent; /* SETUP SCRIPT The setup script is used to set up entities and data in a level. Below you'll find a configuration object partitioned into zones. Each zone is likely to contain multiple entities. Entities have a name (like "Bridge", "Elevator", and so on) and an ID (a hex code like "2bbc752e0454d031"). While multiple entities may have the same name (e.g., there may be multiple bridges on a level), each entity is uniquely identified by its ID. Entities may be referenced in the configuration object using their names or their unique IDs. Once you reference an entity, you may change its properties following the template below. The exact properties of an entity can be found by inspecting ``` -------------------------------- ### Configure Level Entities and Events Source: https://github.com/alemart/opensurge/wiki/setup-scripts Define entity behaviors, triggers, and event sequences within the setup object configuration block. ```javascript object "Example Setup" { // // This is the configuration area. // You'll configure your entities here. // config = { // // all zones / acts // "*": { // the configuration below is just an example // (modify at will, but backup this file first!) // Example: configuring all Bridges. Setting their // length and their animation number. "Bridge": { "length": 12, // length 12 is the default "anim": 1 // animation number (the sprite is "Bridge") }, // Example: configuring all Elevators. "Elevator": { "anim": 2 // animation number } }, // // zone 1 only // "1": { // Example: configuring the Background Exchanger for zone 1. "Background Exchanger": { "background": "themes/template.bg" }, // Example: making a specific Door become red. // (suppose its ID is 532ab77cef1252ae) "532ab77cef1252ae": { "color": "red" }, // Example: configuring an event. An event is something that // may be triggered during gameplay. This will print a message // as soon as the player touches an Event Trigger 1 entity. "Event Trigger 1": { "onTrigger": FunctionEvent("Print").withArgument("Hello! Give me pizza!") }, // Example: lock the camera as soon as the player touches an // Event Trigger 4 entity, ideally placed near the goal flag. "Event Trigger 4": { "onTrigger": FunctionEvent("Lock Camera").withArgument(2048) // give a maximum space of 2048 pixels to the right }, // Example: collapse a specific Bridge (ID: 481c9ccb42a38268) // when activating a specific Switch (ID: 142f0aa6855b991a). "142f0aa6855b991a": { "onActivate": EntityEvent("481c9ccb42a38268").willCall("collapse") }, // Example: open a specific Door (ID: 2bbc752e0454d031) ONLY IF // a specific red Switch (ID: 66b9b90da2a5a5fa) is being pressed. "66b9b90da2a5a5fa": { "color": "red", "sticky": false, "onActivate": EntityEvent("2bbc752e0454d031").willCall("open"), "onDeactivate": EntityEvent("2bbc752e0454d031").willCall("close") } }, // // zone 2 only // "2": { // Example: make all Switches blue. // Make them trigger multiple events at the same time! "Switch": { "color": "blue", "onActivate": EventList([ FunctionEvent("Print").withArgument("Oh my! Look at the water!"), FunctionEvent("Change Water Level").withArgument(128) // raise water to ypos = 128 ]) }, // Example: tell a story. Trigger one event at a time! "Event Trigger 2": { "onTrigger": EventList([ FunctionEvent("Print").withArgument("Oh my! Something is about to happen!"), DelayedEvent( FunctionEvent("Print").withArgument("I can feel... water...") ).willWait(3.0), // wait 3 seconds before triggering this DelayedEvent( FunctionEvent("Print").withArgument("WATCH OUT!") ).willWait(6.0), // wait 6 seconds before triggering this DelayedEvent( FunctionEvent("Change Water Level").withArgument(128) ).willWait(7.0) // wait 7 seconds before triggering this ]) }, // Example: trigger different events when pressing a // Switch multiple times. The events will be triggered // sequentially, like the links of a chain. "e58aecd5740a0547": { "sticky": false, "onActivate": EventChain([ FunctionEvent("Print").withArgument("First time you pressed it"), ``` -------------------------------- ### Set Game Distribution Directory Source: https://github.com/alemart/opensurge/blob/master/CMakeLists.txt Configures the base installation directory for running the game in place. ```cmake set(GAME_DISTDIR "." CACHE PATH "Installation directory of the game, relative to the build folder, when running in place") ``` -------------------------------- ### Compile SurgeScript Source: https://github.com/alemart/opensurge/wiki/compiling-the-source-code Builds SurgeScript using CMake with a MinGW toolchain file and installs the resulting binaries. ```sh # extract the sources to surgescript/ pushd surgescript mkdir -p build && cd build cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain-mingw.cmake -DWANT_SHARED=OFF -DWANT_STATIC=ON -DWANT_EXECUTABLE=OFF make sudo make install popd ``` -------------------------------- ### Compile libogg and libvorbis Source: https://github.com/alemart/opensurge/wiki/compiling-the-source-code Compiles Ogg and Vorbis libraries, ensuring Vorbis links against the Ogg installation. ```sh wget http://downloads.xiph.org/releases/ogg/libogg-1.3.6.tar.gz tar xvzf libogg-1.3.6.tar.gz && cd libogg-1.3.6 # sed -e s/"-mno-ieee-fp"/""/g -i ./configure # skip this (clang only, x86) ./configure --host=$TOOLSET --target=$TOOLSET --prefix=$ALLEGRO_DEPS_FOLDER --disable-shared --enable-static make make install cd .. ``` ```sh wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.7.tar.gz tar xvzf libvorbis-1.3.7.tar.gz && cd libvorbis-1.3.7 # sed -e s/"-mno-ieee-fp"/""/g -i ./configure # skip this (clang only, x86) ./configure --host=$TOOLSET --target=$TOOLSET --prefix=$ALLEGRO_DEPS_FOLDER --disable-shared --enable-static \   --with-ogg=$ALLEGRO_DEPS_FOLDER --with-ogg-libraries=$ALLEGRO_DEPS_FOLDER/lib \   --with-ogg-includes=$ALLEGRO_DEPS_FOLDER/include make make install cd .. ``` -------------------------------- ### Language File Metadata Structure Source: https://github.com/alemart/opensurge/wiki/translation-guide Example of the metadata section in an Open Surge language file, showing key/value pairs for language identification and compatibility. ```text // ... // Translation metadata LANG_ID "en_US" // language code & country according to ISO 639-1 & ISO 3166-1, respectively LANG_NAM "English" // language name LANG_AUTHOR "Alexandre Martins" // translation author LANG_COMPATIBILITY "0.5.0" // required engine version // ... ``` ```text // ... // Translation metadata LANG_ID "pt_BR" // language code & country according to ISO 639-1 & ISO 3166-1, respectively LANG_NAME "Português (Brasil)" // language name LANG_AUTHOR "Alexandre Martins" // translation author LANG_COMPATIBILITY "0.5.0" // required engine version // ... ``` -------------------------------- ### Modify Level Editor Key Bindings Source: https://github.com/alemart/opensurge/wiki/user-input Example configuration for the editorcmd input map, showing how to rebind the level editor key from F12 to F6. ```text // level editor inputmap "editorcmd1" {     keyboard     {         up              KEY_UP            right           KEY_RIGHT         down            KEY_DOWN         left            KEY_LEFT             fire1           KEY_LCONTROL         fire2           KEY_RCONTROL         fire3           KEY_LSHIFT         fire4           KEY_RSHIFT         fire5           KEY_S          fire6           KEY_R           fire7           KEY_F1          fire8           KEY_F12 // <-- modify this to KEY_F6     } } ``` -------------------------------- ### Define a custom Collectible sprite Source: https://github.com/alemart/opensurge/wiki/sprites Example configuration for a custom sprite definition, including source file path, frame dimensions, and animation sequences. ```text // Collectible sprite "Collectible" {    source_file     "images/my_collectibles.png"    source_rect     1 1 176 16    frame_size      16 16    hot_spot        8 12        // idle    animation 0    {        repeat      TRUE        fps         16        data        0 1 2 3 4 5 2 6    }        // end    animation 1    {        repeat      FALSE        fps         8        data        7 8 9 10    } } ``` -------------------------------- ### Run OpenSurge Help Source: https://github.com/alemart/opensurge/blob/master/README.md Displays the command-line help menu for the OpenSurge executable. ```bash opensurge --help ``` -------------------------------- ### Create dependencies directory Source: https://github.com/alemart/opensurge/wiki/compiling-the-source-code Prepare the folder for storing compiled dependencies. ```sh mkdir -p $ALLEGRO_DEPS_FOLDER cd $ALLEGRO_DEPS_FOLDER ``` -------------------------------- ### Define a group structure Source: https://github.com/alemart/opensurge/wiki/groups Example of a group definition containing multiple bricks. ```text group { brick 49 16 16 brick 50 0 16 brick 0 0 0 brick 50 32 16 brick 49 48 16 brick 0 32 0 brick 50 64 16 brick 49 80 16 brick 0 64 0 brick 50 96 16 brick 49 112 16 brick 0 96 0 brick 50 128 16 brick 49 144 16 brick 0 128 0 } ``` -------------------------------- ### Import and launch project via Flatpak Source: https://github.com/alemart/opensurge/wiki/upgrading-the-engine Commands to import a game project and launch the engine within the sandboxed Flatpak environment. ```sh OPENSURGE_USER_PATH="$HOME/.local/share/opensurge/path_to_the_newer_release" flatpak run org.opensurge2d.OpenSurge --import "$HOME/Downloads/path_to_your_game" ``` ```sh mv "$HOME/.local/share/opensurge/path_to_the_newer_release" "$HOME/Downloads/path_to_the_newer_release" ``` ```sh flatpak run org.opensurge2d.OpenSurge --game-folder "$HOME/Downloads/path_to_the_newer_release" ``` -------------------------------- ### Load a quest via command line Source: https://github.com/alemart/opensurge/wiki/quests Use the --quest flag to specify a custom quest file path when launching the engine. ```bash opensurge --quest quests/my_quest.qst ``` -------------------------------- ### Run Import Wizard for source-compiled engine Source: https://github.com/alemart/opensurge/wiki/upgrading-the-engine Launch the import wizard for engines compiled with the GAME_RUNINPLACE flag. ```sh cd ~/path/to/opensurge/ ./opensurge --import-wizard ``` -------------------------------- ### Download and extract Allegro 5 Source: https://github.com/alemart/opensurge/wiki/compiling-the-source-code Fetch the Allegro 5 source code and prepare the directory structure. ```sh wget https://github.com/liballeg/allegro5/releases/download/5.2.11.1/allegro-5.2.11.1.tar.gz tar xvzf allegro-5.2.11.1.tar.gz cd allegro-5.2.11.1 ``` -------------------------------- ### Initialize CMake Project Source: https://github.com/alemart/opensurge/blob/master/CMakeLists.txt Sets the minimum required CMake version and defines the project name and supported languages. ```cmake cmake_minimum_required(VERSION 3.20) project(opensurge LANGUAGES C CXX) ``` -------------------------------- ### Compile zlib Source: https://github.com/alemart/opensurge/wiki/compiling-the-source-code Download and compile zlib for the target environment. ```sh wget https://zlib.net/zlib-1.3.1.tar.gz tar xvzf zlib-1.3.1.tar.gz && cd zlib-1.3.1 # ./configure --prefix=$ALLEGRO_DEPS_FOLDER --static && make && make install # skip this (not win32) sed -e s/"PREFIX ="/"PREFIX = ${TOOLSET}-"/ -i win32/Makefile.gcc BINARY_PATH=${ALLEGRO_DEPS_FOLDER}/bin \ INCLUDE_PATH=${ALLEGRO_DEPS_FOLDER}/include \ LIBRARY_PATH=${ALLEGRO_DEPS_FOLDER}/lib \ make -f win32/Makefile.gcc install cd .. ``` -------------------------------- ### Define a collectible sprite in .spr format Source: https://github.com/alemart/opensurge/wiki/sprites Example of a sprite definition block including source file path, frame dimensions, and multiple animation sequences. ```text // ... // Collectible sprite "Collectible" {     source_file     "images/collectibles.png"     source_rect     0 0 304 16     frame_size      16 16     hot_spot        8 12     // spinning     animation 0     {         repeat      TRUE         fps         16         data        0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15     }     // disappearing     animation 1     {         repeat      FALSE         fps         8         data        16 17 18     } } // ... ``` -------------------------------- ### Configure Build Standards and Variables Source: https://github.com/alemart/opensurge/blob/master/CMakeLists.txt Sets the C standard and defines project-specific metadata variables. ```cmake set(CMAKE_C_STANDARD 99) set(GAME_UNIXNAME "opensurge") set(GAME_NAME "Open Surge Engine") ``` -------------------------------- ### Define Build Options and Preprocessor Definitions Source: https://github.com/alemart/opensurge/blob/master/CMakeLists.txt Configures project-wide build settings using CMake options and conditionally appends preprocessor definitions to the DEFS list. ```cmake option(ALLEGRO_MONOLITH "Use the monolith version of Allegro" OFF) option(SURGESCRIPT_STATIC "Link SurgeScript statically" OFF) # Link Allegro statically option(ALLEGRO_STATIC "Link Allegro statically (Windows only)" OFF) if(ALLEGRO_STATIC) list(APPEND DEFS "ALLEGRO_STATICLINK=1") endif() # Run in place? option(GAME_RUNINPLACE "Read assets only from the directory of the executable" OFF) if(GAME_RUNINPLACE) list(APPEND DEFS "GAME_RUNINPLACE=1") endif() # Set the build type & version - this helps identify the platform and the development builds set(GAME_BUILD_VERSION "" CACHE STRING "Build type & version (optional)") if(NOT GAME_BUILD_VERSION STREQUAL "") list(APPEND DEFS "GAME_BUILD_VERSION=\"${GAME_BUILD_VERSION}\"") endif() # Set the build date option(WANT_BUILD_DATE "Include the build date in the binary (disable for reproducible builds)" ON) if(WANT_BUILD_DATE) list(APPEND DEFS "GAME_BUILD_DATE=__DATE__") endif() # Play a MOD (options screen) option(WANT_PLAYMOD "Display the MOD loader in the options screen" ON) if(WANT_PLAYMOD) list(APPEND DEFS "WANT_PLAYMOD=1") endif() # OpenGL ES option(WANT_GLES "Use OpenGL ES (Android and X11)" OFF) if(WANT_GLES) list(APPEND DEFS "WANT_GLES=1") endif() # FastDraw option(WANT_FASTDRAW "Use the FastDraw mini-library" ON) if(WANT_FASTDRAW) list(APPEND DEFS "WANT_FASTDRAW=1") endif() # Improved Gamepad support option(WANT_BETTER_GAMEPAD "Autodetect gamepad layouts for consistent cross-platform behavior" ON) if(WANT_BETTER_GAMEPAD) list(APPEND DEFS "WANT_BETTER_GAMEPAD=1") endif() ``` -------------------------------- ### Configure Level Aesthetics Source: https://github.com/alemart/opensurge/wiki/level-specification Sets the brickset, background theme, and background music for the level. ```text theme "themes/template.brk" ``` ```text bgtheme "themes/template.bg" ``` ```text music "musics/title.ogg" ``` -------------------------------- ### Compile Allegro 5 Source: https://github.com/alemart/opensurge/wiki/compiling-the-source-code Configures and builds the static monolith version of Allegro 5. ```sh mkdir -p $ALLEGRO_BUILD_FOLDER cd $ALLEGRO_BUILD_FOLDER cmake .. -DCMAKE_TOOLCHAIN_FILE="$ALLEGRO_FOLDER/cmake/Toolchain-mingw.cmake" -DCMAKE_BUILD_TYPE=Release \   -DWANT_MONOLITH=on -DSHARED=off -DPREFER_STATIC_DEPS=on -DWANT_DOCS=off \   -DWANT_EXAMPLES=on -DWANT_DEMO=on -DWANT_TESTS=off -DWANT_MP3=off \   -DWANT_STATIC_RUNTIME=on -DCMAKE_VERBOSE_MAKEFILE=on # Cross fingers and pray. make -j`nproc` sudo make install ``` ```sh cd $ALLEGRO_FOLDER/.. ``` -------------------------------- ### Compile libpng Source: https://github.com/alemart/opensurge/wiki/compiling-the-source-code Downloads and compiles libpng as a static library. ```sh wget https://download.sourceforge.net/libpng/libpng-1.6.53.tar.gz tar xvzf libpng-1.6.53.tar.gz && cd libpng-1.6.53 ./configure --host=$TOOLSET --target=$TOOLSET --prefix=$ALLEGRO_DEPS_FOLDER --disable-shared --enable-static make make install cd .. ``` -------------------------------- ### Define a basic level configuration Source: https://github.com/alemart/opensurge/wiki/how-to-make-a-level The .lev file format uses a plain text structure to define level metadata, themes, and initial spawn points. ```text // ... // header name "Empty Level" author "YOUR_NAME_HERE" license "CC-BY 3.0" version "1.0" requires "0.5.0" act 1 theme "themes/waterworks.brk" bgtheme "themes/template.bg" spawn_point 128 9920 music "musics/template.ogg" setup "Default Setup" players "Surge" "Neon" // ... ``` -------------------------------- ### Set Allegro build environment variables Source: https://github.com/alemart/opensurge/wiki/compiling-the-source-code Configure paths for Allegro dependencies and build folders. ```sh export ALLEGRO_FOLDER="$(pwd)" export ALLEGRO_BUILD_FOLDER="$ALLEGRO_FOLDER/build" export ALLEGRO_DEPS_FOLDER="$ALLEGRO_FOLDER/deps" export LDFLAGS="-L$ALLEGRO_DEPS_FOLDER/lib" export CFLAGS="-I$ALLEGRO_DEPS_FOLDER/include" export CPPFLAGS="-I$ALLEGRO_DEPS_FOLDER/include" ``` -------------------------------- ### Include Utilities and Read Versioning Source: https://github.com/alemart/opensurge/blob/master/CMakeLists.txt Includes custom utility scripts and extracts versioning information for the build output. ```cmake include(utils) read_game_version(GAME_VERSION_STRING GAME_VERSION_MAJOR GAME_VERSION_MINOR GAME_VERSION_PATCH GAME_VERSION_BUILD) read_game_years(GAME_YEARS) message("${GAME_NAME} version ${GAME_VERSION_STRING}") ``` -------------------------------- ### Configure FLOAT behavior Source: https://github.com/alemart/opensurge/wiki/bricksets Defines a platform that dips when stepped on. ```text // syntax: behavior FLOAT [modifier] type SOLID behavior FLOAT ``` -------------------------------- ### Create CMake toolchain file Source: https://github.com/alemart/opensurge/wiki/compiling-the-source-code Generate a CMake configuration file for the MinGW cross-compiler. ```sh cat > toolchain-mingw.cmake << EOF set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_PROCESSOR X86) set(CMAKE_C_COMPILER ${TOOLSET}-gcc) set(CMAKE_CXX_COMPILER ${TOOLSET}-g++) set(CMAKE_RC_COMPILER ${TOOLSET}-windres) set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN}) set(CMAKE_AR:FILEPATH `which ${TOOLSET}-ar`) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) EOF ``` -------------------------------- ### Locate SurgeScript and PhysicsFS Dependencies Source: https://github.com/alemart/opensurge/blob/master/CMakeLists.txt Uses find_path and find_library to locate headers and libraries for SurgeScript and PhysicsFS, terminating with a fatal error if not found. ```cmake find_path(SURGESCRIPT_INCDIR NAMES "surgescript.h" PATHS ${SURGESCRIPT_INCLUDE_PATH}) if(NOT SURGESCRIPT_INCDIR) message(FATAL_ERROR "Can't find surgescript.h! ${HELP}") else() message(STATUS "Found surgescript.h at ${SURGESCRIPT_INCDIR}") endif() find_library(LSURGESCRIPT NAMES "${SURGESCRIPT_LIB}" PATHS ${SURGESCRIPT_LIBRARY_PATH}) if(NOT LSURGESCRIPT) message(FATAL_ERROR "Can't find lib${SURGESCRIPT_LIB}! ${HELP}") else() message(STATUS "Found lib${SURGESCRIPT_LIB} at ${LSURGESCRIPT}...") endif() # PhysicsFS find_path(PHYSFS_INCDIR NAMES "physfs.h" PATHS ${PHYSFS_INCLUDE_PATH}) if(NOT PHYSFS_INCDIR) message(FATAL_ERROR "Can't find physfs.h! ${HELP}") else() message(STATUS "Found physfs.h at ${PHYSFS_INCDIR}") endif() find_library(LPHYSFS NAMES "physfs" PATHS ${PHYSFS_LIBRARY_PATH}) if(NOT LPHYSFS) message(FATAL_ERROR "Can't find libphysfs! ${HELP}") else() message(STATUS "Found libphysfs at ${LPHYSFS}...") endif() ``` -------------------------------- ### Compile Open Surge Source: https://github.com/alemart/opensurge/wiki/compiling-the-source-code Builds the Open Surge executable using CMake with specific toolchain and dependency paths. ```sh # extract the sources to opensurge/ pushd opensurge mkdir -p build && cd build cmake .. -DCMAKE_TOOLCHAIN_FILE=../src/misc/toolchain-mingw.cmake \   -DCMAKE_SYSROOT=$ALLEGRO_DEPS_FOLDER -DALLEGRO_STATIC=ON -DALLEGRO_MONOLITH=ON -DSURGESCRIPT_STATIC=ON make # sudo make install # the Linux build uses this popd ``` -------------------------------- ### Create legacy object Source: https://github.com/alemart/opensurge/wiki/level-specification Deprecated command to spawn a custom object by name at specific coordinates. ```text object "Basic Pipe System: Pipe Master" 831 2046 ``` -------------------------------- ### Configure Reproducible Builds Source: https://github.com/alemart/opensurge/blob/master/CMakeLists.txt Uses file-prefix-map to ensure relative paths in __FILE__ for non-MSVC compilers. ```cmake # Use relative paths in __FILE__ (reproducible builds) if(NOT MSVC) target_compile_options(${GAME_UNIXNAME} PUBLIC "-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.") endif() ``` -------------------------------- ### Configure cross-compiler environment variables Source: https://github.com/alemart/opensurge/wiki/compiling-the-source-code Set the toolset and toolchain path for the cross-compiler. ```sh # Name of the cross compiler # Usually one of the following: i686-w64-mingw32, i686-pc-mingw32, i386-mingw32 (32 bit) export TOOLSET=i686-w64-mingw32 # Location of the cross compiler # Usually in /usr (please check) - it should have subdirectories: bin/, include/, lib/ export TOOLCHAIN=/usr/$TOOLSET ``` -------------------------------- ### Compile OpenSurge Engine Source: https://github.com/alemart/opensurge/blob/master/README.md Standard build process for the OpenSurge engine using CMake and Make. ```bash cd /path/to/opensurge/ mkdir build && cd build cmake .. make -j`nproc` sudo make install ``` -------------------------------- ### Implement custom ability in SurgeScript Source: https://github.com/alemart/opensurge/wiki/characters Define a companion object in a .ss file to create custom character moves like the Super Peel Out dash. ```cs using SurgeEngine.Level; using SurgeEngine.Vector2; using SurgeEngine.Audio.Sound; // // This is a dash move that should be configured as a // companion object in a character definition file (.chr) // // When you are stopped, hold up and press jump to charge. // Release up after half a second and you'll gain a nice boost! // object "Super Peel Out" is "companion" { public anim = 2; // default animation: running speed = 720; // dash speed, in pixels/second charge = Sound("samples/charge.wav"); release = Sound("samples/release.wav"); player = parent; // since this object is configured as a // companion, parent is the reference // to the correct Player object // capture the event state "main" { if(player.lookingUp) { if(player.input.buttonPressed("fire1")) { charge.play(); state = "charging"; } } } // charging the dash state "charging" { // disable the dash? if(player.midair || player.hit || player.dying || player.winning) { state = "main"; return; } // change the animation player.restore(); // stop looking up player.anim = anim; // make the player stand still player.xsp = player.ysp = player.gsp = 0; player.input.simulateButton("right", false); player.input.simulateButton("left", false); player.input.simulateButton("down", false); // ready to go? if(player.input.buttonReleased("up")) { if(timeout(0.5)) { player.gsp = speed * player.direction; // dash!!! release.play(); spawnSmoke(); } state = "main"; } else if(player.input.buttonPressed("fire1")) charge.play(); } fun spawnSmoke() { Level.spawnEntity( "Speed Smoke", Vector2( player.collider.center.x - player.direction * 22, player.collider.bottom + 2 ) ).setDirection(player.direction); } } ``` -------------------------------- ### Compile OpenAL Soft Source: https://github.com/alemart/opensurge/wiki/compiling-the-source-code Cross-compiles OpenAL Soft for Windows. ```sh wget https://kcat.strangesoft.net/openal-releases/openal-soft-1.17.2.tar.bz2 tar xvjf openal-soft-1.17.2.tar.bz2 && pushd openal-soft-1.17.2/build cmake .. -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER=$(which $CC) -DCMAKE_CXX_COMPILER=$(which $CXX) \   -DCMAKE_FIND_ROOT_PATH=$TOOLCHAIN -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \   -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY -DCMAKE_INSTALL_PREFIX=$ALLEGRO_DEPS_FOLDER -DLIBTYPE=STATIC make make install popd ``` -------------------------------- ### Place Bricks Source: https://github.com/alemart/opensurge/wiki/level-specification Adds bricks to the level with optional layer and flip parameters. ```text brick 101 6917 1316 ``` ```text brick 101 6917 1316 green brick 221 7212 3281 yellow ``` ```text brick 101 6917 1316 hflip brick 101 6917 1316 green hflip ``` -------------------------------- ### Define Dependency Paths Source: https://github.com/alemart/opensurge/blob/master/CMakeLists.txt Sets cache variables for library and include paths for project dependencies. ```cmake set(ALLEGRO_LIBRARY_PATH "${CMAKE_LIBRARY_PATH}" CACHE PATH "Where to look for Allegro & its dependencies") set(ALLEGRO_INCLUDE_PATH "${CMAKE_INCLUDE_PATH}" CACHE PATH "Where to look for the header files of Allegro") set(SURGESCRIPT_LIBRARY_PATH "${CMAKE_LIBRARY_PATH}" CACHE PATH "Where to look for SurgeScript") set(SURGESCRIPT_INCLUDE_PATH "${CMAKE_INCLUDE_PATH}" CACHE PATH "Where to look for the header files of SurgeScript") set(PHYSFS_LIBRARY_PATH "${CMAKE_LIBRARY_PATH}" CACHE PATH "Where to look for PhysicsFS") set(PHYSFS_INCLUDE_PATH "${CMAKE_INCLUDE_PATH}" CACHE PATH "Where to look for the header files of PhysicsFS") ``` -------------------------------- ### Set Target Definitions and Properties Source: https://github.com/alemart/opensurge/blob/master/CMakeLists.txt Applies compile definitions and project-specific properties to the game target. ```cmake # Our #defines target_compile_definitions(${GAME_UNIXNAME} PUBLIC ${DEFS}) # Target properties set_target_properties(${GAME_UNIXNAME} PROPERTIES PROJECT_LABEL "${GAME_NAME}") if(GAME_RUNINPLACE) set_target_properties(${GAME_UNIXNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}") endif() ``` -------------------------------- ### Register group theme in .lev file Source: https://github.com/alemart/opensurge/wiki/groups Configuration required in the level file to enable group usage. ```text // header name "Legacy Template" author "OS Team" version "1.0" requires 0.2.0 act 1 theme "themes/template.brk" bgtheme "themes/template.bg" spawn_point 56 6424 music "musics/template.ogg" grouptheme "themes/template.grp" // <--- .grp file startup ".default_startup" players "Surge" "Neon" "Charge" ``` -------------------------------- ### Create legacy item Source: https://github.com/alemart/opensurge/wiki/level-specification Deprecated command to spawn a built-in item at specific coordinates. ```text item 0 3322 774 ``` -------------------------------- ### Default Input Map Configuration Source: https://github.com/alemart/opensurge/wiki/user-input Defines the default keyboard and joystick mappings for game actions. This file is located at inputs/default.in. ```text // File: inputs/default.in inputmap "default" { /* We use the following conventions for the button names in the default mapping: up: directional control right: directional control down: directional control left: directional control fire1: primary action button (jump | menus: confirm) fire2: secondary action button (menus: cancel) fire3: start, confirm, pause fire4: back, cancel, quit fire5: left shoulder button (left bumper) fire6: right shoulder button (right bumper) fire7: left thumbstick button fire8: right thumbstick button */ keyboard { up KEY_UP right KEY_RIGHT down KEY_DOWN left KEY_LEFT fire1 KEY_SPACE fire2 KEY_LCONTROL fire3 KEY_ENTER fire4 KEY_ESC fire5 KEY_LSHIFT fire6 KEY_RSHIFT fire7 KEY_NONE fire8 KEY_NONE } // default mapping for XInput controllers in Allegro // (standard gamepad based on the layout of the Xbox 360 controller) joystick 1 { up BUTTON_14 // D-pad right BUTTON_11 down BUTTON_13 left BUTTON_12 fire1 BUTTON_1 | BUTTON_3 | BUTTON_4 // A, X, Y fire2 BUTTON_2 // B fire3 BUTTON_10 // START fire4 BUTTON_9 // BACK / SELECT fire5 BUTTON_6 // L1 fire6 BUTTON_5 // R1 fire7 BUTTON_8 // THUMBL fire8 BUTTON_7 // THUMBR } } ``` -------------------------------- ### Configure Data Directory Paths Source: https://github.com/alemart/opensurge/blob/master/CMakeLists.txt Sets platform-specific definitions for user and data directories on UNIX systems. ```cmake if(UNIX) list(APPEND DEFS "GAME_USERDIRNAME=\"${GAME_USERDIRNAME}\"") if(IS_ABSOLUTE "${GAME_DATADIR}") list(APPEND DEFS "GAME_DATADIR=\"${GAME_DATADIR}\"") else() list(APPEND DEFS "GAME_DATADIR=\"${CMAKE_INSTALL_PREFIX}/${GAME_DATADIR}\"") endif() endif() ``` -------------------------------- ### Define a wildcard animation transition Source: https://github.com/alemart/opensurge/wiki/sprites Uses the any wildcard to trigger a transition to any other user-defined animation. ```text transition 10 to any {     // ... } ``` -------------------------------- ### Set CMake Module Path and Definitions Source: https://github.com/alemart/opensurge/blob/master/CMakeLists.txt Appends the custom module directory to the search path and initializes global definitions. ```cmake list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/misc/cmake") set(HELP "Tweak the options or get help at opensurge2d.org") set(DEFS "") # our #defines ``` -------------------------------- ### Define a quest file structure Source: https://github.com/alemart/opensurge/wiki/quests Quest files use a simple format with name properties and a sequential list of level file paths. Comments are denoted by double slashes. ```text // ----------------------------------------------------- // example.qst // Originally designed for: Open Surge Lunar Mod // Version 1.0 // Author: lunarrush // ----------------------------------------------------- // quest properties name "Example Quest" // level list (in order of appearance) level "levels/level1.lev" level "levels/cutscene1.lev" level "levels/level2.lev" // ... these can go on to the n-th level ``` -------------------------------- ### Running JBlocks from the terminal Source: https://github.com/alemart/opensurge/wiki/jblocks Use this command to launch the JBlocks application if double-clicking the JAR file fails. ```bash java -jar JBlocks.jar ``` -------------------------------- ### Configure MARKER behavior Source: https://github.com/alemart/opensurge/wiki/bricksets Defines a brick that is only visible in the editor. ```text // a marker won't be rendered during gameplay type SOLID behavior MARKER ```