Giter Club home page Giter Club logo

snake-qr's Introduction

Snake QR

QR code
A simple and pure win32 Snake game, without any compressor trickery, just under 2,953 bytes!

Contenxt/Credit

The original source code was taken from MattKC's "Can you fit a whole game into a QR code?" video. If you haven't watched the video prior, watch it here for context and what not.

Main changes compared to the MattKC version

  • No crinker/compressor is used. Just pure C and compiler shenanigans.
  • A few visual and gameplay fixes to make it much closer to the HTML version that was shown in the video.
  • You can pause the game now by pressing the enter key instead of the pause or 'P' key.
  • You can retry the game by pressing the 'R' key.

Primary changes

To see the differences between the original and this version first-hand, it's best to view the original file and see what's different from a programming perspective. Regardless, here is a list of the main changes between the two:

Space saving changes

  • The input system has been reworked to utilize only 2 variables instead of using an array of valid/invalid inputs. This rework reduces quite a considerable amount of taken up space inside the executable, as the game now does less interanally for the same result.
  • The food starts at a constant position instead of calling the rand function at startup.
  • All integers are size_t.
  • A custom rand is implemented instead of relying on the C standard version.
  • Code to change the snake's color depending on the game state (playing/won/lost) has been reworked to be completely branchless.
  • WM_TIMER's while loop has been converted to a single if statement.
  • Removed the bool moved variable in WM_TIMER and used goto instead.
  • Removed the else statement at if (snake_len == MAX_TILE_COUNT).
  • Removed GetModuleHandleA and AdjustWindowRect.
  • The app now uses allocates memory into the stack instead of the heap to allocate snake_pos.
  • Removed if (msg.message == WM_QUIT) in the main loop.
  • Removed TranslateMessage in the main loop.

Bug fixes

Visual changes

  • The apple is now green.

Misc changes

  • You can now retry the game at anytime by pressing 'R'.
  • The game's performance has been improved (less branching, PosEqual does one check instead of 2, etc).
  • The pause button has been changed from VK_PAUSE and P to VK_ENTER.
  • Regular WNDCLASSA and CreateWindowA are used instead of the expanded versions.
  • The game doesn't overallocate dir_queue like it did in the original.

Building

NOTE: cl.exe is assumed to be x86, not x64! Compiling it in 64-bit will considerably increase the size of the binary.

Windows

Just copy the terminal commands from Makefile and paste them into the terminal.

Linux/*nix OSses

This requires downloading msvc from msvc-wine. After that, just run make and you'll get correct binaries.

Making the QR code

Once you compiled snake.exe, on Unix you can run make qrcode to generate code.png.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.