Skip to content

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

License

Notifications You must be signed in to change notification settings

codecurious-bln/elixir_snake

Repository files navigation

CircleCI

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.)

  2. 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.)

  3. 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.

Tips & Tricks

  • use prettier CLI to automatically format the markdown files:

    npx prettier --write <path-to-file>
    

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages