Skip to content
A top-down 2d game engine, written from scratch in under 1000 lines of C.
C Makefile Other
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows Add update command to apt-get. Feb 17, 2020
.theia Tweak Gitpod config. Ensure that clang-format works there as well. Feb 9, 2020
assets Allow EMPTY_COLUMN to be positive or negative. Feb 17, 2020
linux Getting to the bottom of these core dump bugs ... Feb 15, 2020
mac Update Mac binary. Feb 13, 2020
source Allow EMPTY_COLUMN to be positive or negative. Feb 17, 2020
windows Allow EMPTY_COLUMN to be positive or negative. Feb 17, 2020
.clang-format Initial commit. Feb 1, 2020
.clang_complete Initial commit. Feb 1, 2020
.editorconfig Initial commit. Feb 1, 2020
.gitignore Initial commit. Feb 1, 2020
.gitpod.Dockerfile Tweak Gitpod config. Ensure that clang-format works there as well. Feb 9, 2020
.gitpod.yml Tweak Gitpod config. Ensure that clang-format works there as well. Feb 9, 2020
LICENSE Initial commit. Feb 1, 2020
Makefile Initial commit. Feb 1, 2020
README.md Some wording tweaks. Feb 13, 2020
TODO.txt Clean up some memory allocation issues. Thanks to @pmttavara for some… Feb 6, 2020
cloc_it.cmd
line_count.md Allow EMPTY_COLUMN to be positive or negative. Feb 17, 2020

README.md

Basque

Basque is a top-down 2d game engine.


Basque demo Basque demo 2


Too lazy to do local setup? You can give it a spin using Gitpod (no sound or key repeats though)!

Open in Gitpod


Global keyboard shortcuts:

: Move player North

: Move player East

: Move player South

: Move player West

q: Quit

e: Toggle edit mode

Edit mode shortcuts:

l: Toggle map library

Mouse button 1 (left click): Place tile

Mouse button 2 (right click): Select tile


Why do this?

Why not just use Godot/Unity/et cetera? Basque has a very different priority list than these engines. It is not a generic engine. There isn't much here, but it is a good starting point if you are looking to roll your own engine, here is what it does:

  • Compiles cross platform (Linux/Mac/Windows, should work on BSD or Haiku as well).
  • Visual map editing (with an easy to understand plain text format).
  • Spritesheet animation.
  • Background music.
  • Scrolling.
  • Collision detection.
  • Some frame rate limiting.
  • Accepts command line arguments (currently only for enabling fullscreen mode).

Everything that is here should not be considered a final or optimal solution, but rather, 'a good start'. At this point the engine will start becoming more specific to the game I am building, which is why I see this as the best time to open source it. Hopefully, it can be useful to others, either as a starting point, or as a guide of how to do some things with SDL2. Note that all of the code here is not necessarily the best solution to these problems, but it is a solution.


Map editing/layouts/attributes:

The current map system utilizes three main files:

  • map_attributes.txt
  • map_layout.txt
  • map_library.txt

While editing the map, you may use the visual map editor (available in DEBUG_MODE by pressing e) or edit the text files directly. Basque checks the timestamps of the files, and will reload them if they change, you do not need to recompile or relaunch Basque to do this. map_layout.txt also has suffixed versions created, with the intention of supporting future redo/undo functionality. The current number of versions that are kept is 100. This is of course, configurable.

map_attributes.txt follows the following format (all items are integers):

TILE_INDEX:
{ X_CLIP, Y_CLIP }, { NORTH_BORDER, EAST_BORDER, SOUTH_BORDER, WEST_BORDER },

Comments preceded with // in the attributes file are allowed. The other file types do not allow comments.

map_layout.txt and map_library.txt are comma separated integers, representing the tile indices. Newlines represent new rows.

For example:

  0,  1,  2,  3,  4,  1,  5,  _
 27, 16, 16, 16, 16, 16, 17,  _
 27, 16, 16, 16, 16, 16, 17,  _
 27, 16, 28, 16, 16, 16, 17,  _

The visual map editor (available in DEBUG_MODE by pressing e) automatically writes the indices with even spacing. _ is a shortcut for a blank tile (the index for which is configurable under configuration.h).

map_library.txt is intended to be a resource for picking tiles (available in DEBUG_MODE -> EDIT_MODE by pressing l), while editing the world map (map_layout.txt). It has a few special properties. It will not show the player, and it always appears starting at the top left corner of the screen. It is also not editable by the map editor.


Basque currently requires:

  • SDL2
  • SDL2_image
  • SDL2_mixer
  • SDL2_ttf

Getting SDL2 installed:

Linux:

apt:
sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev
dnf:
sudo dnf install SDL2-devel SDL2_image-devel SDL2_mixer-devel SDL2_ttf-devel

Or whatever the equivalent package is for your distro.

Mac:

brew install sdl2 sdl2_image sdl2_mixer sdl2_ttf

Windows:

  1. Download the latest VC development files from: https://libsdl.org

  2. Place the entire contents of include and lib under C:\INCLUDE\SDL2.

  3. Copy all DLLs under lib to C:\Windows\System32 and C:\Windows\SysWOW64.

  4. Repeat for SDL2_image, SDL2_mixer, and SDL2_ttf.

  5. Profit.


Compiling:

Linux & Mac:

make

Windows:

nmake

Running:

After compiling for your platform, you can launch with ./basque (or basque.exe on Windows). Passing -f or --fullscreen will launch the app in fullscreen, rather than the resolution specified in configuration.h.

You can’t perform that action at this time.