Exemplo n.º 1
0
        public void Run()
        {
            var player = _room.Player;

            foreach (var t in _room.Enemies)
            {
                if (!t.IsWaiting)
                {
                    //var distance = new Vector2(player.X - t.X, player.Y - t.Y).Length;
                    //var direction = new Vector2(player.X - t.X, player.Y - t.Y);
                    ////var direction = new Vector2(t.X - player.X, t.Y - player.Y);
                    //if (direction.X < 0)
                    //{
                    //    t.TurnLeft();
                    //}
                    //if (direction.X > 0)
                    //{
                    //    t.TurnRight();
                    //}
                    //if (distance > 0.8f * t.ShotRange)
                    //{
                    //    if (t.CanMove(direction, _room))
                    //    {
                    //        t.Move(direction);
                    //    }
                    //}
                    //else
                    //{
                    //    direction = new Vector2(player.X - t.XAttack, player.YAttack - t.Y);
                    //    t.Shoot(_room, new Shot(t.XAttack, t.YAttack, direction, t));
                    //}

                    _room.EnemyControllers[t].Control();

                    if (t is Boss)
                    {
                        var bEnemy = t as Boss;
                        var bRoom  = _room as BossRoom;
                        if (bEnemy.CanUseSkill && bEnemy.Hp < bEnemy.MaxHp / 2)
                        {
                            bEnemy.UseSkill(bEnemy, bRoom);
                        }
                    }
                }
            }

            if (_room.SummonedEnemies.Count != 0)
            {
                foreach (var t in _room.SummonedEnemies)
                {
                    t.IsWaiting = false;
                    _room.Enemies.Add(t);
                }
                _room.SummonedEnemies.Clear();
            }


            foreach (var t in _room.Shots)
            {
                t.Move();
            }
            _room.Shots.RemoveAll(ShotIsRemoved);

            var collisionChecker = new CollisionChecker();

            foreach (var t in _room.Shots)
            {
                if (collisionChecker.IsCollided(t, _room))
                {
                    OnShotBorderCollision(t, _room);
                }
                if (collisionChecker.IsCollided(t, player))
                {
                    if (t.Owner.GetType() != player.GetType())
                    {
                        OnShotPlayerCollision?.Invoke(t, player);
                    }
                }
                foreach (var item in _room.Enemies)
                {
                    if (collisionChecker.IsCollided(t, item))
                    {
                        if (t.Owner != item)
                        {
                            OnShotEnemyCollision(t, item);
                        }
                    }
                }
            }

            foreach (var t in _room.Items)
            {
                if (collisionChecker.IsCollided(player, t) && t.IsAvailable)
                {
                    OnPlayerItemCollision(player, t);
                }
            }
            _room.Shots.RemoveAll(ShotIsRemoved);
            _room.Enemies.RemoveAll(EnemyIsDead);
            _room.Items.RemoveAll(ItemIsPicked);
        }
        public void Run()
        {
            //var player = _room.Players[0];
            foreach (var player in _room.Players)
            {
                foreach (var t in _room.Players)
                {
                    NetCommandBuilder.AppendToRoomCommand(player, "player_move/" + _room.Players.IndexOf(t) + "/"
                                                          + t.X + "/" + t.Y + "/" + t.Texture);
                }
            }

            foreach (var t in _room.Enemies)
            {
                if (!t.IsWaiting)
                {
                    _room.EnemyControllers[t].Control();
                    foreach (var player in _room.Players)
                    {
                        NetCommandBuilder.AppendToRoomCommand(player, "enemy_move/" + _room.Enemies.IndexOf(t) + "/"
                                                              + t.X + "/" + t.Y + "/" + t.Texture);
                    }
                    //NetCommandBuilder.AppendToRoomCommand("enemy_move/" + _room.Enemies.IndexOf(t) + "/"
                    //    +  t.X + "/" + t.Y + "/" + t.Texture);

                    //if (t is Boss)
                    //{
                    //    var bEnemy = t as Boss;
                    //    var bRoom = _room as BossRoom;
                    //    if (bEnemy.CanUseSkill && bEnemy.Hp < bEnemy.MaxHp / 2)
                    //    {
                    //        bEnemy.UseSkill(bEnemy, bRoom);
                    //    }
                    //}
                }
            }

            if (_room.SummonedEnemies.Count != 0)
            {
                foreach (var t in _room.SummonedEnemies)
                {
                    t.IsWaiting = false;
                    _room.Enemies.Add(t);
                    foreach (var player in _room.Players)
                    {
                        NetCommandBuilder.AppendToRoomCommand(player, "enemy_add/" + t.X + "/" + t.Y + "/" +
                                                              t.Form.Width + "/" + t.Form.Height + "/" + t.Texture);
                    }
                }
                _room.SummonedEnemies.Clear();
            }


            foreach (var t in _room.Shots)
            {
                t.Move();
                foreach (var player in _room.Players)
                {
                    NetCommandBuilder.AppendToRoomCommand(player, "shot_move/" + _room.Shots.IndexOf(t) + "/"
                                                          + t.X + "/" + t.Y + "/" + t.Texture);
                }
            }
            foreach (var t in _room.Shots)
            {
                if (ShotIsRemoved(t))
                {
                    foreach (var player in _room.Players)
                    {
                        NetCommandBuilder.AppendToRoomCommand(player, "shot_remove/" + _room.Shots.IndexOf(t));
                    }
                }
            }
            _room.Shots.RemoveAll(ShotIsRemoved);

            var collisionChecker = new CollisionChecker();

            foreach (var t in _room.Shots)
            {
                foreach (var player in _room.Players)
                {
                    if (collisionChecker.IsCollided(t, _room))
                    {
                        OnShotBorderCollision?.Invoke(t, _room);
                    }
                    if (collisionChecker.IsCollided(t, player))
                    {
                        if (t.Owner.GetType() != player.GetType())
                        {
                            OnShotPlayerCollision?.Invoke(t, player);
                        }
                    }
                }
                foreach (var item in _room.Enemies)
                {
                    if (collisionChecker.IsCollided(t, item))
                    {
                        if (t.Owner != item)
                        {
                            OnShotEnemyCollision?.Invoke(t, item);
                        }
                    }
                }
            }

            foreach (var t in _room.Items)
            {
                foreach (var player in _room.Players)
                {
                    if (collisionChecker.IsCollided(player, t) && t.IsAvailable)
                    {
                        OnPlayerItemCollision?.Invoke(player, t);
                    }
                }
            }
            foreach (var t in _room.Shots)
            {
                if (ShotIsRemoved(t))
                {
                    foreach (var player in _room.Players)
                    {
                        NetCommandBuilder.AppendToRoomCommand(player, "shot_remove/" + _room.Shots.IndexOf(t));
                    }
                }
            }
            _room.Shots.RemoveAll(ShotIsRemoved);
            foreach (var t in _room.Enemies)
            {
                if (EnemyIsDead(t))
                {
                    foreach (var player in _room.Players)
                    {
                        NetCommandBuilder.AppendToRoomCommand(player, "enemy_remove/" + _room.Enemies.IndexOf(t));
                    }
                }
            }
            _room.Enemies.RemoveAll(EnemyIsDead);
            _room.Items.RemoveAll(ItemIsPicked);
            //Network.NetWorker.Send(Encoding.UTF8.GetBytes(NetCommandBuilder.Command));
        }
Exemplo n.º 3
0
        public void Run(Player player, Room room)
        {
            foreach (var t in room.Enemies)
            {
                if (!t.IsWaiting)
                {
                    //var distance = new Vector2(player.X - t.X, player.Y - t.Y).Length;
                    //var direction = new Vector2(player.X - t.X, player.Y - t.Y);
                    ////var direction = new Vector2(t.X - player.X, t.Y - player.Y);
                    //if (direction.X < 0)
                    //{
                    //    t.TurnLeft();
                    //}
                    //if (direction.X > 0)
                    //{
                    //    t.TurnRight();
                    //}
                    //if (distance > 0.8f * t.ShotRange)
                    //{
                    //    if(t.CanMove(direction, room))
                    //    {
                    //        t.Move(direction);
                    //    }
                    //}
                    //else
                    //{
                    //    direction = new Vector2(player.X - t.XAttack, player.YAttack - t.Y);
                    //    t.Shoot(room, new Shot(t.XAttack, t.YAttack, direction, t));
                    //}



                    if (t is Boss)
                    {
                        var bEnemy = t as Boss;
                        var bRoom  = room as BossRoom;
                        if (bEnemy.CanUseSkill && bEnemy.Hp < bEnemy.MaxHp / 2)
                        {
                            bEnemy.UseSkill(bEnemy, bRoom);
                        }
                    }
                }
            }

            if (room.SummonedEnemies.Count != 0)
            {
                foreach (var t in room.SummonedEnemies)
                {
                    t.IsWaiting = false;
                    room.Enemies.Add(t);
                }
                room.SummonedEnemies.Clear();
            }


            foreach (var t in room.Shots)
            {
                t.Move();
            }
            room.Shots.RemoveAll(ShotIsRemoved);

            var collisionChecker = new CollisionChecker();

            foreach (var t in room.Shots)
            {
                if (collisionChecker.IsCollided(t, room))
                {
                    OnShotBorderCollision(t, room);
                }
                if (collisionChecker.IsCollided(t, player))
                {
                    if (t.Owner.GetType() != player.GetType())
                    {
                        OnShotPlayerCollision?.Invoke(t, player);
                    }
                }
                foreach (var item in room.Enemies)
                {
                    if (collisionChecker.IsCollided(t, item))
                    {
                        if (t.Owner != item)
                        {
                            OnShotEnemyCollision(t, item);
                        }
                    }
                }
            }

            foreach (var t in room.Items)
            {
                if (collisionChecker.IsCollided(player, t) && t.IsAvailable)
                {
                    OnPlayerItemCollision(player, t);
                }
            }

            if (room is BossRoom)
            {
                var bRoom = room as BossRoom;
                if (collisionChecker.IsCollided(player, bRoom.FinishZone))
                {
                    if (bRoom.FinishZone.IsActive)
                    {
                        if (bRoom.Boss.IsFinal)
                        {
                            //_game.Win();
                        }
                        else
                        {
                            _game.GoToNextLevel();
                        }
                    }
                }
            }

            if (room is ChallengeRoom)
            {
                var chalRoom = room as ChallengeRoom;
                if (collisionChecker.IsCollided(player, chalRoom.Note))
                {
                    //new TaskDrawer(_game.Textures).Draw(chalRoom.Note);
                }
            }

            room.Shots.RemoveAll(ShotIsRemoved);
            room.Enemies.RemoveAll(EnemyIsDead);
            room.Items.RemoveAll(ItemIsPicked);
        }