示例#1
0
        public override void Initialize()
        {
            base.Initialize();

            //Debug map generation frim mapTest.dat (This is not how the map will work later)
            //Filling outer walls
            for (int i = 0; i < FIELD_WIDTH; i++)
            {
                background[0, i] = 2;
                background[FIELD_HEIGHT - 1, i] = 2;
            }
            for (int i = 1; i < FIELD_HEIGHT - 1; i++)
            {
                background[i, 0] = 2;
                background[i, FIELD_WIDTH - 1] = 2;
            }
            //Reading map file
            try
            {
                using (StreamReader sr = new StreamReader(@"MapFiles/mapTest.dat"))
                {
                    //For each row of the field
                    for (int i = 1; i < FIELD_HEIGHT - 1; i++)
                    {
                        String line = sr.ReadLine();
                        //For each character in the row
                        for (int j = 0; j < line.Length; j++)
                        {
                            //The row is shifted right one to fit within the outer walls
                            background[i, j + 1] = line[j] - '0';
                        }
                    }

                }
            } catch (Exception e)
            {
                //Later, load a default map (empty?) when map data is missing
                Console.WriteLine("The map data could not be read:");
                Console.WriteLine(e.Message);
            }
            // Create test game object
            rogueBot = new RogueBot(100, 100);
            box = new GameObject(200, 250, 50, 50);
        }
示例#2
0
 // Check for collisions with another object
 public bool Overlap(GameObject o)
 {
     return (x + width >= o.x && x <= o.x + o.width && y + height >= o.y && y <= o.y + o.width);
 }