Beispiel #1
0
    public void TargetDetection()
    {
        RaycastHit[] hit = Physics.SphereCastAll(transform.position, 20f, transform.forward, m_targetMask);

        if (hit.Length < 1)
        {
            ClearTargets();
            return;
        }

        for (int i = 0; i < hit.Length; i++)
        {
            CTarget temp = hit[i].collider.GetComponent <CTarget>();

            if (temp == null)
            {
                continue;
            }

            Vector3 tempDir = temp.transform.position - m_camCtrl.Camera.transform.position;

            float dot = Vector3.Dot(m_camCtrl.Camera.transform.forward, tempDir.normalized);

            if (dot >= 0.65f)
            {
                m_targets.Add(temp);
            }
        }

        if (m_targets.Count > 0)
        {
            m_camCtrl.IsLockOn = true;
        }
    }
Beispiel #2
0
        public static void Main(string[] args)
        {
#if REQUIRES_CRT_INIT
            CRT.Auto.Initialize();
#endif

            if (args.Length < 2)
            {
                Console.WriteLine("SNMP++.NET command line utility\n"
                                  + "Author: Marek Malowidzki 2003,2004 ([email protected])\n"
                                  + "Based on SNMP++ package from Peter E. Mellquist (HP) and Jochen Katz\n"
                                  + "SNMP++.NET " + Assembly.GetAssembly(typeof(Snmp))
                                  + " built on " + Snmp.BuildTime
                                  + "; SNMP++ v. " + Snmp.Snmp_ppVersion + "\n\n"
                                  + "Usage: " + Environment.GetCommandLineArgs()[0] + " <op> <agent> [<options>]\n"
                                  + "where:\n"
                                  + "op           - SNMP operation to perform (get,getnext,getbulk,set,walk,table)\n"
                                  + "agent        - IP address or DNS name of an agent\n"
                                  + "options are the following:\n"
                                  + "-v<version>  - SNMP version to use (v1(default),v2c,v3)\n"
                                  + "-p<port>     - port number to use\n"
                                  + "-r<retries>  - number of retries (default: 2)\n"
                                  + "-t<timeout>  - timeout in milliseconds (default: 1000)\n"
                                  + "-d<bool>     - print debug messages\n"
                                  + "-o<oid>      - subsequent OID\n"
                                  + "-T<type>     - subsequent SNMP type name:\n"
                                  + string.Join(",", SnmpSyntax.SupportedSyntaxNames)
                                  + " (o stands for oid and s for string)\n"
                                  + "-V<value>    - subsequent value\n"
                                  + "Debug options:\n"
                                  + "-Df<file>    - log file name\n"
                                  + "-Dl<level>   - log level\n"
                                  + "SNMPv1/v2c options:\n"
                                  + "-c<comm>     - read community name (default: public)\n"
                                  + "-C<comm>     - write community name (default: public)\n"
                                  + "SNMPv3 options:\n"
                                  + "-b<boot>     - boot counter value (default: 100)\n"
                                  + "-sn<secName> - security name\n"
                                  + "-sl<secLevel>- security level ("
                                  + ManagerUtilities.EnumInfo(typeof(SecurityLevel), SecurityLevel.AuthPriv) + ")\n"
                                  + "-sm<secModel>- security model ("
                                  + ManagerUtilities.EnumInfo(typeof(SecurityModel), SecurityModel.USM) + ")\n"
                                  + "-xn<ctxName> - context name\n"
                                  + "-xe<ctxEngId>- context engine ID (default: discover)\n"
                                  + "-A<authProto>- authentication protocol ("
                                  + ManagerUtilities.EnumInfo(typeof(AuthProtocol), AuthProtocol.None) + ")\n"
                                  + "-P<privProto>- privacy protocol ("
                                  + ManagerUtilities.EnumInfo(typeof(PrivProtocol), PrivProtocol.None) + ")\n"
                                  + "-Ua<authPass>- authentication password\n"
                                  + "-Up<privPass>- privacy password\n"
                                  + "Table operation options:\n"
                                  + "-Os<rowOid>  - row index to start from\n"
                                  + "-Oe<rowOid>  - row index to finish at\n"
                                  + "-On<count>   - max number of rows to retrieve\n"
                                  + "-Or<count>   - rows per query or 0 for heuristics\n"
                                  + "Testing options:\n"
                                  + "-Xa<bool>    - use asynchronous interface\n"
                                  + "-Xm<filePfx> - collect memory usage in <filePfx>.<ext> files, where ext denotes memory type\n"
                                  + "-Xn<repeat>  - repeat number of times (default: 1)\n"
                                  + "-Xp<priority>- set process priority ("
                                  + ManagerUtilities.EnumInfo(typeof(ProcessPriorityClass), ProcessPriorityClass.Normal) + ")\n"
                                  + "-Xs<bool>    - use asychronous interface for synchronous calls\n"
                                  + "-Xt<threads> - run multiple threads (default: 1)");
                Environment.Exit(1);
            }

            string      option         = "<ip>";
            Thread      statsCollector = null;
            MemoryStats stats          = null;
            int         retCode        = 1;
            try
            {
                UdpAddress  udp = new UdpAddress(args[1]);
                SnmpVersion ver = SnmpVersion.SNMPv1;
                SnmpTarget.DefaultRetries = 2;
                SnmpTarget.DefaultTimeout = 1000;
                uint   nRepeats = 1, nThreads = 1;
                int    debugLevel = int.MinValue;
                string statsFile = null, debugFile = null;
                TableReader.GetTableOptions tableOptions = new TableReader.GetTableOptions();
                bool async = false, asyncSync = false, debug = false;

                string readCommunity   = "public",
                       writeCommunity  = "public";
                AuthProtocol authProto = AuthProtocol.None;
                PrivProtocol privProto = PrivProtocol.None;
                string       authPass  = "",
                             privPass  = "",
                             secName   = "",
                             ctxName   = "",
                             ctxEngId  = "";
                SecurityLevel secLevel = SecurityLevel.AuthPriv;
                SecurityModel secModel = SecurityModel.USM;
                uint          boot     = 100;

                string[] oids = new string[128],
                types = new string[128],
                vals  = new string[128];
                int noids = 0, ntypes = 0, nvals = 0;

                string val;
                int    index = 2;
                while (ManagerUtilities.GetOption(args, out option, out val, ref index))
                {
                    char sub;
                    switch (option)
                    {
                    case "v":
                        ver = (SnmpVersion)Enum.Parse(
                            typeof(SnmpVersion), "SNMPv" + val, true);
                        break;

                    case "p":
                        udp = new UdpAddress(udp.Ip, int.Parse(val));
                        break;

                    case "r":
                        SnmpTarget.DefaultRetries = int.Parse(val);
                        break;

                    case "t":
                        SnmpTarget.DefaultTimeout = int.Parse(val);
                        break;

                    case "d":
                        debug = bool.Parse(val);
                        break;

                    case "o":
                        oids[noids++] = val;
                        break;

                    case "T":
                        types[ntypes++] = val;
                        break;

                    case "V":
                        vals[nvals++] = val;
                        break;

                    case "c":
                        readCommunity = val;
                        break;

                    case "C":
                        writeCommunity = val;
                        break;

                    case "b":
                        boot = uint.Parse(val);
                        break;

                    case "s":
                        switch (sub = ManagerUtilities.GetSubOption(ref val))
                        {
                        case 'n':
                            secName = val;
                            break;

                        case 'l':
                            secLevel = (SecurityLevel)Enum.Parse(
                                typeof(SecurityLevel), val, true);
                            break;

                        case 'm':
                            secModel = (SecurityModel)Enum.Parse(
                                typeof(SecurityModel), val, true);
                            break;

                        default:
                            throw new ArgumentException(
                                      sub + ": invalid sub-option");
                        }
                        break;

                    case "x":
                        switch (sub = ManagerUtilities.GetSubOption(ref val))
                        {
                        case 'n':
                            ctxName = val;
                            break;

                        case 'e':
                            ctxEngId = val;
                            break;

                        default:
                            throw new ArgumentException(
                                      sub + ": invalid sub-option");
                        }
                        break;

                    case "A":
                        authProto = (AuthProtocol)Enum.Parse(
                            typeof(AuthProtocol), val, true);
                        break;

                    case "P":
                        privProto = (PrivProtocol)Enum.Parse(
                            typeof(PrivProtocol), val, true);
                        break;

                    case "D":
                        switch (sub = ManagerUtilities.GetSubOption(ref val))
                        {
                        case 'f':
                            debugFile = val;
                            break;

                        case 'l':
                            debugLevel = int.Parse(val);
                            break;

                        default:
                            throw new ArgumentException(
                                      sub + ": invalid sub-option");
                        }
                        break;

                    case "U":
                        switch (sub = ManagerUtilities.GetSubOption(ref val))
                        {
                        case 'a':
                            authPass = val;
                            break;

                        case 'p':
                            privPass = val;
                            break;

                        default:
                            throw new ArgumentException(
                                      sub + ": invalid sub-option");
                        }
                        break;

                    case "O":
                    {
                        switch (sub = ManagerUtilities.GetSubOption(ref val))
                        {
                        case 's':
                            tableOptions.startRowIndex = new Oid(val);
                            break;

                        case 'e':
                            tableOptions.endRowIndex = new Oid(val);
                            break;

                        case 'n':
                            tableOptions.maxRows = int.Parse(val);
                            break;

                        case 'r':
                            tableOptions.rowsPerQuery = int.Parse(val);
                            break;

                        default:
                            throw new ArgumentException(
                                      sub + ": invalid sub-option");
                        }
                        break;
                    }

                    case "X":
                        switch (sub = ManagerUtilities.GetSubOption(ref val))
                        {
                        case 'a':
                            async = ParseBoolWithDefault(val);
                            break;

                        case 'm':
                            statsFile = val;
                            break;

                        case 'n':
                            nRepeats = uint.Parse(val);
                            break;

                        case 'p':
                            System.Diagnostics.Process.GetCurrentProcess().PriorityClass
                                = (ProcessPriorityClass)Enum.Parse(
                                      typeof(ProcessPriorityClass), val, true);
                            break;

                        case 's':
                            asyncSync = ParseBoolWithDefault(val);
                            break;

                        case 't':
                            if ((nThreads = uint.Parse(val)) <= 0)
                            {
                                throw new ArgumentException(
                                          val + ": invalid threads number");
                            }
                            break;

                        default:
                            throw new ArgumentException(
                                      sub + ": invalid sub-option");
                        }
                        break;

                    default:
                        throw new ArgumentException(
                                  "-" + option + ": invalid option");
                    }
                }

                if (noids == 0)
                {
                    option = "<OIDs>";
                    throw new ArgumentException(
                              "No OIDs specified, use -o option");
                }

                bool asyncMode = async || asyncSync;

                // Debug options
                if (debugFile != null)
                {
                    Snmp.DebugLogFile = debugFile;
                }
                if (debugLevel != int.MinValue)
                {
                    Snmp.DebugLogLevel = debugLevel;
                }

                // Operation type processing
                option = "<Pdu creation>";
                PduType  pduType;
                OperType operType;
                GetOperType(args[0].ToLower(), out pduType, out operType);

                // Adjusting settings for a table operation
                if (operType == OperType.Table)
                {
                    TableReader.UseAsyncInvoke = asyncMode;
                }

                // Pdu creation
                Pdu pdu;
                using (IMemoryManager mgr = MemoryManager.GetMemoryManager())
                {
                    Vb[] vbs = ManagerUtilities.CreateVbs(pduType, oids, noids, types, ntypes, vals, nvals);
                    pdu = new Pdu(pduType, vbs);
                    mgr.Remove(pdu);                            // remove Pdu from the memory manager
                }

                // SnmpTarget creation
                SnmpTarget target;
                if (ver == SnmpVersion.SNMPv3)
                {
                    option = "<SNMPv3 initialization>";
                    V3MP.Init(new OctetStr("SNMP++.NET"), boot);
                    USM usm = V3MP.Instance.Usm;
                    usm.AddUsmUser(secName, authProto, privProto, authPass, privPass);

                    target = new UTarget(udp, secName, secModel);

                    pdu.SecurityLevel   = secLevel;
                    pdu.ContextName     = new OctetStr(ctxName);
                    pdu.ContextEngineId = new OctetStr(ctxEngId);
                }
                else
                {
                    option = "<SNMPv1/v2c initialization>";
                    target = new CTarget(udp, ver, readCommunity, writeCommunity);
                }
                udp = null;

                // Memory usage statistics initialization
                option = "<Statistics collector initialization>";
                if (statsFile != null)
                {
                    stats                   = new MemoryStats(statsFile);
                    statsCollector          = new Thread(new ThreadStart(stats.Collect));
                    statsCollector.Priority = ThreadPriority.BelowNormal;
                    statsCollector.Start();
                }

                // Snmp session initialization & further processing
                option = "<SNMP session initialization>";
                using (Snmp snmp = new Snmp(asyncMode))
                {
                    Thread.CurrentThread.Name = "0";

                    Barrier  barrier;
                    Delegate fun;
                    if (async)
                    {
                        fun     = new Delegate(AsyncProcess);
                        barrier = new Barrier(nThreads + 1);
                    }
                    else
                    {
                        fun     = new Delegate(Process);
                        barrier = new Barrier(nThreads);
                    }

                    Manager mgr = new Manager(0, snmp, target, pdu, operType,
                                              ref tableOptions, barrier,
                                              nRepeats, asyncSync, debug);

                    DateTime start  = DateTime.Now;
                    int      ncalls = fun(mgr, ref option);
                    double   msec   = DateTime.Now.Subtract(start).TotalMilliseconds;

                    // clear references on stack
                    pdu = null; target = null; mgr = null;
                    Console.WriteLine("{0} {1} SNMP request(s) in {2} msec. ({3} req./sec.)",
                                      ncalls, asyncMode ? "asynchronous" : "synchronous",
                                      (int)msec, msec > 0 ? (1000 * (long)ncalls / msec) : 0);
                }
                retCode = 0;
            }
            catch (SnmpClassException e)
            {
                Console.Error.WriteLine("*** SNMP class error while processing {0}:\n"
                                        + "SnmpClass status code: {1}\n{2}", option, e.Status, e);
            }
            catch (SnmpException e)
            {
                Console.Error.WriteLine("*** SNMP protocol error while processing {0}:\n"
                                        + "SNMP error status: {1}\nSNMP error index: {2}\n{3}",
                                        option, e.ErrorStatus, e.ErrorIndex, e);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("*** Error while processing {0}:\n{1}", option, e);
            }

            Console.WriteLine("Remaining native SNMP++ objects before GC: "
                              + MemoryManager.Count);

            if (statsCollector != null)
            {
                stats.WaitForNextStat();
            }

            GC.Collect();
            GC.Collect();
            GC.WaitForPendingFinalizers();

            if (statsCollector != null)
            {
                stats.WaitForNextStat();

                statsCollector.Interrupt();
                statsCollector.Join();
            }

            // Despite our honest intentions, there may still be uncollected
            // SNMP++.NET objects, especially in the Release mode
            Console.WriteLine("Remaining native SNMP++ objects after GC: "
                              + MemoryManager.Count);

            Environment.Exit(retCode);
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.Error.WriteLine(
                    "SNMP++.NET {0} built on {1}; SNMP++ v. {2}\n\n"
                    + "Usage: {3} <ip> <readCommunity> [<debugMark>]",
                    Assembly.GetAssembly(typeof(Snmp)),
                    Snmp.BuildTime,
                    Snmp.Snmp_ppVersion,
                    Environment.GetCommandLineArgs()[0]);
                Environment.Exit(1);
            }

            string ip = args[0], community = args[1];
            bool   debug = args.Length > 2 && args[2].Length > 0;

            try
            {
                SnmpTarget.DefaultTimeout = 10000;
                SnmpTarget.DefaultRetries = 2;

                using (Snmp snmp = new Snmp(false))
                {
                    UdpAddress  udp       = new UdpAddress(ip);
                    SnmpVersion ver       = SnmpVersion.SNMPv1;
                    CTarget     target    = new CTarget(udp, ver, community, community);
                    Oid         systemOid = (Oid)SYSOID2NAME_["system"];
                    Vb          vb        = new Vb(systemOid);
                    Pdu         pdu       = new Pdu(PduType.GetNext, vb);
                    while (true)
                    {
                        if (debug)
                        {
                            Console.WriteLine("Sending : " + pdu + " to " + target);
                        }

                        Pdu resp = snmp.Invoke(pdu, target);

                        if (debug)
                        {
                            Console.WriteLine("Received: " + resp);
                        }

                        vb = resp[0];
                        Oid oid = vb.Oid;
                        if (!oid.StartsWith(systemOid))
                        {
                            break;
                        }

                        SnmpSyntax val = vb.Value;
                        Console.WriteLine("{0}({1}): {2} ({3})",
                                          oid, SYSOID2NAME_[oid], val, val.SmiSyntax);

                        pdu = pdu.Clone(vb);
                    }
                }
            }
            catch (SnmpException e)
            {
                Console.WriteLine("SnmpException:"
                                  + "\nstatus : " + e.ErrorStatus
                                  + "\nindex  : " + e.ErrorIndex
                                  + "\nmessage: " + e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        // Function to Draw the Game in it's current state to the Back Buffer
        private void DrawGame(float fTimeSinceLastUpdateInSeconds, Graphics cBackBuffer)
        {
            // Brush and Pen to draw with
            Brush cBrush;
            Pen   cPen;

            // Clear the screen to Black
            cBackBuffer.Clear(Color.Black);

            // Loop though all Targets in the Target List
            int iTargetIndex     = 0;
            int iNumberOfTargets = mcTargetList.Count;

            for (iTargetIndex = 0; iTargetIndex < iNumberOfTargets; iTargetIndex++)
            {
                // Save a handle to this Target for readability
                CTarget cTarget = mcTargetList[iTargetIndex];

                // Rectangle used to draw Target to the screen
                Rectangle rRect = new Rectangle((int)cTarget.rRect.X, (int)cTarget.rRect.Y, (int)cTarget.rRect.Width, (int)cTarget.rRect.Height);

                // If the Target is Facing Left
                if (cTarget.bFacingLeft)
                {
                    // Draw this Target to the screen facing Left
                    cBackBuffer.DrawImage(mcTargetFacingLeftImage, rRect, 0, 0, mcTargetFacingLeftImage.Width, mcTargetFacingLeftImage.Height, GraphicsUnit.Pixel, mcTargetImageAttributes);
                }
                // Else the Target is Facing Right
                else
                {
                    // Draw this Target to the screen facing Right
                    cBackBuffer.DrawImage(mcTargetFacingRightImage, rRect, 0, 0, mcTargetFacingLeftImage.Width, mcTargetFacingLeftImage.Height, GraphicsUnit.Pixel, mcTargetImageAttributes);
                }
            }

            // Draw the Pitch Meter
            mcPitchMeter.AutoDetectPitchAndUpdateMeter();
            mcPitchMeter.Draw(cBackBuffer);

            // Draw the area in which the Targets can be "hit"
            cPen = new Pen(Color.White);
            cBackBuffer.DrawRectangle(cPen, miSHOOT_TARGET_AREA_LEFT, miSHOOT_TARGET_AREA_TOP, (miSHOOT_TARGET_AREA_RIGHT - miSHOOT_TARGET_AREA_LEFT), (miSHOOT_TARGET_AREA_BOTTOM - miSHOOT_TARGET_AREA_TOP));

            // Display to press Space Bar to Pause the game
            cBrush = new SolidBrush(Color.LightBlue);
            cBackBuffer.DrawString("Pause - Space Bar", mcFontText, cBrush, 475, 530);

            // Display to press R to Restart the game
            cBackBuffer.DrawString("Restart - R", mcFontText, cBrush, 150, 530);

            // Display the players Score
            cBackBuffer.DrawString("Score " + miScore, mcFontText, cBrush, 10, 10);

            // Display the instructions
            cBackBuffer.DrawString("Try and hit as many ducks as possible", mcFontText, cBrush, 190, 10);

            // If the Song is still loading
            if (mcWindowsMediaPlayer.status == "Connecting...")
            {
                cBackBuffer.DrawString("Loading Tune", mcFontChooseMusicTitle, cBrush, 230, 200);
            }

            // Clean up the Brush and Pen resources
            cBrush.Dispose();
            cPen.Dispose();
        }
        // Function to Update all of the Game Objects
        private void UpdateGameObjects(float fTimeSinceLastUpdateInSeconds, Graphics cBackBuffer)
        {
            // Loop through Midi Data and create new Targets if necessary
            int iMidiIndex         = 0;
            int iNumberOfMidiNotes = CMidiInput.Instance().cMidiInfoList.Count;

            for (iMidiIndex = 0; iMidiIndex < iNumberOfMidiNotes; iMidiIndex++)
            {
                // Create a handle to the current Midi Info for readability
                CMidiInfo cMidiInfo = CMidiInput.Instance().cMidiInfoList[iMidiIndex];

                // Filter Midi Notes based on which Music is playing
                // If this Midi Note is not on the Channel we want
                if (cMidiInfo.iChannel != mcCurrentMusic.iChannelToUse && cMidiInfo.iChannel > 0)
                {
                    // Move to the next Midi Note (only keep Notes on the desired Channel)
                    continue;
                }

                // Create a new Target
                CTarget cNewTarget = new CTarget();

                // Specify Target Width and Height
                cNewTarget.rRect.Width  = 70;
                cNewTarget.rRect.Height = 80;

                // Determine which Row the Target should be in
                // If it should be in the bottom Row
                if (cMidiInfo.iNote < mcCurrentMusic.iLowPitchCeiling)
                {
                    cNewTarget.rRect.Y = miBOTTOM_ROW_Y;
                }
                // Else if it should be in the middle Row
                else if (cMidiInfo.iNote < mcCurrentMusic.iMiddlePitchCeiling)
                {
                    cNewTarget.rRect.Y = miMIDDLE_ROW_Y;
                }
                // Else it should be in the top Row
                else
                {
                    cNewTarget.rRect.Y = miTOP_ROW_Y;
                }

                // Calculate the Targets velocity based on the Midi Note's Velocity
                cNewTarget.sVelocity.X = cMidiInfo.iVelocity + 140;
                cNewTarget.sVelocity.Y = 0.0f;

                // 50/50 chance of Target approaching from left/right side
                bool bApproachFromRight = (mcRandom.Next(0, 2) == 0) ? true : false;
                bApproachFromRight = false;

                // If this Target is approaching from the Right
                if (bApproachFromRight)
                {
                    // Reverse it's X Velocity
                    cNewTarget.sVelocity.X = -cNewTarget.sVelocity.X;

                    // Record that it should be Facing Left
                    cNewTarget.bFacingLeft = true;
                }

                // Save the Targets Starting Velocity
                cNewTarget.sStartingVelocity = cNewTarget.sVelocity;

                // Calculate the Time when the Target should reach the center of the screen
                cNewTarget.cTimeToBeAtCenter = cMidiInfo.cTime.AddSeconds(3.0);

                // Calculate how long between the current Time and the time the target
                // should be in the middle of the screen
                TimeSpan cTimeSpanToReachCenter = cNewTarget.cTimeToBeAtCenter - DateTime.Now;
                float    fTimeToReachCenter     = (float)(cTimeSpanToReachCenter.TotalMilliseconds / 1000.0f);

                // Calculate where it should be placed to reach the middle of the screen at the desired time
                cNewTarget.rRect.X = (int)(miCENTER_OF_SCREEN_X - (cNewTarget.sVelocity.X * fTimeToReachCenter)) + (cNewTarget.rRect.Width / 2.0f);

                // Add the new Target to the Target List
                mcTargetList.Add(cNewTarget);
            }

            // Temp variable to keep track of which Row the Players Pitch is in
            ETargetRows ePlayersPitchRow;

            // If the Player is making a sound
            if (CSoundInput.Instance().bInputReceived)
            {
                // If the Song is not still loading
                if (mcWindowsMediaPlayer.status != "Connecting...")
                {
                    // Duduct from their Score (so they don't make sounds the whole time)
                    miScore--;
                }

                // Save which Row their Pitch corresponds to
                // If the Pitch corresponds to the Bottom Row
                if (CSoundInput.Instance().fPitch < CSoundInput.Instance().iOneThirdOfPitchRange)
                {
                    ePlayersPitchRow = ETargetRows.Bottom;
                }
                // Else if the Pitch corresponds to the Middle Row
                else if (CSoundInput.Instance().fPitch < CSoundInput.Instance().iTwoThirdsOfPitchRange)
                {
                    ePlayersPitchRow = ETargetRows.Middle;
                }
                // Else the Pitch corresponds to the Top Row
                else
                {
                    ePlayersPitchRow = ETargetRows.Top;
                }
            }
            // Else no input was recieved
            else
            {
                ePlayersPitchRow = ETargetRows.None;
            }

            // Loop though all Targets in the Target List
            int iTargetIndex     = 0;
            int iNumberOfTargets = mcTargetList.Count;

            for (iTargetIndex = 0; iTargetIndex < iNumberOfTargets; iTargetIndex++)
            {
                // Save a handle to this Target for readability
                CTarget cTarget = mcTargetList[iTargetIndex];

                // Make sure the Targets Velocity will still put them at the
                // center of the screen at the correct time

                // If this target has not passed the middle of the screen yet
                if (cTarget.cTimeToBeAtCenter > DateTime.Now)
                {
                    // Calculate how long between the current Time and the time the target
                    // should be in the middle of the screen
                    TimeSpan cTimeSpanToReachCenter = cTarget.cTimeToBeAtCenter - DateTime.Now;
                    float    fTimeToReachCenter     = (float)(cTimeSpanToReachCenter.TotalMilliseconds / 1000.0f);

                    // Calculate the Distance this Target is from the Center of the screen
                    float fDistanceToCenter = miCENTER_OF_SCREEN_X - (cTarget.rRect.X + (cTarget.rRect.Width / 2.0f));

                    // Calculate where it should be placed to reach the middle of the screen at the desired time
                    cTarget.sVelocity.X = fDistanceToCenter / fTimeToReachCenter;

                    // If the Velocity should be negative and it isn't, or it should be positive and it isn't
                    if ((cTarget.sStartingVelocity.X < 0.0f && cTarget.sVelocity.X > 0.0f) ||
                        (cTarget.sStartingVelocity.X > 0.0f && cTarget.sVelocity.X < 0.0f))
                    {
                        // Make the Velocity
                        cTarget.sVelocity.X *= -1;
                    }
                }
                // Else it has passed the middle of the screen
                else
                {
                    // So make sure it is using it's original velocity
                    cTarget.sVelocity = cTarget.sStartingVelocity;
                }

                // Update the Position of this Target
                cTarget.rRect.X += (cTarget.sVelocity.X * fTimeSinceLastUpdateInSeconds);
                cTarget.rRect.Y += (cTarget.sVelocity.Y * fTimeSinceLastUpdateInSeconds);

                // Store which Row this Target is in
                ETargetRows eTargetRow;

                // If the Target is in the Top Row
                if (cTarget.rRect.Y == miTOP_ROW_Y)
                {
                    eTargetRow = ETargetRows.Top;
                }
                // Else if the Target is in the Middle Row
                else if (cTarget.rRect.Y == miMIDDLE_ROW_Y)
                {
                    eTargetRow = ETargetRows.Middle;
                }
                // Else the Target is in the Bottom Row
                else
                {
                    eTargetRow = ETargetRows.Bottom;
                }

                // Calculate the middle position of the Target
                float fMiddlePosition = cTarget.rRect.X + (cTarget.rRect.Width / 2.0f);

                // If the Player is making a Pitch correspond to the Row this Target is in
                // AND the Target is in the shooting area
                if (ePlayersPitchRow == eTargetRow &&
                    fMiddlePosition >= miSHOOT_TARGET_AREA_LEFT && fMiddlePosition <= miSHOOT_TARGET_AREA_RIGHT)
                {
                    // Give the Player some Points for hitting this Target
                    miScore += 25;

                    // Kill this Target by moving it off the screen
                    cTarget.rRect.X += (cTarget.sVelocity.X * 10.0f);
                }
            }

            // Remove all Targets from the List which have moved off the screen
            mcTargetList.RemoveAll(delegate(CTarget cTarget)
            {
                // Return if the Target has moved off the screen or not yet
                return((cTarget.sVelocity.X > 0.0f && cTarget.rRect.X > 800) ||
                       (cTarget.sVelocity.X < 0.0f && (cTarget.rRect.X + cTarget.rRect.Width) < 0));
            });

            // If the Song is finished playing
            if (mcWindowsMediaPlayer.status == "Stopped")
            {
                // Sum the amount of time passed since the song finished playing
                mfSecondsSongHasBeenCompleteFor += fTimeSinceLastUpdateInSeconds;

                // If the Song has been finished for 7 seconds
                if (mfSecondsSongHasBeenCompleteFor >= 7.0f)
                {
                    // Check which Song is being played
                    switch (mcCurrentMusic.eMusic)
                    {
                    default:
                    case EMusic.Simple:
                        // Save the Players Score if it's better than their old one
                        if (miScore > CProfiles.Instance().mcCurrentProfile.iScoreShootingGallerySong1)
                        {
                            // Save the Players new High Score
                            CProfiles.Instance().mcCurrentProfile.iScoreShootingGallerySong1 = miScore;
                            CProfiles.Instance().SaveProfilesToFile();
                        }
                        break;

                    case EMusic.DansMario:
                        // Save the Players Score if it's better than their old one
                        if (miScore > CProfiles.Instance().mcCurrentProfile.iScoreShootingGallerySong2)
                        {
                            // Save the Players new High Score
                            CProfiles.Instance().mcCurrentProfile.iScoreShootingGallerySong2 = miScore;
                            CProfiles.Instance().SaveProfilesToFile();
                        }
                        break;

                    case EMusic.Mario:
                        // Save the Players Score if it's better than their old one
                        if (miScore > CProfiles.Instance().mcCurrentProfile.iScoreShootingGallerySong3)
                        {
                            // Save the Players new High Score
                            CProfiles.Instance().mcCurrentProfile.iScoreShootingGallerySong3 = miScore;
                            CProfiles.Instance().SaveProfilesToFile();
                        }
                        break;
                    }

                    // Restart the game
                    Reset();
                }
            }
        }
Beispiel #6
0
 private void Start()
 {
     // Setting up the references.
     _targetScript = CTargetManager._instance.GetRandomTarget().GetComponent <CTarget>();
 }