public EmptyMapLocationCache(AbstractMap map)
 {
     for (int x = 0; x < map.Width; x++)
     {
         for (int y = 0; y < map.Height; y++)
         {
             if (map.GetMatterTypeAt(x, y) == null)
             {
                 internalCache.Add(new Point(x, y));
             }
         }
     }
 }
示例#2
0
        /// <summary>
        /// Whether sprite is in collision with map walls
        /// </summary>
        /// <param name="sprite">sprite</param>
        /// <param name="map">map</param>
        /// <returns>Whether sprite is in collision with map walls</returns>
        public static bool IsDetectMapCollision(AbstractSprite sprite, AbstractMap map)
        {
            double currentRadius = sprite.Radius;

            do
            {
                if (sprite.PositionX < 0 || sprite.PositionY < 0 || sprite.PositionX >= map.Width || sprite.PositionY >= map.Height)
                {
                    return(true);
                }
                else if (map.GetMatterTypeAt(sprite.PositionX - sprite.Radius, sprite.PositionY - sprite.Radius) != null)
                {
                    return(true);
                }
                else if (map.GetMatterTypeAt(sprite.PositionX, sprite.PositionY - sprite.Radius) != null)
                {
                    return(true);
                }
                else if (map.GetMatterTypeAt(sprite.PositionX + sprite.Radius, sprite.PositionY - sprite.Radius) != null)
                {
                    return(true);
                }
                else if (map.GetMatterTypeAt(sprite.PositionX - sprite.Radius, sprite.PositionY) != null)
                {
                    return(true);
                }
                else if (map.GetMatterTypeAt(sprite.PositionX + sprite.Radius, sprite.PositionY) != null)
                {
                    return(true);
                }
                else if (map.GetMatterTypeAt(sprite.PositionX - sprite.Radius, sprite.PositionY + sprite.Radius) != null)
                {
                    return(true);
                }
                else if (map.GetMatterTypeAt(sprite.PositionX, sprite.PositionY + sprite.Radius) != null)
                {
                    return(true);
                }
                else if (map.GetMatterTypeAt(sprite.PositionX + sprite.Radius, sprite.PositionY + sprite.Radius) != null)
                {
                    return(true);
                }

                currentRadius -= spriteToMapCollisionPrecision;
            } while (currentRadius > 0);

            return(false);
        }
示例#3
0
        public void Trace(AbstractHumanoid viewerSprite, double angleDegree, double rayDistanceResolution, AbstractMap map)
        {
            double xMove = Math.Cos(angleDegree / 180 * Math.PI) * rayDistanceResolution;
            double yMove = Math.Sin(angleDegree / 180 * Math.PI) * rayDistanceResolution;

            x = viewerSprite.PositionX;
            y = viewerSprite.PositionY;

            while (true)
            {
                x += xMove;
                y += yMove;

                xMove *= 1.01;
                yMove *= 1.01;

                if (x < 0 || y < 0 || x > map.Width || y > map.Height)
                {
                    break;
                }

                if (map.GetMatterTypeAt(x, y) != null)
                {
                    break;
                }
            }

            if (x < 0)
            {
                x = 0;
            }
            else if (x > map.Width)
            {
                x = map.Width - xMove;
            }

            if (y < 0)
            {
                y = 0;
            }
            else if (y > map.Height)
            {
                y = map.Height - yMove;
            }
        }
示例#4
0
        private Surface GetOrCreateMapSurface(AbstractMap map)
        {
            if (this.currentMap != map)
            {
                this.currentMap = map;
                mapSurface      = null;
            }

            if (mapSurface != null)
            {
                return(mapSurface);
            }

            int pixelWidth  = (int)Math.Ceiling((double)map.Width / precision);
            int pixelHeight = (int)Math.Ceiling((double)map.Height / precision);

            mapSurface = new Surface(pixelWidth, pixelHeight);

            int pixelLocationX = 0;

            for (double mapLocationX = 0; mapLocationX < map.Width; mapLocationX += precision)
            {
                int pixelLocationY = 0;
                for (double mapLocationY = 0; mapLocationY < map.Height; mapLocationY += precision)
                {
                    if (map.GetMatterTypeAt(mapLocationX, mapLocationY) != null)
                    {
                        if (PointLoader.IsPositionValid(pixelLocationX, pixelLocationY))
                        {
                            mapSurface.Draw(PointLoader.GetPoint(pixelLocationX, pixelLocationY), Color.Gray);
                        }
                    }
                    pixelLocationY++;
                }
                pixelLocationX++;
            }

            mapSurface.Transparent = true;

            return(mapSurface);
        }
示例#5
0
        public WaveMapCache(AbstractMap sourceMap, double precision)
        {
            this.precision = precision;
            this.width = width = (int)Math.Ceiling((double)(sourceMap.Width) / precision);
            this.height = height = (int)Math.Ceiling((double)(sourceMap.Height) / precision);

            internalCache = new AbstractMatterType[width, height];

            double sourceX = 0;
            for (int x = 0; x < this.width; x++)
            {
                double sourceY = 0;
                for (int y = 0; y < this.width; y++)
                {
                    internalCache[x, y] = sourceMap.GetMatterTypeAt(sourceX, sourceY);

                    sourceY += precision;
                }
                sourceX += precision;
            }
        }
示例#6
0
        public static bool IsSpriteViewable(AbstractSprite viewerSprite, AbstractSprite viewedSprite, AbstractMap map, int fov)
        {
            if (viewerSprite == viewedSprite)
            {
                return(true);
            }


            double angleRadian = FixAngleRadian(GetSpriteAngleToSpriteRadian(viewerSprite, viewedSprite));
            double angleDegree = FixAngleDegree(angleRadian / Math.PI * 180);


            double minimumViewingAngle = FixAngleDegree(viewerSprite.AngleDegree - (double)fov / 1.8);
            double maximumViewingAngle = FixAngleDegree(viewerSprite.AngleDegree + (double)fov / 1.8);


            if (maximumViewingAngle > minimumViewingAngle)
            {
                if (angleDegree < minimumViewingAngle)
                {
                    return(false);
                }
                if (angleDegree > maximumViewingAngle)
                {
                    return(false);
                }
            }
            else
            {
                if (angleDegree < minimumViewingAngle && angleDegree > maximumViewingAngle)
                {
                    return(false);
                }
            }

            double xMove = Math.Cos(angleRadian) * rayDistanceResolution;
            double yMove = Math.Sin(angleRadian) * rayDistanceResolution;

            double x = viewerSprite.PositionX;
            double y = viewerSprite.PositionY;

            double xDistanceToPerform = Math.Abs(viewerSprite.PositionX - viewedSprite.PositionX);
            double yDistanceToPerform = Math.Abs(viewerSprite.PositionY - viewedSprite.PositionY);



            double xDistance = 0;
            double yDistance = 0;

            while (true)
            {
                x += xMove;
                y += yMove;

                xDistance += Math.Abs(xMove);
                yDistance += Math.Abs(yMove);

                if (xDistance >= xDistanceToPerform && yDistance >= yDistanceToPerform)
                {
                    return(true);
                }

                if (map.GetMatterTypeAt(x, y) != null)
                {
                    return(false);
                }

                if (x < 0 || y < 0 || x > map.Width || y > map.Height)
                {
                    return(false);
                }
            }
        }