# Writing a 2D Platform Game in Nim with SDL2

DevFeed: [Writing a 2D Platform Game in Nim with SDL2](<https://devfeed.tech/articles/writing-a-2d-platform-game-in-nim-with-sdl2-30846.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/writing-a-2d-platform-game-in-nim-with-sdl2/>)

Published: 2016-06-13T22:00:00Z

Content type: tutorial

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Nim](<https://devfeed.tech/topics/nim.md>), [Simple DirectMedia Layer](<https://devfeed.tech/topics/sdl.md>), [Game Development](<https://devfeed.tech/topics/game-development.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Graphics](<https://devfeed.tech/topics/graphics.md>), [GitHub](<https://devfeed.tech/topics/github.md>)

Tags: [game-development](<https://devfeed.tech/tags/game-development.md>), [github](<https://devfeed.tech/tags/github.md>), [graphics](<https://devfeed.tech/tags/graphics.md>), [linux](<https://devfeed.tech/tags/linux.md>), [nim](<https://devfeed.tech/tags/nim.md>), [programming](<https://devfeed.tech/tags/programming.md>), [sdl](<https://devfeed.tech/tags/sdl.md>), [tutorial](<https://devfeed.tech/tags/tutorial.md>), [windows](<https://devfeed.tech/tags/windows.md>)

## AI overview

This tutorial explains how to build a simple 2D platform game in Nim with SDL2. It covers user input, graphics, tile maps, 2D physics with collision detection, camera movement, game logic, text rendering with caching, source code organization, and cross-compiling Nim programs for Windows on Linux.

## Source excerpt

Japanese Translation In this article we're going to write a simple 2D platform game. You can also consider this as a tutorial for game development with SDL2 in Nim. We will read in user input, display graphics and a tile map, and simulate simple 2D physics with collision detection and handling. Afterwards we will implement simple camera movement and game logic. To display some information we will render texts and develop a caching mechanism for said text rendering. The final result will be a binary file that requires only SDL2 and can be easily distributed, perfect for games. If you're on Linux we will also present a simple way to cross-compile Nim programs for Windows. For the sake of simplicity we're going to use the familiar graphics from DDNet and Teeworlds, with the end result of this tutorial looking like this: We're going to follow along with the development throughout this article with illustrative images and videos, but the best way to learn is if you follow along yourself by implementing the steps from this article. The code is purposefully kept simple and easy to extend so that you can play around with it and try out all kinds of changes to get an intuitive understanding. At the end of every section there is a link to its full source code. The iterations of the code of this article and the final result are available in a repository on GitHub. The resulting binaries can be downloaded here: Win64, Win32, Linux x86_64, Linux x86 Preliminaries For this post we require: The Nim programming language and its package manager Nimble SDL 2, SDL_image 2, SDL_ttf 2 (all for developers) Nim SDL2 wrapper and strfmt, which can be installed using Nimble On a unixoid system like Linux or Mac OS X the installation looks something like this: # Debian / Ubuntu $ sudo apt-get install git libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev # Arch Linux $ pacman -S git sdl2 sdl2_image sdl2_ttf # Homebrew on OS X $ brew install git sdl2 sdl2_image sdl2_ttf # FreeBSD $ pkg install git