Esempio n. 1
0
        public override void Update(float dt)
        {
            _gameModel.TargetPoint = _gameModel.FoodModel.Position;
            _gameModel.BugModel.Update(dt);

            if (Mathematics.Distance(_gameModel.BugModel.Position, _gameModel.FoodModel.Position) < _foodThreshold)
            {
                _gameModel.SetFood();
            }
        }
Esempio n. 2
0
        public static double CalcAngle(Position aPos, Position bPos, Position cPos)
        {
            var a = Mathematics.Distance(aPos, cPos);
            var b = Mathematics.Distance(aPos, bPos);
            var c = Mathematics.Distance(bPos, cPos);

            var angle = Mathematics.Angle(a, b, c);

            return(angle);
        }
        private List <Shadow> CreateShadows(List <IGameObject> field, Position player, int dist)
        {
            var blocks = field.Where(elem => elem.Type == ObjectType.Block)
                         .OrderBy(block => Mathematics.Distance(block.Centre, player));

            var shadows = new List <Shadow>();

            foreach (var block in blocks)
            {
                var shadow = Algorithms.CreateShadow(player, block as Block, dist);
                if (shadow != null)
                {
                    shadows.Add(shadow);
                }
            }
            return(shadows);
        }
        private static bool PreciseСalculationCollision(Block block, IRound obj, Position newCentre)
        {
            var location = FindRelativeLocation(block, newCentre);

            if (location == Location.Inside)
            {
                return(true);
            }

            if (location == Location.Top || location == Location.Bottom)
            {
                var diff = Math.Abs(block.Centre.Y - newCentre.Y) - obj.Radius - block.Height / 2;
                return(diff < 0);
            }
            else if (location == Location.MiddleLeft || location == Location.MiddleRight)
            {
                var diff = Math.Abs(block.Centre.X - newCentre.X) - obj.Radius - block.Width / 2;
                return(diff < 0);
            }
            else if (location == Location.TopLeft)
            {
                var cornerPos = new Position(block.Centre.X - block.Width / 2, block.Centre.Y - block.Height / 2);
                var diff      = Mathematics.Distance(cornerPos, newCentre) - obj.Radius;
                return(diff < 0);
            }
            else if (location == Location.TopRight)
            {
                var cornerPos = new Position(block.Centre.X + block.Width / 2, block.Centre.Y - block.Height / 2);
                var diff      = Mathematics.Distance(cornerPos, newCentre) - obj.Radius;
                return(diff < 0);
            }
            else if (location == Location.BottomRight)
            {
                var cornerPos = new Position(block.Centre.X + block.Width / 2, block.Centre.Y + block.Height / 2);
                var diff      = Mathematics.Distance(cornerPos, newCentre) - obj.Radius;
                return(diff < 0);
            }
            else if (location == Location.BottomLeft)
            {
                var cornerPos = new Position(block.Centre.X - block.Width / 2, block.Centre.Y + block.Height / 2);
                var diff      = Mathematics.Distance(cornerPos, newCentre) - obj.Radius;
                return(diff < 0);
            }
            return(false);
        }
Esempio n. 5
0
        public void UpdateEnemies(float dt)
        {
            bool bugIsCaught = false;

            foreach (EnemyModel enemyModel in _enemyList)
            {
                float distance = Mathematics.Distance(enemyModel.Position, BugModel.Position);
                enemyModel.Excitement = Math.Max(0, (_enemyExcitementThreshold - distance) / _enemyExcitementThreshold);
                enemyModel.Update(dt);
                if (distance < 15)
                {
                    bugIsCaught = true;
                }
            }
            if (!IsGameOver)
            {
                if (bugIsCaught && GameOver != null)
                {
                    IsGameOver = true;
                    GameOver(this, null);
                }
            }
        }