Пример #1
0
        public PEnemy GenerateRandomEnemy() {
            if (st.EnemiesConfigs.IsNullOrEmpty()) {
                Debug.LogErrorFormat("Cannot crete unit cause {0} IsNullOrEmpty", nameof(st.EnemiesConfigs));
                return null;
            }

            var enemyConfig = PRandomUtil.Select(st.EnemiesConfigs);
            if (enemyConfig == null) {
                Debug.LogErrorFormat("Cannot crete unit cause null in {0}", nameof(st.EnemiesConfigs));
                return null;
            }

            var enemyUnit = enemyConfig.Prefab.CreateUnit();
            if (enemyUnit == null) {
                Debug.LogErrorFormat("Cannot crete unit from prefab");
                return null;
            }
            
            enemyUnit.HP = enemyConfig.MaxHP;
            enemyUnit.Vulnerability = enemyConfig.Vulnerability;
            enemyUnit.MovementSpeed = enemyConfig.MovementSpeed;
            enemyUnit.RotationSpeed = enemyConfig.RotationSpeed;
            enemyUnit.Damage = enemyConfig.Damage;

            float angle = PRandomUtil.Float(0, PMathUtil.TwoPI); 
            enemyUnit.transform.position = st.EnemyGenerationCenter + PMathUtil.PolarToDecart(st.EnemyGenerationRadius, angle);
            enemyUnit.transform.rotation = Quaternion.Euler(0f, 0f, -angle.AngleToDegree());

            return enemyUnit;
        }
Пример #2
0
        private void ProcessMovement()
        {
            bool forward  = Input.GetKey(KeyCode.W);
            bool backward = Input.GetKey(KeyCode.S);

            if (forward == backward)
            {
                st.Tank.Rigidbody2D.velocity = Vector2.zero;
            }
            else if (forward)
            {
                st.Tank.Rigidbody2D.velocity = PMathUtil.PolarToDecart(st.Tank.MovementSpeed, st.Tank.Rotation2DRad());
            }
            else
            {
                st.Tank.Rigidbody2D.velocity = -PMathUtil.PolarToDecart(st.Tank.MovementSpeed, st.Tank.Rotation2DRad());
            }
        }
Пример #3
0
        private void ProcessForward(PBaseCharacter tank)
        {
            var     movementDeltaPerSec = PMathUtil.PolarToDecart(st.Unit.MovementSpeed, st.Unit.Rotation2DRad());
            Vector3 movementDelta       = movementDeltaPerSec * Time.fixedDeltaTime;

            var positionDelta = st.Unit.transform.position - tank.transform.position;

            float dist           = positionDelta.sqrMagnitude;
            float distIfForward  = (positionDelta + movementDelta).sqrMagnitude;
            float distIfBackward = (positionDelta - movementDelta).sqrMagnitude;

            if (dist < distIfForward && dist < distIfBackward)
            {
                st.Unit.Rigidbody2D.velocity = Vector2.zero;
            }
            else
            {
                st.Unit.Rigidbody2D.velocity = distIfForward < distIfBackward ? movementDeltaPerSec : -movementDeltaPerSec;
            }
        }