コード例 #1
0
ファイル: WaveMap.cs プロジェクト: udovisdevoh/BlindFps
        /// <summary>
        /// Returns matter type at specified coordinates, null if empty space
        /// </summary>
        /// <param name="x">x</param>
        /// <param name="y">y</param>
        /// <returns>matter type at specified coordinates, null if empty space</returns>
        public override AbstractMatterType GetMatterTypeAt(double x, double y)
        {
            AbstractMatterType hardCodedMatterType = hardCodedMap.GetMatterTypeAt(x, y);

            if (hardCodedMatterType == null)
            {
                return(null);
            }

            x += waveX[Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2))];
            y += waveY[Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2))];

            while (x < 0)
            {
                x += hardCodedMap.Width;
            }
            while (x >= hardCodedMap.Width)
            {
                x -= hardCodedMap.Width;
            }
            while (y < 0)
            {
                y += hardCodedMap.Height;
            }
            while (y >= hardCodedMap.Height)
            {
                y -= hardCodedMap.Height;
            }

            return(hardCodedMap.GetMatterTypeAt(x, y));
        }
コード例 #2
0
ファイル: ImageCache.cs プロジェクト: udovisdevoh/BlindFps
        public bool TryLoadMapCache(out AbstractMatterType[,] mapCache, int width, int height)
        {
            mapCache = null;
            FileInfo file = new FileInfo(originalFileName + fileSuffix);

            if (!file.Exists)
            {
                return(false);
            }

            AbstractMatterType wall = new MatterTypeWall();

            mapCache = new AbstractMatterType[width, height];

            int x = 0;
            int y = 0;

            using (BinaryReader binaryReader = new BinaryReader(File.Open(originalFileName + fileSuffix, FileMode.Open)))
            {
                int position = 0;
                int length   = (int)binaryReader.BaseStream.Length;

                List <bool> boolList = new List <bool>(8);
                for (int i = 0; i < 8; i++)
                {
                    boolList.Add(false);
                }

                while (position < length)
                {
                    byte byteFromFile = binaryReader.ReadByte();

                    WriteByteToBoolList(byteFromFile, boolList);

                    foreach (bool boolean in boolList)
                    {
                        if (boolean)
                        {
                            mapCache[x, y] = wall;
                        }
                        else
                        {
                            mapCache[x, y] = null;
                        }

                        x++;
                        if (x == width)
                        {
                            x = 0;
                            y++;
                        }
                    }

                    position += sizeof(byte);
                }
            }

            return(true);
        }