コード例 #1
0
ファイル: DerpManager.cs プロジェクト: GoodSky/game-nuggets
        // Very similar to the above, but takes in a point and searches all derps
        // We return a pointer to the poor soul or null if none are in range
        public Derp SearchForDerp(int x, int y, double range)
        {
            // return null if there is no collision
            Derp   ret     = null;
            double mindist = range * range;

            // check against all other enemy derps
            foreach (Derp o in homeDerps)
            {
                myVector toOther = new myVector(o.x - x, o.y - y);

                if (toOther.mag2() < mindist)
                {
                    mindist = toOther.mag2();
                    ret     = o;
                }
            }

            foreach (Derp o in awayDerps)
            {
                myVector toOther = new myVector(o.x - x, o.y - y);

                if (toOther.mag2() < mindist)
                {
                    mindist = toOther.mag2();
                    ret     = o;
                }
            }

            // the unlucky nearest visible enemy
            return(ret);
        }
コード例 #2
0
        // DRAW
        // Draw the Base Image First and then draw the Accessories over top
        public void Draw(SpriteBatch spriteBatch, Rectangle camera)
        {
            // Which direction frame to draw
            int frameID = 0;

            if (vel.mag2() > 1e-6)
            {
                frameID = Geometry.GetNearestCardinalDir(vel);
            }
            else
            {
                frameID = lastDir;
            }

            lastDir = frameID;

            // Which step in the animation are we on
            int stepID = lastStep;

            spriteBatch.Draw(baseTexture, new Rectangle((int)(x - camera.X - baseOffset.offsetX), (int)(y - camera.Y - baseOffset.offsetY), baseOffset.width, baseOffset.height),
                             new Rectangle(stepID * baseOffset.width, frameID * baseOffset.height, baseOffset.width, baseOffset.height), Color.White);

            // DEBUG:
            //if (isStuck)
            //{
            //    spriteBatch.DrawString(GUI.smallFont, "X", new Vector2((float)(x - camera.X - 6), (float)(y - 10)), Color.Red);
            //}
        }
コード例 #3
0
ファイル: DerpManager.cs プロジェクト: GoodSky/game-nuggets
        // Search for enemy derps within our radar range
        // We return a pointer to the poor soul or null if none are in range
        public Derp SearchForEnemy(Derp d, double range)
        {
            // return null if there is no collision
            Derp ret = null;

            // For collision we are checking only against our enemies
            List <Derp> checkingList;

            if (d.team == TEAM.HOME)
            {
                checkingList = awayDerps;
            }
            else
            {
                checkingList = homeDerps;
            }

            double mindist = range * range;

            // check against all other enemy derps
            double        throwaway1;
            myLineSegment throwaway2;

            foreach (Derp o in checkingList)
            {
                myVector toOther = new myVector(o.x - d.x, o.y - d.y);

                if (toOther.mag2() < mindist && !Field.field.CheckFieldCollision(d, toOther, out throwaway1, out throwaway2))
                {
                    mindist = toOther.mag2();
                    ret     = o;
                }
            }

            // the unlucky nearest visible enemy
            return(ret);
        }