Snake away with a .NET Gadgeteer arcade console and Snake game


Hardware Friday's have been pretty .Net Gadgeteer focused lately, I know. Next week I'll dig through my story archive list and find something different, but being a child of the 80's I couldn't resist this project. I've always wanted my own arcade console, and while this isn't an Asteroids or Ms PacMan, the fact that you build the hardware and code it up from the ground floor almost makes it better... (well... almost... Smiley

.NET Gadgeteer Arcade Console

Relive the days of classic arcade games with this gorgeous do-it-yourself miniature arcade console. It’s equipped with a touch screen, joystick and Ethernet port for fun multiplayer action! Pay tribute to your favorite classic game or invent your own!

The Arcade console is an implementation of the Snake video game. There are many versions of this game. In this version the .NET Gadgeteer Display T35 module and .NET Gadgeteer Timer are used to display the snake and a pellet of food and to move them around the display window. A joystick sends user input that controls the movement of the snake. The object of the game is to move the snake into a collision with the food pellet, which makes the snake grow longer.

The code for the Arcade console demonstrates many features of the Display T35 module, the .NET Gadgeteer WPF Window class, and .NET Micro Framework Canvas class. The implementation of the GameEngine, GameCanvas, and Sprite classes illustrates the use of bitmap resources and drawing on the canvas. Two timers are running while the game is in progress. One timer randomly advances the food pellet and another moves the snake as directed by the user from the joystick. Math classes are used in the positioning of the sprites.

The C# program runs on a GHI Electronics Fez Spider mainboard powered by the Dual Power module, which can be used with a battery or USB power. The USB connection must be connected initially to deploy assemblies to the mainboard. An Ethernet module is included to support extensibility for multiple players.

Code for MicroSnake game:

Laser cut enclosure (Ponoko-ready):

Here's a snip of the hardware design;


And a code snip;

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

using Gadgeteer.GameEngine;
using Gadgeteer.Modules.GHIElectronics;

namespace MicroSnake
    public partial class Program
        const int GAME_GRID_SIZE = 20;

        Window mainWindow;
        GameEngine gameEngine;
        Gadgeteer.Timer drawTimer;
        Gadgeteer.Timer inputTimer;

        Sprite food = new Sprite(Resources.GetBitmap(Resources.BitmapResources.Food_20x20), 160, 200, true);
        SpriteCollection snake = new SpriteCollection();
        Bitmap snakeBitmap = Resources.GetBitmap(Resources.BitmapResources.SnakeBlueBody_20x20);

        void ProgramStarted()
            // Initialize event handlers here.
            // e.g. button.ButtonPressed += new GTM.MSRC.Button.ButtonEventHandler(button_ButtonPressed);
            mainWindow = display.WPFWindow;

            gameEngine = new GameEngine(mainWindow);

            drawTimer = new GT.Timer(new TimeSpan(0, 0, 0, 0, 400));
            drawTimer.Tick += new GT.Timer.TickEventHandler(drawTimer_Tick);

            inputTimer = new GT.Timer(new TimeSpan(0, 0, 0, 0, 100));
            inputTimer.Tick += new GT.Timer.TickEventHandler(inputTimer_Tick);

            CurrentDirection = Direction.Right;


            // Do one-time tasks here
            Debug.Print("Program Started");

        void inputTimer_Tick(GT.Timer timer)
            GTM.GHIElectronics.Joystick.Position jPos = joystick.GetJoystickPostion();

            if (0.3 < jPos.Y && jPos.Y < 0.7)
                if (jPos.X > 0.8)
                    if (CurrentDirection != Direction.Left)
                        CurrentDirection = Direction.Right;
                else if (jPos.X < 0.2)
                    if (CurrentDirection != Direction.Right)
                        CurrentDirection = Direction.Left;

            if (0.3 < jPos.X && jPos.X < 0.7)
                if (jPos.Y > 0.8)
                    if (CurrentDirection != Direction.Down)
                        CurrentDirection = Direction.Up;
                else if (jPos.Y < 0.2)
                    if (CurrentDirection != Direction.Up)
                        CurrentDirection = Direction.Down;

This is just another example that building hardware you can code to, or code that you can build hardware for, is probably easier, faster and more fun than you think.

The Discussion

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.