Esempio n. 1
0
        protected override async void Execute(List <GameEntity> entities)
        {
            foreach (GameEntity levelEntity in entities)
            {
                if (levelEntity.hasAsyncOperationHandle)
                {
                    Addressables.Release(levelEntity.asyncOperationHandle.Value);
                    levelEntity.RemoveAsyncOperationHandle();
                }

                if (levelEntity.hasView)
                {
                    levelEntity.view.Value.Unlink();
                    GameObject.Destroy(levelEntity.view.Value);
                    levelEntity.RemoveView();
                }
            }

            GameEntity[] tempList = entities.ToArray();
            foreach (GameEntity levelEntity in tempList)
            {
                AssetReference levelReference =
                    GameConfigurations.AssetReferenceConfiguration.LevelAssetReferences[levelEntity.levelIndex.Value];

                await AssetLoaderUtils.InstantiateAssetAsyncTask(levelReference, levelEntity, Vector3.zero, Quaternion.identity);
            }
        }
Esempio n. 2
0
        private async void SpawnCollectableOnSpawns(GameEntity[] listOfSpawnEntities)
        {
            foreach (GameEntity spawnEntity in listOfSpawnEntities)
            {
                bool found = false;
                foreach (SaveDataEntity saveDataEntity in _savedCollectables.GetEntities())
                {
                    if (saveDataEntity.collectableId.Value == spawnEntity.collectableId.Value)
                    {
                        found = true;
                        break;
                    }
                }

                GameEntity collectableEntity = Contexts.sharedInstance.game.CreateEntity();
                collectableEntity.isCollectable = true;
                collectableEntity.AddCollectableId(spawnEntity.collectableId.Value);
                await AssetLoaderUtils.InstantiateAssetAsyncTask(GameConfigurations.AssetReferenceConfiguration.CollectableReference, collectableEntity, spawnEntity.view.Value.transform.position, Quaternion.identity);

                Material collectableMaterial = collectableEntity.view.Value.GetComponentInChildren <SpriteRenderer>().material;
                collectableMaterial.SetInt(ShaderUtils.IsOutlineActive, Convert.ToInt32(found));
                collectableEntity.AddAnimator(collectableEntity.view.Value.GetComponentInChildren <Animator>());
                collectableEntity.AddAudioSource(collectableEntity.view.Value.GetComponentInChildren <AudioSource>());
            }
        }
Esempio n. 3
0
        protected override async void Execute(List <GameEntity> entities)
        {
            GameEntity playerEntity = playerGroup.GetSingleEntity();
            GameEntity spawnEntity  = spawnPointGroup.GetSingleEntity();

            if (playerEntity.hasView)
            {
                playerEntity.ReplacePosition(spawnEntity.view.Value.transform.position);
                playerEntity.ReplaceVelocity(Vector3.zero);
                playerEntity.isIsInGoal = false;
            }
            else
            {
                await AssetLoaderUtils.InstantiateAssetAsyncTask(GameConfigurations.AssetReferenceConfiguration.PlayerAssetReference, playerEntity, spawnEntity.view.Value.transform.position, Quaternion.identity);

                GameObject playerObject = playerEntity.view.Value;
                playerObject.transform.position = spawnEntity.view.Value.transform.position;
                Rigidbody2D      playerRigidBody        = playerObject.GetComponent <Rigidbody2D>();
                CircleCollider2D playerCircleCollider2D = playerObject.GetComponent <CircleCollider2D>();
                playerEntity.AddRigidbody(playerRigidBody);
                playerEntity.AddCircleCollider(playerCircleCollider2D);
                playerEntity.AddVelocity(playerRigidBody.velocity);
                playerEntity.isCameraFollow = true;
                playerEntity.AddGroundState(GroundState.Ground);
                playerEntity.AddTrailRenderer(playerObject.GetComponentInChildren <TrailRenderer>());
                playerEntity.AddAudioSource(playerObject.GetComponent <AudioSource>());
                playerEntity.AddSpriteRenderer(playerObject.GetComponent <SpriteRenderer>());
                playerEntity.AddAnimation(playerObject.GetComponent <Animation>());
            }
        }
Esempio n. 4
0
        private async void HandleImpactStars(ContactPoint2D contactPoint, GameEntity playerEntity)
        {
            float angle = Vector2.Angle(playerEntity.velocity.Value.normalized.Abs(),
                                        contactPoint.normal.normalized.Abs());
            float angleThreshold    = GameConfigurations.GameConstantsConfiguration.ImpatStarCollisionAngleThreshold;
            float velocityThreshold = GameConfigurations.GameConstantsConfiguration.ImpactStarEffectVelocityThreshold;

            if (playerEntity.velocity.Value.magnitude >= velocityThreshold && angle <= angleThreshold)
            {
                GameEntity impactStarEntity  = Contexts.sharedInstance.game.CreateEntity();
                GameEntity impactStarEntity2 = Contexts.sharedInstance.game.CreateEntity();
                impactStarEntity2.isImpactStar = true;
                impactStarEntity.isImpactStar  = true;
                Task <bool> impactStar1Task = AssetLoaderUtils.InstantiateAssetAsyncTask(GameConfigurations.AssetReferenceConfiguration.ImpactStarReference, impactStarEntity, contactPoint.point, Quaternion.identity);
                Task <bool> impactStar2Task = AssetLoaderUtils.InstantiateAssetAsyncTask(GameConfigurations.AssetReferenceConfiguration.ImpactStarReference, impactStarEntity2, contactPoint.point, Quaternion.identity);

                if (await impactStar1Task)
                {
                    GameObject impactStarObject = impactStarEntity.view.Value;
                    impactStarObject.transform.Rotate(0, 0, Vector2.SignedAngle(Vector2.up, contactPoint.normal));
                    Animation impactAnimation = impactStarObject.GetComponentInChildren <Animation>();
                    impactStarEntity.AddAnimation(impactAnimation);
                }

                if (await impactStar2Task)
                {
                    GameObject impactStarObject2 = impactStarEntity2.view.Value;
                    impactStarObject2.transform.Rotate(180 * contactPoint.normal.x, 180 * contactPoint.normal.y,
                                                       Vector2.SignedAngle(Vector2.up, contactPoint.normal));
                    Animation impactAnimation2 = impactStarObject2.GetComponentInChildren <Animation>();
                    impactStarEntity2.AddAnimation(impactAnimation2);
                }
            }
        }
Esempio n. 5
0
        protected override async void Execute(List <GameEntity> entities)
        {
            GameContext gameContext             = Contexts.sharedInstance.game;
            GameEntity  finishLevelDialogEntity = gameContext.CreateEntity();
            await AssetLoaderUtils.InstantiateAssetAsyncTask(GameConfigurations.AssetReferenceConfiguration.FinishLevelDialogReference, finishLevelDialogEntity, gameContext.staticLayer.Value.transform);

            finishLevelDialogEntity.isFinishLevelDialog = true;
        }
        protected override async void Execute(List <GameSettingsEntity> entities)
        {
            GameEntity speedrunControllerEntity = Contexts.sharedInstance.game.CreateEntity();
            await AssetLoaderUtils.InstantiateAssetAsyncTask(
                GameConfigurations.AssetReferenceConfiguration.SpeedrunControllerReference, speedrunControllerEntity,
                Vector3.zero, Quaternion.identity);

            //speedrunControllerEntity.AddController(speedrunControllerEntity.view.Value.GetComponent<SpeedrunController>());
        }
Esempio n. 7
0
        protected override async void Execute(List <GameEntity> entities)
        {
            int levelCount        = GameConfigurations.AssetReferenceConfiguration.LevelAssetReferences.Length;
            int currentLevelIndex = _levelEntityGroup.GetSingleEntity().levelIndex.Value;

            if (Contexts.sharedInstance.game.isAllCollectedInLevel)
            {
                if (currentLevelIndex >= levelCount - 1)
                {
                    GameContext gameContext = Contexts.sharedInstance.game;
                    GameEntity  finishSpeedrunDialogEntity = gameContext.CreateEntity();
                    await AssetLoaderUtils.InstantiateAssetAsyncTask(GameConfigurations.AssetReferenceConfiguration.FinishSpeedrunDialogReference, finishSpeedrunDialogEntity, gameContext.staticLayer.Value.transform);

                    finishSpeedrunDialogEntity.isFinishSpeedrunDialog = true;
                }
                else
                {
                    TransitionUtils.StartTransitionSequence(
                        new TransitionComponentData
                    {
                        Index = GameComponentsLookup.ControllerToRestartTransition,
                        TransitionComponent = new ControllerToRestartTransitionComponent {
                            Value = GameControllerType.Game
                        }
                    },
                        new TransitionComponentData
                    {
                        Index = GameComponentsLookup.LevelIndexToLoadTransition,
                        TransitionComponent = new LevelIndexToLoadTransitionComponent
                        {
                            Value = currentLevelIndex < levelCount - 1 ? currentLevelIndex + 1 : 1
                        }
                    }
                        );
                }
            }
            else
            {
                TransitionUtils.StartTransitionSequence(
                    new TransitionComponentData
                {
                    Index = GameComponentsLookup.ControllerToRestartTransition,
                    TransitionComponent = new ControllerToRestartTransitionComponent {
                        Value = GameControllerType.Game
                    }
                },
                    new TransitionComponentData
                {
                    Index = GameComponentsLookup.LevelIndexToLoadTransition,
                    TransitionComponent = new LevelIndexToLoadTransitionComponent
                    {
                        Value = currentLevelIndex
                    }
                }
                    );
            }
        }
        public async void Initialize()
        {
            GameContext gameContext      = Contexts.sharedInstance.game;
            GameEntity  levelTimerEntity = gameContext.CreateEntity();
            await AssetLoaderUtils.InstantiateAssetAsyncTask(
                GameConfigurations.AssetReferenceConfiguration.LevelTimerComponentReference, levelTimerEntity,
                gameContext.staticLayer.Value.transform);

            levelTimerEntity.isLevelTimer = true;
            levelTimerEntity.AddLevelTimerBehaviour(levelTimerEntity.view.Value.GetComponent <LevelTimerBehaviour>());
        }
Esempio n. 9
0
        protected override async void Execute(List <GameEntity> entities)
        {
            Physics2D.simulationMode = SimulationMode2D.Script;
            GameContext gameContext             = Contexts.sharedInstance.game;
            GameEntity  finishLevelDialogEntity = gameContext.CreateEntity();

            _pauseOverlayGroup.GetSingleEntity().pauseOverlay.Value.enabled = true;
            await AssetLoaderUtils.InstantiateAssetAsyncTask(GameConfigurations.AssetReferenceConfiguration.FinishLevelDialogReference, finishLevelDialogEntity, gameContext.overlayLayer.Value.transform);

            finishLevelDialogEntity.isFinishLevelDialog = true;
        }
Esempio n. 10
0
        protected override async void Execute(List <GameEntity> entities)
        {
            GameEntity lineEntity = Contexts.sharedInstance.game.CreateEntity();
            await AssetLoaderUtils.InstantiateAssetAsyncTask(GameConfigurations.AssetReferenceConfiguration.FlickLineRendererReference, lineEntity, Vector3.zero, Quaternion.identity);

            LineRenderer lineRenderer = lineEntity.view.Value.GetComponent <LineRenderer>();

            lineEntity.AddFlickLine(lineRenderer);
            lineEntity.AddMaxDragLength(GameConfigurations.GameConstantsConfiguration.MaxDragLength);
            lineEntity.AddCurrentDragLength(0f);
        }
Esempio n. 11
0
        protected override async void Execute(List <GameEntity> entities)
        {
            GameEntity[]   tempList          = entities.ToArray();
            AssetReference mainMenuReference = GameConfigurations.AssetReferenceConfiguration.MainMenuReference;

            foreach (GameEntity gameEntity in tempList)
            {
                await AssetLoaderUtils.InstantiateAssetAsyncTask(mainMenuReference, gameEntity, Contexts.sharedInstance.game.staticLayer.Value.transform);

                gameEntity.AddMainMenuBehaviour(gameEntity.view.Value.GetComponent <MainMenuBehaviour>());
            }
        }
Esempio n. 12
0
        private async void DrawNewLine(Vector3 point1, Vector3 point2)
        {
            GameEntity itemConnector = Contexts.sharedInstance.game.CreateEntity();

            itemConnector.isLevelSelectionItemConnector = true;
            await AssetLoaderUtils.InstantiateAssetAsyncTask(
                GameConfigurations.AssetReferenceConfiguration.LevelSelectionConnectorReference, itemConnector,
                Vector3.zero, Quaternion.identity);

            var lineRenderer = itemConnector.view.Value.GetComponent <LineRenderer>();

            lineRenderer.SetPositions(new [] { point1, point2 });
        }
Esempio n. 13
0
        public async void Initialize()
        {
            IGroup <GameEntity> levelGroup  = Contexts.sharedInstance.game.GetGroup(GameMatcher.Level);
            GameEntity          levelEntity = levelGroup.GetSingleEntity();

            if (levelEntity != null && !levelEntity.hasView)
            {
                AssetReference levelReference =
                    GameConfigurations.AssetReferenceConfiguration.LevelAssetReferences[levelEntity.levelIndex.Value];

                await AssetLoaderUtils.InstantiateAssetAsyncTask(levelReference, levelEntity, Vector3.zero, Quaternion.identity);
            }
        }
Esempio n. 14
0
        public async void Initialize()
        {
            GameContext context = Contexts.sharedInstance.game;

            for (int i = 1; i < GameConfigurations.AssetReferenceConfiguration.LevelAssetReferences.Length; i++)
            {
                GameEntity levelSelectionItemEntity = context.CreateEntity();
                await AssetLoaderUtils.InstantiateAssetAsyncTask(GameConfigurations.AssetReferenceConfiguration.LevelSelectionItemReference, levelSelectionItemEntity, Vector3.zero, Quaternion.identity);

                var behaviour = levelSelectionItemEntity.view.Value.GetComponent <LevelSelectionItemBehaviour>();
                behaviour.LevelIndex = i;
                levelSelectionItemEntity.AddSpriteRenderer(levelSelectionItemEntity.view.Value.GetComponent <SpriteRenderer>());
                levelSelectionItemEntity.AddLevelSelectionItemBehaviour(behaviour);
            }
        }
Esempio n. 15
0
        private void OnSpeedrunModeButtonClicked()
        {
            GameContext gameContext = Contexts.sharedInstance.game;

            gameContext.CreateEntity().AddTeardownController(GameControllerType.MainMenu);
            GameEntity dialogEntity = gameContext.CreateEntity();

            AssetLoaderUtils.InstantiateAssetAsyncTask(
                GameConfigurations.AssetReferenceConfiguration.ExplainSpeedrunDialogReference, dialogEntity,
                gameContext.staticLayer.Value.transform);
            GameEntity mainMenuEntity = gameObject.GetEntityLink().entity as GameEntity;

            mainMenuEntity?.DestroyEntity();
            //gameContext.CreateEntity().AddLeve

            /*Contexts.sharedInstance.gameSettings.isSpeedrun = true;
             * Contexts.sharedInstance.saveData.DestroyAllEntities();
             *
             * TransitionUtils.StartTransitionSequence(
             *  new TransitionComponentData
             *  {
             *      Index = GameComponentsLookup.ControllerToTeardownTransition,
             *      TransitionComponent = new ControllerToTeardownTransitionComponent
             *          {Value = GameControllerType.MainMenu}
             *  },
             *  new TransitionComponentData
             *  {
             *      Index = GameComponentsLookup.SceneToRemove,
             *      TransitionComponent = new SceneToRemoveComponent
             *          {Value = GameConfigurations.GameSceneConfiguration.MainMenuSceneName}
             *  },
             *  new TransitionComponentData
             *  {
             *      Index = GameComponentsLookup.SceneToAdd,
             *      TransitionComponent = new SceneToAddComponent
             *          {Value = GameConfigurations.GameSceneConfiguration.GameSceneName,}
             *  },
             *  new TransitionComponentData
             *  {
             *      Index = GameComponentsLookup.LevelIndexToLoadTransition,
             *      TransitionComponent = new LevelIndexToLoadTransitionComponent {Value = 1}
             *  }
             * );
             *
             * GameEntity mainMenuEntity = gameObject.GetEntityLink().entity as GameEntity;
             * mainMenuEntity?.DestroyEntity();*/
        }
Esempio n. 16
0
        public async void Initialize()
        {
            if (Contexts.sharedInstance.gameSettings.isSpeedrun)
            {
                GameContext gameContext      = Contexts.sharedInstance.game;
                GameEntity  levelTimerEntity = gameContext.CreateEntity();
                await AssetLoaderUtils.InstantiateAssetAsyncTask(
                    GameConfigurations.AssetReferenceConfiguration.LevelTimerComponentReference, levelTimerEntity,
                    gameContext.staticLayer.Value.transform);

                levelTimerEntity.isSpeedrunLevelTimer = true;
                levelTimerEntity.AddLevelTimerBehaviour(levelTimerEntity.view.Value
                                                        .GetComponent <LevelTimerBehaviour>());
                // changing the speedrun timer's position in a super hacky way
                Vector3 transformPosition = levelTimerEntity.view.Value.transform.position;
                levelTimerEntity.view.Value.transform.position =
                    new Vector3(transformPosition.x, transformPosition.y - 50f, transformPosition.z);
            }
        }