Exemple #1
0
        public override bool CanMove(Vector2 direction, Room room)
        {
            var collisionChecker = new CollisionChecker();

            direction.Normalize();
            var movedEnemy = new Enemy(_x + _speed * direction.X, _y + _speed * direction.Y,
                                       _width, _height, _speed, _attackSpeed, _leftTexture, _rightTexture, _shotChar, _hp, _damage,
                                       _shotSpeed, _shotRange, _name);

            if (collisionChecker.IsCollided(movedEnemy, room))
            {
                return(false);
            }

            foreach (var t in room.Enemies)
            {
                if (collisionChecker.IsCollided(movedEnemy, t) && t != this)
                {
                    return(false);
                }
            }

            if (collisionChecker.IsCollided(room.Player, movedEnemy))
            {
                return(false);
            }



            return(base.CanMove(direction, room));
        }
Exemple #2
0
        public void Run(Player player, Room room)
        {
            foreach (var t in room.Enemies)
            {
                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);
                if (distance > 0.8f*t.ShotChar.Range)
                {
                    t.Move(direction);
                }
                else
                {
                    t.Shoot(room, new Shot(t.Form.Left, t.Form.Top, direction, t));
                }
            }

            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(t, player);
                    }
                }
                foreach(var item in room.Enemies)
                {
                    if (collisionChecker.IsCollided(t, item))
                    {
                        if (t.Owner != item)
                        {
                            OnShotEnemyCollision(t, item);
                        }
                    }
                }
            }

            if (collisionChecker.IsCollided(player, room.FinishZone) && room.FinishZone.IsActive)
            {
                OnPlayerFinishZoneCollision(player, room.FinishZone);
            }

            room.Shots.RemoveAll(ShotIsRemoved);
            room.Enemies.RemoveAll(EnemyIsDead);
        }
Exemple #3
0
        public override bool CanMove(Vector2 direction, Room room)
        {
            var collisionChecker = new CollisionChecker();

            direction.Normalize();
            var movedPlayer = new Player(_x + _speed * direction.X, _y + _speed * direction.Y,
                                         _width, _height, _speed, _attackSpeed, _leftTexture, _rightTexture, _shotChar, _hp, _damage,
                                         _shotSpeed, _shotRange, _name);

            if (collisionChecker.IsCollided(movedPlayer, room))
            {
                return(false);
            }
            foreach (var t in room.Obstacles)
            {
                if (collisionChecker.IsCollided(movedPlayer, t))
                {
                    return(false);
                }
            }
            foreach (var t in room.Enemies)
            {
                if (collisionChecker.IsCollided(movedPlayer, t))
                {
                    return(false);
                }
            }

            if (room is ChallengeRoom)
            {
                var chalRoom = room as ChallengeRoom;
                foreach (var t in chalRoom.Levers)
                {
                    if (collisionChecker.IsCollided(movedPlayer, t))
                    {
                        Console.WriteLine("Collision");
                        return(false);
                    }
                }
            }
            return(base.CanMove(direction, room));
        }
Exemple #4
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.MatrixMode(MatrixMode.Modelview);
            roomDrawer.Draw(firstRoom);

            GL.PushMatrix();
            playerDrawer.Draw(player);
            GL.PopMatrix();

            roomSupervisor.Run(player, firstRoom);

            player.Controller.Control(player, firstRoom);

            if(player.Hp <= 0)
            {
                Console.WriteLine("Dog killed ypu =(");
                Exit();
            }

            var collisionChecker = new CollisionChecker();
            if(firstRoom.Enemies.Count == 0 && !collisionChecker.IsCollided(player, firstRoom.FinishZone))
            {
                firstRoom.FinishZone.IsActive = true;
            }

            SwapBuffers();
        }