catsocks / spacerocks-sdl

An arcade Asteroids clone in C using SDL that you can play in the browser.

Home Page:https://catsocks.github.io/spacerocks-sdl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spacerocks

A clone of the Asteroids arcade game, made with the cross-platform SDL library, for Windows, macOS, Linux, and the browser.

You can play the game in your browser at catsocks.github.io/spacerocks-sdl, and download executables from the Releases page of this project's GitHub repository.

It looks and behaves a lot like the original, but it is not identical. Notably, the appearance of the spaceship, explosions, and the feel of the controls are very different.

You can watch a video of Asteroids on Youtube and play it with the MAME emulator, provided you have an Asteroids ROM.

Features

  • Support for up to 2 gamepads
  • Touchscreen buttons (shown after the first touch)
  • Persistent high scores (saved after entering initials)
  • Portuguese text (English by default)
  • Resizable window and desktop fullscreen

Screenshots

Screenshot of the start screen

Controls

Keyboard

  • C inserts a a coin
  • 1 starts a 1 player game
  • 2 starts a 2 player game
  • A rotates the ship left
  • D rotates the ship right
  • W thrusts the ship forward
  • J fires a missile
  • K sends the ship into hyperpace
  • F11 toggles fullscreen
  • F10 switches to the next language
  • F9 switches to the previous language

The ones below are only available when the DEBUG_SPACEROCKS symbol is equal to 1. It is set to 1 for debug builds by default in CMakeLists.txt.

  • 3 adds an extra ship
  • 4 adds 5,000 points
  • 5 destroys the ship
  • 6 destroys all the rocks
  • 7 destroys the saucer
  • 8 causes the game to be over

Gamepad

The button names of a Xbox 360 controller are used.

  • Y inserts a coin
  • Left shoulder starts a 1 player game
  • Right shoulder starts a 2 player game
  • D-pad left rotates the ship left
  • D-pad right rotates the ship right
  • D-pad up thrusts the ship forward
  • A fires a missile
  • B sends the ship into hyperspace

Build

Requirements

Programs

  • C compiler with C99 support
  • CMake
  • Node.js (optional, used for building the website and the manual)

Note that to use the Node.js scripts, you must first run npm install from the root folder of this project to install their dependencies.

Libraries

Native executable

The executable can be built by first configuring a build using CMake from the root folder of the project:

$ cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug

The command will configure a debug build to a folder named build.

If you wouldn't like to build the tests pass -DBUILD_TESTING=off and if you encounter any issues with missing libraries, passing -DCMAKE_FIND_DEBUG_MODE=on will make CMake print the paths where it expects to find the library files.

With a successfully configured build, you can build it as follows:

$ cmake --build build

And with a successful build you can run the executable from the build folder like so (assuming you're using an Unix-like shell):

$ (cd build && ./spacerocks)

It's necessary to run Spacerocks from the folder it was built so it may find its assets.

Manual

The manual is an HTML file containing a stripped down version of the website's index page meant to be distributed with the game's executable.

The manual can be built using the spacerocks_manual build target defined in CMakeLists.txt which will call the tools/build-manual.js script for you:

$ cmake --build build --target spacerocks_manual

Emscripten executable

Emscripten is used to create an executable that can be run in the browser.

The only library you will have to install is PhysicsFS, because SDL will be automatically installed during compilation using Emscripten Ports, and the OpenAL library that comes with Emscripten will be used. Unfortunately as of 2021-05-21 PhysicsFS is not included in Emscripten Ports.

The build is configured the same way a native one is, except that the emcmake tool should be used to call CMake, as it will let CMake know how to cross-compile the project:

$ emcmake cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug

Build the same way you would a native executable, and with a successful build you can run the executable using the emrun tool which will serve it in a web server and open it in your default browser:

$ emrun --serve_root build build/game.html

It's not necessary to restart emrun after rebuilding, and the option --no_browser will disable the launching of the browser.

Website

The website for the Emscripten executable can be built using the spacerocks_website target which will call the tools/build-website.js script for you:

$ cmake --build build --target spacerocks_website

If the web server used to serve the game does not compress the files it serves, you should consider packaging the files with the Emscripten packager tool using the --lz4 option to enable compression since Emscripten does not package the game assets with compression by default as of 2021-05-04.

Bugs

  • The ship thrust sound is disabled in the browser because of audio crackling when the Emscripten OpenAL implementation is used
  • The graphics lines can become too thin on very high resolution screens

License

My work for this project is dedicated to the public domain under the CC0 1.0 Universal license included in the LICENSE.md file.

The licenses of the work from third parties included in this project is available in the THIRD-PARTY-NOTICES.md file.

Acknowledgements

About

An arcade Asteroids clone in C using SDL that you can play in the browser.

https://catsocks.github.io/spacerocks-sdl

License:Creative Commons Zero v1.0 Universal


Languages

Language:C 83.3%Language:HTML 10.6%Language:CMake 4.0%Language:JavaScript 2.1%