Example #1
0
        public override void Move(List <Draw> solid)
        {
            switch (navigator)
            {
            case Player.Navigator.Up:
                source = look_up;
                foreach (Draw d in solid)
                {
                    if (location.y - 1 == d.location.y && location.x == d.location.x)
                    {
                        if (d is Wall || d is Door)
                        {
                            //Moves player back down if hitting wall
                            navigator        = Player.Navigator.Down;
                            movement_counter = 0;
                            Move(solid);
                        }
                    }
                }

                --location.y;
                ++movement_counter;
                SpriteManager();
                if (movement_counter == 4)
                {
                    movement_counter = 0;
                    navigator        = Player.Navigator.Down;
                }

                break;

            case Player.Navigator.Down:
                source = look_down;
                foreach (Draw d in solid)
                {
                    if (location.y + 1 == d.location.y && location.x == d.location.x)
                    {
                        if (d is Wall || d is Door)
                        {
                            //Moves player back down if hitting wall
                            navigator        = Player.Navigator.Up;
                            movement_counter = 0;
                            Move(solid);
                        }
                    }
                }
                ++location.y;
                ++movement_counter;
                SpriteManager();
                if (movement_counter == 4)
                {
                    movement_counter = 0;
                    navigator        = Player.Navigator.Up;
                }

                break;

            case Player.Navigator.Left:
                source = look_left;
                foreach (Draw d in solid)
                {
                    if (location.y == d.location.y && location.x - 1 == d.location.x)
                    {
                        if (d is Wall || d is Door)
                        {
                            //Moves player back down if hitting wall
                            navigator        = Player.Navigator.Right;
                            movement_counter = 0;
                            Move(solid);
                        }
                    }
                }
                --location.x;
                ++movement_counter;
                SpriteManager();
                if (movement_counter == 4)
                {
                    movement_counter = 0;
                    navigator        = Player.Navigator.Right;
                }

                break;

            case Player.Navigator.Right:
                source = look_right;
                foreach (Draw d in solid)
                {
                    if (location.y == d.location.y && location.x + 1 == d.location.x)
                    {
                        if (d is Wall || d is Door)
                        {
                            //Moves player back down if hitting wall
                            navigator        = Player.Navigator.Left;
                            movement_counter = 0;
                            Move(solid);
                        }
                    }
                }
                ++location.x;
                ++movement_counter;
                SpriteManager();
                if (movement_counter == 4)
                {
                    movement_counter = 0;
                    navigator        = Player.Navigator.Left;
                }

                break;
            }
        }
Example #2
0
        public List <Draw> Import(string f_name, Boolean putFloor)
        {
            XmlDocument document = new XmlDocument();

            document.Load("../../Resources/" + f_name + ".xml");
            //document.Load(@"../../Resources/Floor01.xml");

            List <Draw> map       = new List <Draw>();
            List <Draw> drawables = new List <Draw>();

            hostiles = new List <Hostile>();

            //Spawn XML
            foreach (XmlNode node in document.SelectNodes("MAP/SPAWNPOINT"))
            {
                int x = int.Parse(node["X"].InnerText);
                int y = int.Parse(node["Y"].InnerText);
                spawn = new SpawnPoint(x, y);

                drawables.Add(spawn);
            }

            //EndPoint XML
            foreach (XmlNode node in document.SelectNodes("MAP/ENDPOINT"))
            {
                int  x        = int.Parse(node["X"].InnerText);
                int  y        = int.Parse(node["Y"].InnerText);
                Draw endPoint = new EndPoint(x, y);

                drawables.Add(endPoint);
            }

            //Wall XML
            foreach (XmlNode node in document.SelectNodes("MAP/WALL"))
            {
                int  x    = int.Parse(node["X"].InnerText);
                int  y    = int.Parse(node["Y"].InnerText);
                Wall wall = new Wall(x, y);

                drawables.Add(wall);
            }

            //Key XML
            foreach (XmlNode node in document.SelectNodes("MAP/KEY"))
            {
                Door door = null;
                foreach (XmlNode door_node in node.SelectNodes("DOOR"))
                {
                    int    xD        = int.Parse(door_node["X"].InnerText);
                    int    yD        = int.Parse(door_node["Y"].InnerText);
                    string door_name = door_node["NAME"].InnerText;
                    door = new Door(xD, yD, door_name);
                    Debug.WriteLine("Added door to the list and xD/xY: " + xD + "/" + yD);
                    drawables.Add(door);
                    break;
                }
                int x   = int.Parse(node["X"].InnerText);
                int y   = int.Parse(node["Y"].InnerText);
                Key key = new Key(x, y, door);

                drawables.Add(key);
            }

            //Duck XML
            foreach (XmlNode node in document.SelectNodes("MAP/HOSTILE"))
            {
                int              x          = int.Parse(node["X"].InnerText);
                int              y          = int.Parse(node["Y"].InnerText);
                string           enemy_name = node["NAME"].InnerText;
                Player.Navigator navigator  = Player.Navigator.Up;

                if (enemy_name == "Duck")
                {
                    string facing = node["FACING"].InnerText;
                    switch (facing.ToLower())
                    {
                    case "up":
                        navigator = Player.Navigator.Up;
                        break;

                    case "down":
                        navigator = Player.Navigator.Down;
                        break;

                    case "left":
                        navigator = Player.Navigator.Left;
                        break;

                    case "right":
                        navigator = Player.Navigator.Right;
                        break;
                    }
                    Hostile hostile = new Duck(x, y, navigator);
                    hostiles.Add(hostile);
                }
            }

            //Add enemies to drawables
            drawables.AddRange(hostiles);

            if (putFloor)
            {
                bool has = false;
                for (int x = 0; x < 40; x++)
                {
                    int xy = 0;
                    for (int y = 0; y < 20; y++)
                    {
                        has = false;

                        foreach (Draw d in drawables)
                        {
                            if ((d.location.x) == x && (d.location.y) == y && d is Wall)
                            {
                                has = true;
                            }

                            xy = y;
                        }
                        if (!has)
                        {
                            map.Add(new Floor(x, xy));
                        }
                    }
                }
            }

            map.AddRange(drawables);
            return(map);
        }
Example #3
0
 public Duck(int position_X, int position_Y, Player.Navigator navigator) : base(position_X, position_Y, Properties.Resources.kks_down_1)
 {
     this.navigator = navigator;
     SetSource();
 }