Exemplo n.º 1
0
        private void CheckUnitsBounces()
        {
            for (int unitIndex = 0; unitIndex < _units.Items.Count; unitIndex++)
            {
                var unitItem   = _units.Items[unitIndex];
                var moveItem   = _moves.GetById(unitItem.Id);
                var posItem    = _positions.GetById(unitItem.Id);
                var radiusItem = _radiuses.GetById(unitItem.Id);

                var radius = radiusItem.Radius;
                var pos    = posItem.Position;

                for (int otherUnitIndex = unitIndex + 1; otherUnitIndex < _units.Items.Count; otherUnitIndex++)
                {
                    var otherUnitItem = _units.Items[otherUnitIndex];

                    var otherRadiusItem = _radiuses.GetById(otherUnitItem.Id);

                    var otherPos    = _positions.GetById(otherUnitItem.Id).Position;
                    var otherRadius = otherRadiusItem.Radius;

                    var distBetweenBalls = Vector2.Distance(pos, otherPos);

                    if (distBetweenBalls < radius + otherRadius)
                    {
                        if (otherUnitItem.type == unitItem.type)
                        {
                            var otherMove = _moves.GetById(otherUnitItem.Id);

                            var direction = (pos - otherPos).normalized;

                            moveItem.moveDirection  = direction;
                            otherMove.moveDirection = direction * -1;
                        }
                        else
                        {
                            var distLack = (radius + otherRadius - distBetweenBalls) / 2f;

                            radiusItem.Radius      -= distLack;
                            otherRadiusItem.Radius -= distLack;

                            if (radiusItem.Radius < MinBallRadius ||
                                otherRadiusItem.Radius < MinBallRadius)
                            {
                                _entityToDestroyBuffer.Add(unitItem.Id);
                                _entityToDestroyBuffer.Add(otherUnitItem.Id);
                            }
                            else
                            {
                                _bounds.GetById(unitItem.Id).bound      = _gameConfig.GetBoardSqueezeRadius(radiusItem.Radius);
                                _bounds.GetById(otherUnitItem.Id).bound = _gameConfig.GetBoardSqueezeRadius(otherRadiusItem.Radius);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void DestroyUnits()
        {
            for (int i = 0; i < _entityToDestroyBuffer.Count; i++)
            {
                var entityId = _entityToDestroyBuffer[i];

                if (_entityPool.ContainsId(entityId))
                {
                    _entityPool.GetById(entityId).Destroy();
                }
            }

            _entityToDestroyBuffer.Clear();
        }
Exemplo n.º 3
0
        public void OnUpdate()
        {
            if (IsActive == false)
            {
                return;
            }

            var time = _context.services.time.GetDeltaTime();

            for (int moveIndex = 0; moveIndex < _moves.Items.Count; moveIndex++)
            {
                var moveItem = _moves.Items[moveIndex];
                var posItem  = _positions.GetById(moveItem.Id);

                var speed = moveItem.speed;

                posItem.Position += moveItem.moveDirection * speed * time;
            }
        }