예제 #1
0
        // Add an attack Animation here
        // TODO: maybe put the thing that actually applies the damage here, just to consolodate logical code
        public void AddAttack(Derp from, Derp to)
        {
            // This must be located two radius distance from the derp, in the direction of the delivering attacker
            myVector u = new myVector(from.x - to.x, from.y - to.y);

            u.toUnit();

            // opposite direction for nearest cardinal dir calculation
            myVector u2 = new myVector(-u.x, -u.y);

            DerpAttack attack = new DerpAttack(to.x + (u.x * to.stats.radius * 2), to.y + (u.y * to.stats.radius * 2), Geometry.GetNearestCardinalDir(u2));

            derpAttacks.Add(attack.key, attack);
        }
예제 #2
0
        public void Draw(SpriteBatch spriteBatch, Rectangle camera)
        {
            // Draw all Derps
            // First Step, sort both Team Lists of Derps by Y position, then continually draw the lower Y value first
            DerpHeightSorter dHS = new DerpHeightSorter();

            homeDerps.Sort(dHS);
            awayDerps.Sort(dHS);

            // Merge the two lists and draw each derp in order of Y Position
            int i = 0;
            int j = 0;

            while (i < homeDerps.Count || j < awayDerps.Count)
            {
                Derp d;

                // Merge
                if (i == homeDerps.Count)
                {
                    d = awayDerps[j++];
                }
                else if (j == awayDerps.Count)
                {
                    d = homeDerps[i++];
                }
                else
                {
                    if (homeDerps[i].y > awayDerps[j].y)
                    {
                        d = awayDerps[j++];
                    }
                    else
                    {
                        d = homeDerps[i++];
                    }
                }

                // Draw
                if ((d.x + d.stats.width) > camera.X && (d.x - d.stats.width) < camera.X + camera.Width)
                {
                    d.Draw(spriteBatch, camera);
                }
            }

            // Draw All of the attacks now as well
            Stack <DerpAttack> killingStack = new Stack <DerpAttack>();

            foreach (KeyValuePair <SortKey, DerpAttack> kp in derpAttacks)
            {
                kp.Value.Draw(spriteBatch, camera);

                if (!kp.Value.alive)
                {
                    killingStack.Push(kp.Value);
                }
            }

            // Cleaning up
            while (killingStack.Count > 0)
            {
                DerpAttack deadAttack = killingStack.Pop();
                derpAttacks.Remove(deadAttack.key);
            }
        }