Example #1
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var deltaTime           = TimeUtility.GetLimitedDeltaTime();
        var totalInvincibleTime = GameEntry.Instance.Config.Global.Item.StarInvincibleTotalTime;
        var transitionTime      = GameEntry.Instance.Config.Global.Item.StarInvincibleTotalTime - GameEntry.Instance.Config.Global.Item.StarInvincibleMainTime;

        Entities.WithoutBurst().ForEach((ref PlayerStates playerStates) =>
        {
            if (playerStates.Main != PlayerMainStatus.Alive)
            {
                return;
            }

            if (playerStates.InvincibleRemainingTime <= 0)
            {
                return;
            }

            var lastInvincibleRemainingTime      = playerStates.InvincibleRemainingTime;
            playerStates.InvincibleRemainingTime = math.max(0, lastInvincibleRemainingTime - deltaTime);
            if (playerStates.InvincibleRemainingTime < transitionTime && lastInvincibleRemainingTime >= transitionTime)
            {
                GameEntry.Instance.Audio.PlayMusic(GameEntry.Instance.Scene.SceneData.MusicName, true);
            }
        }).Run();
        return(default);
    protected override void OnUpdate()
    {
        var playerQuery  = GetEntityQuery(typeof(PlayerStates));
        var playerEntity = playerQuery.GetSingletonEntity();
        var playerStates = GetComponentDataFromEntity <PlayerStates>()[playerEntity];

        if (!PlayerUtility.IsLevelDownProtection(playerStates))
        {
            return;
        }

        var deltaTime          = TimeUtility.GetLimitedDeltaTime();
        var flashRenderingData = GetComponentDataFromEntity <FlashRenderingData>()[playerEntity];

        flashRenderingData.TimeLeftToSwitchRenderer = math.max(0, flashRenderingData.TimeLeftToSwitchRenderer - deltaTime);
        if (flashRenderingData.TimeLeftToSwitchRenderer <= 0f)
        {
            flashRenderingData.TimeLeftToSwitchRenderer = GameEntry.Instance.Config.Global.PlayerLevelDownProtectionRendering.FlashingPeriod;
            // TODO: This doesn't work right now.
            if (GetComponentDataFromEntity <MaterialColor>().HasComponent(playerEntity))
            {
                EntityManager.RemoveComponent(playerEntity, typeof(MaterialColor));
            }
            else
            {
                EntityManager.AddComponent <MaterialColor>(playerEntity);
            }
        }

        EntityManager.SetComponentData(playerEntity, flashRenderingData);
    }
Example #3
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var deltaTime = TimeUtility.GetLimitedDeltaTime();

        var jobHandle = Entities.ForEach((Entity entity, ref Translation translation, ref MovementData movementData) =>
        {
            movementData.LastPosition = translation.Value;
            translation.Value        += movementData.Velocity * deltaTime;
        })
                        .Schedule(inputDeps);

        jobHandle.Complete();

        return(default);
Example #4
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var commandBuffer = m_CommandBufferSystem.CreateCommandBuffer().ToConcurrent();
        var deltaTime     = TimeUtility.GetLimitedDeltaTime();
        var jobHandle     = Entities.ForEach((int entityInQueryIndex, Entity entity, ref LifeTime lifeTime) =>
        {
            lifeTime.RemainingLifeTime -= deltaTime;
            if (lifeTime.RemainingLifeTime <= 0)
            {
                commandBuffer.DestroyEntity(entityInQueryIndex, entity);
            }
        }).Schedule(inputDeps);

        jobHandle.Complete();
        return(jobHandle);
    }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var verticalRange = m_VerticalRange;
        var verticalSpeed = m_VerticalSpeed;
        var deltaTime     = TimeUtility.GetLimitedDeltaTime();

        return(Entities
               .ForEach((ref MovableBlockStates movableBlockStates, ref Translation translation) =>
        {
            if (movableBlockStates.Status == MovableBlockStatus.None)
            {
                return;
            }

            switch (movableBlockStates.Status)
            {
            case MovableBlockStatus.MovingUp:
                {
                    var position = translation.Value + deltaTime * new float3(0, verticalSpeed, 0);
                    if (position.y - movableBlockStates.OriginalY > verticalRange)
                    {
                        position.y = movableBlockStates.OriginalY + verticalRange;
                        movableBlockStates.Status = MovableBlockStatus.MovingDown;
                    }

                    translation.Value = position;
                    break;
                }

            case MovableBlockStatus.MovingDown:
                {
                    var position = translation.Value - deltaTime * new float3(0, verticalSpeed, 0);
                    if (position.y < movableBlockStates.OriginalY)
                    {
                        position.y = movableBlockStates.OriginalY;
                        movableBlockStates.Status = MovableBlockStatus.None;
                    }

                    translation.Value = position;
                    break;
                }
            }
        }).Schedule(inputDeps));
    }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var deltaTime = TimeUtility.GetLimitedDeltaTime();
        var commandBufferConcurrent  = m_CommandBufferSystem.CreateCommandBuffer().ToConcurrent();
        var koopaTroopaGeneratorData = GetEntityQuery(typeof(KoopaTroopaGeneratorData))
                                       .GetSingleton <KoopaTroopaGeneratorData>();
        var spawningQueue           = new NativeQueue <float3>(Allocator.TempJob);
        var spawningQueueWriter     = spawningQueue.AsParallelWriter();
        var normalPrefabEntity      = koopaTroopaGeneratorData.NormalPrefabEntity;
        var normalPrefabEntityScale = MathUtility.MatrixToScale(GetComponentDataFromEntity <CompositeScale>()[normalPrefabEntity].Value);
        var jobHandle = Entities.WithoutBurst().ForEach((Entity entity, int entityInQueryIndex, ref ShellData shellData, in EnemyTag enemyTag,
                                                         in MovementData movementData,
                                                         in Translation translation, in CompositeScale scaleComponent) =>
        {
            if (enemyTag.Type != EnemyType.KoopaTroopaShell)
            {
                return;
            }

            var lastIsMoving   = shellData.IsMoving;
            shellData.IsMoving = EnemyUtility.IsMovingShell(enemyTag.Type, movementData);
            if (!lastIsMoving && shellData.IsMoving)
            {
                shellData.ReviveTimeUsed = 0;
            }

            if (lastIsMoving && !shellData.IsMoving)
            {
                shellData.ReviveTimeUsed = 0;
            }

            if (shellData.IsMoving)
            {
                return;
            }

            shellData.ReviveTimeUsed += deltaTime;
            if (shellData.ReviveTimeUsed >= shellData.ReviveTimeConfig)
            {
                commandBufferConcurrent.DestroyEntity(entityInQueryIndex, entity);
                spawningQueueWriter.Enqueue(translation.Value +
                                            new float3(0, normalPrefabEntityScale.y / 2 - MathUtility.MatrixToScale(scaleComponent.Value).y / 2, 0));
            }
        }).Schedule(inputDeps);
Example #7
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var deltaTime          = TimeUtility.GetLimitedDeltaTime();
        var verticalSpeedLimit = GameEntry.Instance.Config.Global.Gravity.VerticalSpeedLimit;
        var jobHandle          = Entities.ForEach((ref MovementData movementData, in GravityAbility gravityAbility) =>
        {
            var vel = movementData.Velocity;
            vel.y  -= gravityAbility.GravityAcc * deltaTime;
            if (vel.y < -verticalSpeedLimit)
            {
                vel.y = -verticalSpeedLimit;
            }

            movementData.Velocity = vel;
        }).Schedule(inputDeps);

        jobHandle.Complete();
        return(jobHandle);
    }
Example #8
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var deltaTime = TimeUtility.GetLimitedDeltaTime();

        return(Entities.ForEach((ref CoinBrickStates states, in CoinBrickConfigData config) =>
        {
            if (!states.TimerStarted || states.CoinLeft <= 1)
            {
                return;
            }

            states.TimeElapsed += deltaTime;
            if (states.TimeElapsed < config.CoinDecrementInterval)
            {
                return;
            }

            states.TimeElapsed = 0;
            states.CoinLeft -= 1;
        }).Schedule(inputDeps));
    }
Example #9
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var deltaTime = TimeUtility.GetLimitedDeltaTime();
        var playerLevelChangeTimeConfig         = m_PlayerLevelChangeTimeConfig;
        var playerLevelDownProtectionTimeConfig = m_PlayerLevelDownProtectionTimeConfig;
        var playerConfig = GameEntry.Instance.Config.Global.Player;
        var defaultScale = playerConfig.DefaultScale;
        var superScale   = playerConfig.SuperScale;

        var jobHandle = Entities
                        .ForEach((ref PlayerStates playerStates, ref Translation translation, ref CompositeScale scaleComponent, ref PhysicsCollider physicsCollider) =>
        {
            if (!PlayerUtility.IsChangingLevel(playerStates))
            {
                return;
            }

            if (math.abs(playerStates.LevelChangeTimeUsed) <= float.Epsilon)
            {
                playerStates.LevelDownProtectionTime = 0;
                var oldScale         = MathUtility.MatrixToScale(scaleComponent.Value);
                var newScale         = playerStates.NextLevel == PlayerLevel.Default ? defaultScale : superScale;
                scaleComponent.Value = MathUtility.ScaleToMatrix(newScale);
                translation.Value.y += newScale.y / 2 - oldScale.y / 2;
                PhysicsUtility.SetBoxColliderSize(physicsCollider, newScale);
            }

            if (playerStates.LevelChangeTimeUsed >= playerLevelChangeTimeConfig)
            {
                playerStates = CompleteLevelChange(playerStates, playerLevelDownProtectionTimeConfig);
            }
            else
            {
                playerStates.LevelChangeTimeUsed += deltaTime;
            }
        }).Schedule(inputDeps);

        jobHandle.Complete();
        return(jobHandle);
    }
Example #10
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var gravityAcc = GameEntry.Instance.Config.Global.Item.ItemGravityAcc;
        var deltaTime  = TimeUtility.GetLimitedDeltaTime();
        var random     = m_Random;
        var jobHandle  = Entities.WithoutBurst().ForEach((
                                                             ref Translation translation,
                                                             ref SimpleMovementAbilityData movementAbilityData,
                                                             ref GravityAbility gravityAbility,
                                                             ref MovementData movementData,
                                                             ref ItemStates states,
                                                             in ItemTag itemTag) =>
        {
            if (states.Status != ItemStatus.BeingBorn)
            {
                return;
            }
            var moveAmount = states.UpSpeed * deltaTime;
            if (moveAmount > states.UpToGo)
            {
                states.Status             = ItemStatus.Normal;
                moveAmount                = states.UpToGo;
                gravityAbility.GravityAcc = gravityAcc;
                movementAbilityData.InteractsWithGround = true;
                movementData.Velocity.x = movementAbilityData.HorizontalSpeed;
                movementData.Velocity.y = random.NextFloat(itemTag.InitialMinVerticalSpeed, itemTag.InitialMaxVerticalSpeed);
            }

            states.UpToGo -= moveAmount;

            var position      = translation.Value;
            position.y       += moveAmount;
            translation.Value = position;
        }).Schedule(inputDeps);

        jobHandle.Complete();
        return(jobHandle);
    }
Example #11
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var deltaTime = TimeUtility.GetLimitedDeltaTime();

        return(Entities.WithAll <PlayerTag>().ForEach((
                                                          ref Translation translation,
                                                          ref MovementData movementData,
                                                          ref PlayerStates states,
                                                          ref PlayerBouncedByEnemyData bouncedByEnemyData,
                                                          ref PlayerInputData inputData,
                                                          in PlayerMovementAbilityData movementAbilityData) =>
        {
            if (states.Main == PlayerMainStatus.Dying)
            {
                return;
            }

            UpdateHorizontal(ref movementData, inputData, movementAbilityData, deltaTime, states);


            if (PlayerUtility.IsGrounded(states))
            {
                UpdateJumpStart(ref states, ref movementData, inputData, movementAbilityData);
            }
            else if (states.Motion == PlayerMotionStatus.Jumping)
            {
                UpdateJumpKeep(ref states, ref movementData, movementAbilityData, inputData, deltaTime);
            }
            else if (states.Motion == PlayerMotionStatus.Falling)
            {
                UpdateBouncedByEnemy(ref bouncedByEnemyData, ref states, ref inputData, ref movementData, movementAbilityData);
            }

            bouncedByEnemyData.IsBounced = false;
        }).Schedule(inputDeps));
    }