Geeks With Blogs
Where software meets hardware (there are 10 types of people, those who understand binary, and those who do not)

 

Well it works !   Here is a simple game using the Fex Panda with 10 LEDs wired to Digital ports 0-9, using the on board button for input.  The LEDs scroll Knight-Rider-Style and you have to press the button when the left hand led is on.  The game keeps speeding up until you fail and then displays your score before restarting.  It only too an hour to write and works a treat.


Click the YouTube Link to see the game in action
 

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;

namespace Game1
{
    public class Program
    {

        static OutputPort led0;
        static OutputPort led1;
        static OutputPort led2;
        static OutputPort led3;
        static OutputPort led4;
        static OutputPort led5;
        static OutputPort led6;
        static OutputPort led7;
        static OutputPort led8;
        static OutputPort led9;

        static int delay = 250;
        static int iLED = 0;
        static bool keepPlaying = true;
        static int score = 0;

        public static void Main()
        {
            //set LEDs
            led0 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di0, false);
            led1 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di1, false);
            led2 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di2, false);
            led3 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di3, false);
            led4 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di4, false);
            led5 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di5, false);
            led6 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di6, false);
            led7 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di7, false);
            led8 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di8, false);
            led9 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di9, false);

            // on board push button
            InterruptPort btn = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.LDR, true, Port.ResistorMode.PullUp,Port.InterruptMode.InterruptEdgeBoth);
            btn.OnInterrupt += new NativeEventHandler(btn_OnInterrupt);
           
            while (true)
            {
                delay = 250;
                keepPlaying = true;
                score = 0;


                while (keepPlaying)
                {

                    for (iLED = 0; iLED < 10; iLED++)
                    {
                        setLeds(iLED, delay);
                        if (!keepPlaying) break;
                    }
                    if (!keepPlaying) break;

                    for (iLED = 8; iLED > 0; iLED--)
                    {
                        setLeds(iLED, delay);
                        if (!keepPlaying) break;

                    }
                }

                for (int j = 0; j < 5; j++)
                {
                    setLeds(score-1, 200);
                    setLeds(100, 50);
                }
            }
        }

        static void btn_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            if (data2 == 1) return;

            Debug.Print(iLED.ToString() + data1.ToString() + data2.ToString());
            if (iLED > 0)
            {
                keepPlaying = false;
            }
            else
            {
                delay = (int)(0.75 * delay);
                score++;
            }
        }

        static void setLeds(int val)
        {
            led0.Write((val == 0));
            led1.Write((val == 1));
            led2.Write((val == 2));
            led3.Write((val == 3));
            led4.Write((val == 4));
            led5.Write((val == 5));
            led6.Write((val == 6));
            led7.Write((val == 7));
            led8.Write((val == 8));
            led9.Write((val == 9));
        }

        static void setLeds(int val, int delay)
        {
            setLeds(val);
            Thread.Sleep(delay);
        }
    }
}

Posted on Thursday, June 9, 2011 11:01 PM .NETMF , Fez Panda | Back to top

Related Posts on Geeks With Blogs Matching Categories

Comments on this post: Adventures with the Fez Panda II - a simple game

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © OneEyedSam | Powered by: GeeksWithBlogs.net