Beispiel #1
0
        /// <summary>
        /// Aktualizacja stanu na mapie z uwzględnieniem spadania
        /// </summary>
        /// <param name="gametime"></param>
        /// <param name="map"></param>
        public override void Update(GameTime gametime, Map.Map map)
        {
            int x_index = rectangle.X / rectangle.Width;
            int y_index = rectangle.Y / rectangle.Height;

            if (y_index == map.getHeight() - 1)
            {
                if (is_falling)
                {
                    map.setObject(x_index, y_index, this);
                    this.x = x_index;
                    this.y = y_index;
                    map.setObject(x_index, y_index - 1, new NonDestroyableObjects.Puste(content, rectangle, x_index, y_index - 1));
                    is_falling = false;
                    return;
                }
                else
                {
                    return;
                }
            }
            if (is_falling)
            {
                //nie spadl calkowice jeszcze na odpowiedni prosokat
                if (rectangle.Y % rectangle.Height != 0)
                {
                    Spadaj();
                }
                else
                {
                    map.setObject(x_index, y_index, this);
                    this.x = x_index;
                    this.y = y_index;
                    map.setObject(x_index, y_index - 1, new NonDestroyableObjects.Puste(content, rectangle, x_index, y_index - 1));
                    if (y_index < map.getHeight() - 1 && map.getObject(x_index, y_index + 1).GetType() == typeof(NonDestroyableObjects.Puste))
                    {
                        Spadaj();
                    }
                    else
                    {
                        is_falling = false;
                    }
                }
            }
            else if (map.getObject(x_index, y_index + 1).GetType() == typeof(NonDestroyableObjects.Puste) && !map.is_vandal_on_rectangle(x_index, y_index + 1))
            {//rozpoczecie spadania
                is_falling = true;
                Spadaj();
            }
            else
            {
                return;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Poruszanie - ustalenie aktualnego kierunku ruchu
        /// </summary>
        /// <param name="map">Mapa obiektów</param>
        public void Move(Map.Map map)
        {
            List <Game.direction> available_dir = new List <Game.direction>();

            if (x > 1 && map.getObject(x - 1, y).GetType() == typeof(NonDestroyableObjects.Puste))
            {
                available_dir.Add(Game.direction.left);
            }
            if (x < map.getWidth() - 1 && map.getObject(x + 1, y).GetType() == typeof(NonDestroyableObjects.Puste))
            {
                available_dir.Add(Game.direction.right);
            }
            if (y > 1 && map.getObject(x, y - 1).GetType() == typeof(NonDestroyableObjects.Puste))
            {
                available_dir.Add(Game.direction.up);
            }
            if (x < map.getHeight() - 1 && map.getObject(x, y + 1).GetType() == typeof(NonDestroyableObjects.Puste))
            {
                available_dir.Add(Game.direction.down);
            }
            if (available_dir.Capacity > 0)
            {
                int rand_dir = rand.Next(0, available_dir.Capacity - 1);
                current_direction = (Game.direction)(rand_dir);
            }
            else
            {
                current_direction = Game.direction.none;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Poruszanie - ustalenie aktualnego kierunku ruchu
        /// </summary>
        /// <param name="map">mapa obiektów</param>
        public void Move(Map.Map map)
        {
            Point p = isVandalInSight(map);

            if ((p.X != 0 && p.Y == 0) || (p.X == 0 && p.Y != 0))
            {
                //gonitwa
                move_frequency = 40;
                if ((this.x - map.GetVandal().x) < 0)
                {
                    current_direction = Game.direction.right;
                }
                else if ((this.x - map.GetVandal().x) > 0)
                {
                    current_direction = Game.direction.left;
                }
                else if ((this.y - map.GetVandal().y) > 0)
                {
                    current_direction = Game.direction.up;
                }
                else if ((this.y - map.GetVandal().y) < 0)
                {
                    current_direction = Game.direction.down;
                }
            }
            else//ruch losowy
            {
                move_frequency = 80;
                List <Game.direction> available_dir = new List <Game.direction>();
                if (x > 1 && (map.getObject(x - 1, y).GetType() == typeof(NonDestroyableObjects.Puste) || map.getObject(x - 1, y).GetType() == typeof(DestroyableObjects.Ziemia)))
                {
                    available_dir.Add(Game.direction.left);
                }
                if (x < map.getWidth() - 1 && (map.getObject(x + 1, y).GetType() == typeof(NonDestroyableObjects.Puste) || map.getObject(x + 1, y).TypeTag == Map.ElementType.ZIEMIA))
                {
                    available_dir.Add(Game.direction.right);
                }
                if (y > 1 && (map.getObject(x, y - 1).GetType() == typeof(NonDestroyableObjects.Puste) || map.getObject(x, y - 1).GetType() == typeof(DestroyableObjects.Ziemia)))
                {
                    available_dir.Add(Game.direction.up);
                }
                if (x < map.getHeight() - 1 && (map.getObject(x, y + 1).GetType() == typeof(NonDestroyableObjects.Puste) || map.getObject(x, y + 1).GetType() == typeof(DestroyableObjects.Ziemia)))
                {
                    available_dir.Add(Game.direction.down);
                }
                if (available_dir.Capacity > 0)
                {
                    int rand_dir = rand.Next(0, available_dir.Capacity - 1);
                    current_direction = (Game.direction)(rand_dir);
                }
                else
                {
                    current_direction = Game.direction.none;
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Aktualizacja stanu Ameby
        /// </summary>
        /// <param name="gametime">czas gry</param>
        /// <param name="map">mapa obiektow</param>
        public override void Update(GameTime gametime, Map.Map map)
        {
            if (create_ameba)
            {
                available_tiles = new List <Map.MapObject>();

                if (x > 0 && y > 0 && map.getObject(x - 1, y - 1) is Features.Slaby)
                {
                    available_tiles.Add(map.getObject(x - 1, y - 1));
                }
                if (x > 0 && map.getObject(x - 1, y) is Features.Slaby)
                {
                    available_tiles.Add(map.getObject(x - 1, y));
                }
                if (x > 0 && y < map.getHeight() - 1 && map.getObject(x - 1, y + 1) is Features.Slaby)
                {
                    available_tiles.Add(map.getObject(x - 1, y + 1));
                }
                if (y > 0 && map.getObject(x, y - 1) is Features.Slaby)
                {
                    available_tiles.Add(map.getObject(x, y - 1));
                }
                if (y < map.getHeight() - 1 && map.getObject(x, y + 1) is Features.Slaby)
                {
                    available_tiles.Add(map.getObject(x, y + 1));
                }
                if (x < map.getWidth() - 1 && y > 0 && map.getObject(x + 1, y - 1) is Features.Slaby)
                {
                    available_tiles.Add(map.getObject(x + 1, y - 1));
                }
                if (x < map.getWidth() - 1 && map.getObject(x + 1, y) is Features.Slaby)
                {
                    available_tiles.Add(map.getObject(x + 1, y));
                }
                if (x < map.getWidth() - 1 && y < map.getHeight() - 1 && map.getObject(x + 1, y + 1) is Features.Slaby)
                {
                    available_tiles.Add(map.getObject(x + 1, y + 1));
                }
                CreateNewAmeba(map);
                create_ameba = false;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Sprawdzenie czy punkt jest dostepny ze wzgledu na poruszanie w danym kierunku
        /// </summary>
        /// <param name="map">Mapa obiektów</param>
        /// <param name="dir">Kierunek ruchu</param>
        /// <returns>Czy jest możliwość ruchu w danym kierunku</returns>
        private bool isPointAccesible(Map.Map map, int dir)
        {
            switch ((Game.direction)dir)
            {
            case Game.direction.down:
                if (y + 1 < map.getHeight() - 1)
                {
                    if (map.getObject(x, y + 1).GetType() == typeof(NonDestroyableObjects.Puste))
                    {
                        return(true);
                    }
                }
                break;

            case Game.direction.left:
                if (x > 0)
                {
                    if (map.getObject(x - 1, y).GetType() == typeof(NonDestroyableObjects.Puste))
                    {
                        return(true);
                    }
                }

                break;

            case Game.direction.right:
                if (x + 1 < map.getWidth() - 1)
                {
                    if (map.getObject(x + 1, y).GetType() == typeof(NonDestroyableObjects.Puste))
                    {
                        return(true);
                    }
                }

                break;

            case Game.direction.up:
                if (y > 0)
                {
                    if (map.getObject(x, y - 1).GetType() == typeof(NonDestroyableObjects.Puste))
                    {
                        return(true);
                    }
                }
                break;
            }
            return(false);
        }
Beispiel #6
0
        /// <summary>
        /// Aktualizacja stanu na mapie z uwzględnieniem spadania
        /// </summary>
        /// <param name="gametime"></param>
        /// <param name="map"></param>
        public override void Update(GameTime gametime, Map.Map map)
        {
            if (explode)
            {
                if (current_frame == 16)
                {
                    die = true; explode = false;
                }
                else
                {
                    src_rectangle = new Rectangle((current_frame++) * 64, 0, 64, 64);
                }
            }
            else if (die)
            {
                map.setObject(x, y, new NonDestroyableObjects.Puste(content, this.Rectangle, x, y));
            }
            else
            {
                int x_index = rectangle.X / rectangle.Width;
                int y_index = rectangle.Y / rectangle.Height;


                //sprawdzenie wszytkich dookola pol
                if (map.is_vandal_on_rectangle(x_index - 1, y_index) ||
                    map.is_vandal_on_rectangle(x_index + 1, y_index) ||
                    map.is_vandal_on_rectangle(x_index, y_index - 1) ||
                    map.is_vandal_on_rectangle(x_index, y_index + 1) ||
                    map.is_vandal_on_rectangle(x_index - 1, y_index - 1) ||
                    map.is_vandal_on_rectangle(x_index - 1, y_index + 1) ||
                    map.is_vandal_on_rectangle(x_index + 1, y_index + 1) ||
                    map.is_vandal_on_rectangle(x_index + 1, y_index - 1))
                {
                    Zabij(map);
                    return;
                }



                if (y_index == map.getHeight() - 1)
                {
                    if (is_falling)
                    {
                        map.setObject(x_index, y_index, this);
                        this.x = x_index;
                        this.y = y_index;
                        map.setObject(x_index, y_index - 1, new NonDestroyableObjects.Puste(content, rectangle, x_index, y_index - 1));
                        is_falling = false;
                        return;
                    }
                    else
                    {
                        return;
                    }
                }
                if (is_falling)
                {
                    //nie spadl calkowice jeszcze na odpowiedni prosokat
                    if (rectangle.Y % rectangle.Height != 0)
                    {
                        Spadaj();
                    }
                    else
                    {
                        map.setObject(x_index, y_index, this);
                        this.x = x_index;
                        this.y = y_index;
                        map.setObject(x_index, y_index - 1, new NonDestroyableObjects.Puste(content, rectangle, x_index, y_index - 1));
                        if (y_index < map.getHeight() - 1 && map.getObject(x_index, y_index + 1).GetType() == typeof(NonDestroyableObjects.Puste))
                        {
                            Spadaj();
                        }
                        else
                        {
                            is_falling = false;
                        }
                    }
                }
                else if (map.getObject(x_index, y_index + 1).GetType() == typeof(NonDestroyableObjects.Puste) && !map.is_vandal_on_rectangle(x_index, y_index + 1))
                {//rozpoczecie spadania
                    is_falling = true;
                    Spadaj();
                }
                else
                {
                    return;
                }
            }
        }
        /// <summary>
        /// Aktualizacja stanu w zależności od otoczenia
        /// </summary>
        /// <param name="gametime"></param>
        /// <param name="map"></param>
        public override void Update(GameTime gametime, Map.Map map)
        {
            int x_index = rectangle.X / rectangle.Width;
            int y_index = rectangle.Y / rectangle.Height;

            //sprawdzenie wszytkich dookola pol
            if (map.is_vandal_on_rectangle(x_index - 1, y_index) ||
                map.is_vandal_on_rectangle(x_index + 1, y_index) ||
                map.is_vandal_on_rectangle(x_index, y_index - 1) ||
                map.is_vandal_on_rectangle(x_index, y_index + 1) ||
                map.is_vandal_on_rectangle(x_index - 1, y_index - 1) ||
                map.is_vandal_on_rectangle(x_index - 1, y_index + 1) ||
                map.is_vandal_on_rectangle(x_index + 1, y_index + 1) ||
                map.is_vandal_on_rectangle(x_index + 1, y_index - 1))
            {
                Zabij(map);
                return;
            }

            if (y_index == map.getHeight() - 1)
            {
                if (is_falling)
                {
                    map.setObject(x_index, y_index, this);
                    map.setObject(x_index, y_index - 1, new NonDestroyableObjects.Puste(content, rectangle, x_index, y_index - 1));
                    is_falling = false;
                    return;
                }
                else
                {
                    return;
                }
            }
            if (is_falling)
            {
                //nie spadl calkowice jeszcze na odpowiedni prosokat
                if (rectangle.Y % rectangle.Height != 0)
                {
                    Spadaj();
                }
                else
                {
                    map.setObject(x_index, y_index, this);
                    map.setObject(x_index, y_index - 1, new NonDestroyableObjects.Puste(content, rectangle, x_index, y_index - 1));
                    //pozniej zmienic na nondestroyable zamista puste
                    if (y_index < map.getHeight() - 1 && map.getObject(x_index, y_index + 1).GetType() == typeof(NonDestroyableObjects.Puste))
                    {
                        Spadaj();
                        // break;
                    }
                    else
                    {
                        is_falling = false;
                    }
                }
            }
            else if (map.getObject(x_index, y_index + 1).GetType() == typeof(NonDestroyableObjects.Puste) && !map.is_vandal_on_rectangle(x_index, y_index + 1))
            {//rozpoczecie spadania
                is_falling = true;
                Spadaj();
            }
        }