예제 #1
0
    protected virtual void Start()
    {
        interact = GameController.Instance.PlayControl;
        movement = movementSystem.LoadMovement(interact);

        if (swimming != null)
        {
            swimming.LoadMovement(interact);
        }

        if (platformerSpecials != null)
        {
            platformerSpecials.LoadKeys(interact);
        }

        if (combatSystem != null)
        {
            combatSystem.LoadAttack(interact);
        }

        if (movement == Movement.MovementType.PLATFORMER && !interact.ContainsValue(UserInput.JUMP) ||
            movement == Movement.MovementType.TOPDOWN && !(interact.ContainsValue(UserInput.MOVEUP) || interact.ContainsValue(UserInput.MOVEDOWN)))
        {
            Debug.LogWarning("The Movement options don't agree with the movement type, please double check everything");
        }
    }
예제 #2
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        EditorGUILayout.PropertyField(canControl);
        EditorGUILayout.PropertyField(movementType);
        Movement.MovementType mt = (Movement.MovementType)movementType.enumValueIndex;
        switch (mt)
        {
        case Movement.MovementType.Rigidbody2DUnidirectional:
            EditorGUILayout.PropertyField(movement, new GUIContent("Rigidbody2DUnidirectional"), true);
            break;

        case Movement.MovementType.Rigidbody2DBidirectional:
            EditorGUILayout.PropertyField(movement, new GUIContent("Rigidbody2DBidirectional"), true);
            break;

        case Movement.MovementType.Rigidbody2DFourDirectional:
            EditorGUILayout.PropertyField(movement, new GUIContent("Rigidbody2DFourDirectional"), true);
            break;

        case Movement.MovementType.Rigidbody2DEightDirectional:
            EditorGUILayout.PropertyField(movement, new GUIContent("Rigidbody2DEightDirectional"), true);
            break;
        }

        serializedObject.ApplyModifiedProperties();
    }
예제 #3
0
    public override bool GetNextMovement(List <IInteractable> interactables, Vector3 myPos, out Movement.MovementType nextMove, out Vector3 moveVec)
    {
        foreach (var pri in Priorities)
        {
            foreach (var strat in OptimeMoverStrategies)
            {
                if (strat.OptimizeType == pri && strat.GetNextMovement(interactables, myPos, out nextMove, out moveVec))
                {
                    return(true);
                }
            }
        }

        nextMove = Movement.MovementType.Backward;
        moveVec  = Vector3.zero;
        return(false);
    }
예제 #4
0
    private void LoadLevel()
    {
        bool             oneOff           = level < 3;
        List <EnemyInfo> enemyToSpawnList = new List <EnemyInfo>();
        int unselectableCtr = 0;

        for (int i = 1; i <= level; i++)
        {
            if (i == 3)
            {
                for (int j = 0; j < 3; j++)
                {
                    Movement.MovementType mType = Movement.MovementType.Diagonal;
                    if (j == 1)
                    {
                        mType = Movement.MovementType.Orthogonal;
                    }

                    enemyToSpawnList.Add(new EnemyInfo()
                    {
                        health                   = 1,
                        movementType             = mType,
                        unselectableOfflineCount = -1
                    });
                }
            }
            else if (i == 2 && level == 2)
            {
                for (int j = 0; j < 3; j++)
                {
                    Movement.MovementType mType = Movement.MovementType.Orthogonal;
                    if (j == 1)
                    {
                        mType = Movement.MovementType.None;
                    }

                    enemyToSpawnList.Add(new EnemyInfo()
                    {
                        health                   = 1,
                        movementType             = mType,
                        unselectableOfflineCount = -1
                    });
                }
            }
            else if (i == 1 && level == 1)
            {
                for (int j = 0; j < 3; j++)
                {
                    enemyToSpawnList.Add(new EnemyInfo()
                    {
                        health                   = 1,
                        movementType             = Movement.MovementType.None,
                        unselectableOfflineCount = -1
                    });
                }
            }
            else if (i % 4 == 0)
            {
                // Add new enemy
                enemyToSpawnList.Add(new EnemyInfo()
                {
                    health                   = 1,
                    movementType             = Movement.MovementType.None,
                    unselectableOfflineCount = -1
                });

                Dictionary <int, List <EnemyInfo> > enemyDict = new Dictionary <int, List <EnemyInfo> >();

                for (int j = 0; j < enemyToSpawnList.Count; j++)
                {
                    if (enemyToSpawnList[j].health < 3)
                    {
                        if (!enemyDict.ContainsKey(enemyToSpawnList[j].health))
                        {
                            enemyDict.Add(enemyToSpawnList[j].health, new List <EnemyInfo>());
                        }

                        enemyDict[enemyToSpawnList[j].health].Add(enemyToSpawnList[j]);
                    }
                }

                // Sort by highest hp
                var items = from pair in enemyDict
                            orderby pair.Key descending
                            select pair;

                // Promote 2 monsters HP by +1
                int numToPromote = 2;
                foreach (KeyValuePair <int, List <EnemyInfo> > entry in items)
                {
                    for (int j = 0; j < entry.Value.Count; j++)
                    {
                        if (entry.Value[j].health < 3)
                        {
                            entry.Value[j].health++;
                            numToPromote--;
                        }

                        if (numToPromote <= 0)
                        {
                            break;
                        }
                    }

                    if (numToPromote <= 0)
                    {
                        break;
                    }
                }
            }
            else if (i % 1 == 0)
            {
                for (int j = 0; j < enemyToSpawnList.Count; j++)
                {
                    if (enemyToSpawnList[j].unselectableOfflineCount < 0)
                    {
                        if (unselectableCtr >= 3)
                        {
                            unselectableCtr = 0;
                        }
                        enemyToSpawnList[j].unselectableOfflineCount = unselectableCtr++;
                        break;
                    }
                }
            }
            else if (i % 2 == 0)
            {
                for (int j = 0; j < enemyToSpawnList.Count; j++)
                {
                    if (enemyToSpawnList[j].movementType == Movement.MovementType.None)
                    {
                        enemyToSpawnList[j].movementType = (Movement.MovementType)Random.Range(1, 3);
                        break;
                    }
                }
            }
            else if (i % 3 == 0)
            {
                for (int j = 0; j < enemyToSpawnList.Count; j++)
                {
                    if (!enemyToSpawnList[j].reboot)
                    {
                        enemyToSpawnList[j].reboot = true;
                        break;
                    }
                }
            }
        }

        ResetSortingCounter();

        List <Vector2> availSpawnPosList = new List <Vector2>(_spawnPositionList);

        for (int j = 0; j < enemyToSpawnList.Count; j++)
        {
            Vector2 spawnPos = availSpawnPosList[Random.Range(0, availSpawnPosList.Count)];
            availSpawnPosList.Remove(spawnPos);
            EnemyAssembler.instance.Spawn(enemyToSpawnList[j], spawnPos, _spriteSortingCounter++ *3);
        }
    }
예제 #5
0
    public override bool GetNextMovement(List <IInteractable> interactables, Vector3 myPos, out Movement.MovementType nextMove, out Vector3 moveVec)
    {
        for (int i = 0; i < _tryApplySequence.Count; i++)
        {
            if (_tryApplySequence[i].GetNextMovement(interactables, myPos, out nextMove, out moveVec))
            {
                return(true);
            }
        }

        // failing to find where to move;
        nextMove = Movement.MovementType.Backward;
        moveVec  = Vector3.zero;
        return(false);
    }
예제 #6
0
 public override bool GetNextMovement(List <IInteractable> interactables, Vector3 myPos, out Movement.MovementType nextMove, out Vector3 moveVec)
 {
     nextMove = AllTypes.GetRandomValue();
     moveVec  = UnityEngine.Random.insideUnitSphere;
     return(true);
 }
예제 #7
0
    public override bool GetNextMovement(List <IInteractable> interactables, Vector3 myPos, out Movement.MovementType nextMove, out Vector3 moveVec)
    {
        var sources = interactables.Where(x => x.GetInteractionType() == whatToSearch);

        if (!sources.Any())
        {
            nextMove = Movement.MovementType.Backward;
            moveVec  = Vector3.zero;
            return(false);
        }

        // To reduce dirWeighted calculations from O(nlogn) to O(n)
        var cache = sources.Select(inter => (dirWeighted: inter.GetValue() / (inter.GetPosition() - myPos).sqrMagnitude, obj: inter)).ToList();

        cache.OrderByDescending(x => x.dirWeighted);
        var moveTo = cache.First();

        moveVec  = moveTo.obj.GetPosition() - myPos;
        nextMove = moveVec.ToMoveDirection();

        return(true);
    }
예제 #8
0
 public abstract bool GetNextMovement(List <IInteractable> interactables, Vector3 myPos, out Movement.MovementType nextMove, out Vector3 moveVec);