/elixir_snake

Tutorial for building a Snake game with Scenic to teach Elixir.

Primary LanguageElixirMIT LicenseMIT

Build a Snake game to learn Elixir

This tutorial is about building a Snake game with Scenic to teach Elixir.

The tutorial is heavily based on the following article: Getting started with Scenic in Elixir — Crafting a simple snake game.

See the guides for the workshop material.

TODOs

So far the tutorial is given as a set of files, see Files. This needs to be fleshed out into a written tutorial.

We should also think about further reducing complexity. If we want to make changes to the game I would suggest to do so in the final version (i.e. in lib/game6.ex) first. We can then retrofit them to the other files.

Setup

Set up the project in order to view and run sample solutions for each step of the tutorial.

Installation

  1. Install Erlang and Elixir on your machine. Scenic requires Erlang/OTP 21 (or newer) and Elixir 1.7 (or newer).

(In case you're using the asdf version manager, install the respective plugins for Erlang/Elixir and run asdf install.)

  1. Install Open GL libraries for (for scenic_new)

On macOS 🍏:

    $ brew install glfw3 glew pkg-config

On Ubuntu 18 🐧:

    $ sudo apt-get install pkgconf libglfw3 libglfw3-dev libglew2.0 libglew-dev

(See https://github.com/boydm/scenic_new#install-prerequisites for details on other operating systems.)

  1. Install the scenic.new mix task (Mix task to easily generate a Scenic app):

     $ mix archive.install hex scenic_new
    

Project dependencies

Download the elixir dependencies from the project with:

$ mix deps.get

Running

Run the game with:

$ mix scenic.run

Files

So far the tutorial is given as a set of files, slowly building up the game:

  • lib/game1.ex - Initial setup with pellet. This is used to explain the basics.
  • lib/game2.ex - Setup to live-code the basic snake movement. Adds a skeleton for the movement functions.
  • lib/game3.ex - The result of live-coding the snake movement.
  • lib/game4.ex - Add input control and setup for live-coding pellet eating.
  • lib/game5.ex - Result of live-coding pellet eating.
  • lib/game6.ex - Final Game, implements dying.