示例#1
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;
                }
            }
        }
示例#2
0
 /// <summary>
 /// Impelemntacja interfejsu eteryczny, zabicie bohatera
 /// </summary>
 public void ZniszczBohatera(Map.Map map)
 {
     if (!map.GetVandal().is_immortal)
     {
         map.vandal.is_alive = false;
     }
 }
示例#3
0
 public void Zabij(Map.Map map)
 {
     if (!map.GetVandal().is_immortal)
     {
         map.vandal.is_alive = false;
     }
 }
示例#4
0
        /// <summary>
        /// aktualizacja stanu Vandala
        /// </summary>
        /// <param name="gametime">czas gry</param>
        /// <param name="map">mapa obiektow</param>
        public override void Update(GameTime gametime, Map.Map map)
        {
            if (!is_immortal)
            {
                //sprawdzenie czy styka sie z wrogiem
                if (!map.GetVandal().is_immortal&&
                    map.getObject(x, y).GetType() == typeof(Characters.Enemy) || map.getObject(x, y) is Skazony)
                {
                    is_alive = false; return;
                }
            }

            LoadCurrentTexture(map);
            if (gametime.TotalGameTime.Milliseconds % 20 == 0)
            {
                switch (current_direction)
                {
                case Game.direction.down:
                    MoveInDirection(0, 1, map);
                    current_direction = Game.direction.none;
                    break;

                case Game.direction.left:
                    if (rectangle.X > 0)
                    {
                        MoveInDirection(-1, 0, map);
                    }
                    current_direction = Game.direction.none;
                    break;

                case Game.direction.right:
                    MoveInDirection(1, 0, map);
                    current_direction = Game.direction.none;
                    break;

                case Game.direction.up:
                    if (rectangle.Y > 0)
                    {
                        MoveInDirection(0, -1, map);
                    }
                    current_direction = Game.direction.none;
                    break;

                default:
                    MoveInDirection(0, 0, map);
                    current_direction = Game.direction.none;
                    break;
                }
            }
        }
示例#5
0
        /// <summary>
        /// Poruszanie w wyznaczonym kierunku
        /// </summary>
        /// <param name="add_x">przyrost indeksu w poziomie</param>
        /// <param name="add_y">przyrost indeksu w pionie</param>
        /// <param name="map">mapa obiektow</param>
        public void MoveInDirection(int add_x, int add_y, Map.Map map)
        {
            int new_x = x + add_x;
            int new_y = y + add_y;

            collision_obj = map.getObject(new_x, new_y);
            if (collision_obj.IsAccesible)
            {
                if (collision_obj is Weapon.Weapon)
                {
                    (collision_obj as Weapon.Weapon).OnFound(map);
                }

                if (collision_obj is Zniszczalny)
                {
                    (collision_obj as Zniszczalny).OnDestroy(map);
                }



                map.setObject(new_x, new_y, this);
                if (!(collision_obj is Eteryczny))
                {
                    map.setObject(x, y, new NonDestroyableObjects.Puste(content, new Rectangle(x * this.rectangle.Width, y * this.rectangle.Height, this.rectangle.Width, this.rectangle.Height), x, y));
                }

                x = new_x;
                y = new_y;
            }
            else if (add_y == 0 && collision_obj is Przesuwalny && (collision_obj as Przesuwalny).Przesun(map, add_x))
            {
                map.setObject(x, y, new NonDestroyableObjects.Puste(content, new Rectangle(x * this.rectangle.Width, y * this.rectangle.Height, this.rectangle.Width, this.rectangle.Height), x, y));
                map.setObject(new_x, new_y, this);
                x = new_x;
                y = new_y;
            }
            else if (!map.GetVandal().is_immortal&& collision_obj.GetType().IsSubclassOf(typeof(Characters.Enemy)))
            {
                this.is_alive = false;
            }
        }
示例#6
0
        /// <summary>
        /// Aktualizacja stanu rakiety
        /// </summary>
        /// <param name="gametime">Czas gry</param>
        /// <param name="map">Mapa obiektów</param>
        public override void Update(GameTime gametime, Map.Map map)
        {
            if (gametime.TotalGameTime.Milliseconds % 20 == 0 && is_fired)
            {
                int collision_x = x;
                int collision_y = y;
                switch (direction)
                {
                case Game.direction.down:
                    texture     = content.Load <Texture2D>("Textures\\racket_down");
                    collision_x = x;
                    collision_y = y + 1;

                    break;

                case Game.direction.up:
                    texture     = content.Load <Texture2D>("Textures\\racket_up");
                    collision_x = x;
                    collision_y = y - 1;

                    break;

                case Game.direction.left:
                    texture     = content.Load <Texture2D>("Textures\\racket_left");
                    collision_x = x - 1;
                    collision_y = y;

                    break;

                case Game.direction.right:
                    texture     = content.Load <Texture2D>("Textures\\racket_right");
                    collision_x = x + 1;
                    collision_y = y;

                    break;
                }

                if (map.getObject(collision_x, collision_y).GetType() != typeof(NonDestroyableObjects.Puste) && map.getObject(collision_x, collision_y) != this)
                {
                    if (map.player.Rackets > 0)
                    {
                        map.addPlayersRacket(-1);



                        //explosion
                        SoundEffect explosion_sound = content.Load <SoundEffect>("Audio\\explosion_sound");
                        if (!map.player.AudioSettings.IsMuted)
                        {
                            SoundEffect.MasterVolume = (float)map.player.AudioSettings.SoundVolume;
                            explosion_sound.Play();
                        }
                        int vandal_x = map.GetVandal().x;
                        int vandal_y = map.GetVandal().y;

                        Map.MapObject
                            obj = map.getObject(x - 1, y - 1);
                        if (obj is Zniszczalny)
                        {
                            (obj as Zniszczalny).OnDestroy(map);
                        }
                        else if (obj.GetType().IsSubclassOf(typeof(Characters.Enemy)))
                        {
                            (obj as Characters.Enemy).Die(map);
                        }
                        obj = map.getObject(x - 1, y + 1);
                        if (obj is Zniszczalny)
                        {
                            (obj as Zniszczalny).OnDestroy(map);
                        }
                        else if (obj.GetType().IsSubclassOf(typeof(Characters.Enemy)))
                        {
                            (obj as Characters.Enemy).Die(map);
                        }
                        obj = map.getObject(x - 1, y);
                        if (obj is Zniszczalny)
                        {
                            (obj as Zniszczalny).OnDestroy(map);
                        }
                        else if (obj.GetType().IsSubclassOf(typeof(Characters.Enemy)))
                        {
                            (obj as Characters.Enemy).Die(map);
                        }
                        obj = map.getObject(x, y - 1);
                        if (obj is Zniszczalny)
                        {
                            (obj as Zniszczalny).OnDestroy(map);
                        }
                        else if (obj.GetType().IsSubclassOf(typeof(Characters.Enemy)))
                        {
                            (obj as Characters.Enemy).Die(map);
                        }
                        obj = map.getObject(x, y + 1);
                        if (obj is Zniszczalny)
                        {
                            (obj as Zniszczalny).OnDestroy(map);
                        }
                        else if (obj.GetType().IsSubclassOf(typeof(Characters.Enemy)))
                        {
                            (obj as Characters.Enemy).Die(map);
                        }
                        obj = map.getObject(x + 1, y);
                        if (obj is Zniszczalny)
                        {
                            (obj as Zniszczalny).OnDestroy(map);
                        }
                        else if (obj.GetType().IsSubclassOf(typeof(Characters.Enemy)))
                        {
                            (obj as Characters.Enemy).Die(map);
                        }
                        obj = map.getObject(x + 1, y - 1);
                        if (obj is Zniszczalny)
                        {
                            (obj as Zniszczalny).OnDestroy(map);
                        }
                        else if (obj.GetType().IsSubclassOf(typeof(Characters.Enemy)))
                        {
                            (obj as Characters.Enemy).Die(map);
                        }
                        obj = map.getObject(x + 1, y + 1);
                        if (obj is Zniszczalny)
                        {
                            (obj as Zniszczalny).OnDestroy(map);
                        }
                        else if (obj.GetType().IsSubclassOf(typeof(Characters.Enemy)))
                        {
                            (obj as Characters.Enemy).Die(map);
                        }


                        //miejsce w ktorym rakieta sie zatrzymala
                        map.setObject(x, y, new NonDestroyableObjects.Puste(content, this.rectangle, x, y));
                    }
                }
                else
                {
                    map.setObject(collision_x, collision_y, this);
                    map.setObject(x, y, new NonDestroyableObjects.Puste(content, this.rectangle, x, y));
                    this.x = collision_x;
                    this.y = collision_y;
                }
            }
        }