Exemplo n.º 1
0
    private IEnumerator Reset(bool shouldDie)
    {
        isResetting = true;

        if (shouldDie)
        {
            DeathSound.Play();
            // Blood
            GameObject deathParticles = GameObject.Instantiate(DeathParticles, playerObject.transform.position + new Vector3(0, 0, -2), Quaternion.identity, LevelParent);
            float      time           = 0;
            while (time < 2.0f)
            {
                yield return(null);

                if (Input.GetKeyDown(KeyCode.X))
                {
                    // Bail - hacky, but ok for now
                    GameObject.Destroy(deathParticles);
                    isResetting = false;
                    GoBack();
                    yield break;
                }
                time += Time.deltaTime;
            }
        }

        DestroyLevelObjects();

        yield return(new WaitForSeconds(0.5f));

        isResetting = false;

        // Regenerate
        ManifestLevel(currentLevel);
    }
Exemplo n.º 2
0
    void Fire()
    {
        GameObject gameObj = Pool.GetObjectFromPool();

        if (gameObj == null)
        {
            return;
        }
        gameObj.transform.position = CanoDaArma.transform.position;
        gameObj.transform.rotation = CanoDaArma.transform.rotation;
        gameObj.SetActive(true);
        Audio.Play();
    }
Exemplo n.º 3
0
    private void DescendCamera(LevelStateFrame frame)
    {
        // TODO: check if any are hitting supports.
        bool shouldBlock = false;

        foreach (ObjectLevelState objectState in frame.Objects)
        {
            DraggableSupport draggableSupport = objectState.Object.GetComponent <DraggableSupport>();
            if (draggableSupport)
            {
                if (draggableSupport.ShouldBlockCameraMovementAndDegrade(generatedLevel))
                {
                    shouldBlock = true; // Keep evaluating even if should block is already trye.
                }
            }
        }

        if (!shouldBlock)
        {
            foreach (ObjectLevelState objectState in frame.Objects)
            {
                if (objectState.Object.GetComponent <FixedToCamera>())
                {
                    objectState.Object.Y++; // We'll save states later.
                }
            }

            frame.YCamera++;
        }
        else
        {
            // Blocked!
            RockBreak.Play(true);
            StartCoroutine(ShakeCamera());
        }
    }
Exemplo n.º 4
0
 public void StepSound()
 {
     audio.Play();
 }
Exemplo n.º 5
0
    // Handles falling.
    private MoveResult ProcessMoveResultsImmediately(PlayerController pc)
    {
        MoveResult result = MoveResult.None;

        // Add a new state frame
        levelState.AddFrame();

        // Can we descend the camera?
        DescendCamera(levelState.Current);

        // Player falls, maybe - unless they hit water?
        // This is a bit tricky, because we also need to push things down.
        ObjectWithPosition thePlayer = pc.GetComponent <ObjectWithPosition>();
        bool somethingMoved          = true;
        bool bail = false;

        foreach (ObjectWithPosition pos in levelState.Objects)
        {
            // Store the transitionary states so we can do nice lerping.
            pos.XIntermediate = pos.X;
            pos.YIntermediate = pos.Y;
        }

        int fallAmount = 0;

        while (somethingMoved && !bail)
        {
            somethingMoved = false;
            ClearMoveWorker();

            for (int i = 0; i < levelState.Objects.Count; i++)
            {
                ObjectWithPosition pos = levelState.Objects[i];

                Gravity gravity   = pos.GetComponent <Gravity>();
                int     direction = gravity ? gravity.Direction : 0;
                bool    isWater   = generatedLevel.IsWater(pos.X, pos.Y);
                if ((!isWater) && direction != 0) // Things float in water.
                {
                    int x = pos.X;
                    int y = pos.Y + direction;
                    //if (generatedLevel.IsBlocked(x, y))
                    if (MoveHelper.CanMove_AndMaybePush(pos, 0, 1, generatedLevel, levelState.Objects, moveWorker))
                    {
                        pos.Y          = y;
                        somethingMoved = true;
                    }
                }
                if (isWater)
                {
                    pos.Direction = 0; // Resets direction
                }

                if (thePlayer == pos)
                {
                    if ((GetBottomDeathRow() == pos.Y) || (pos.Y <= levelState.Current.YCamera))
                    {
                        result = MoveResult.Death;
                        bail   = true;
                        break; // They're gonna die.
                    }

                    if (Constants.Exit == generatedLevel.GetWorldPieceAt(pos.X, pos.Y))
                    {
                        result = MoveResult.Exit;
                        bail   = true;
                        break;
                    }

                    if (somethingMoved)
                    {
                        fallAmount++;
                        if (fallAmount > 3)
                        {
                            FallSound.Play();
                        }
                    }
                }
            }
        }

        levelState.SaveStates(); // Does that for the objects only, camera is already updated.

        return(result);
    }
Exemplo n.º 6
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (escapeTimer > 0f)
            {
                Application.Quit();
            }
            else
            {
                escapeTimer = 1.0f;
            }
        }
        escapeTimer -= Time.deltaTime;
        escapeTimer  = Mathf.Max(0f, escapeTimer);

        if (Input.GetKeyDown(KeyCode.M))
        {
            musicOn = !musicOn;
            if (musicOn)
            {
                Music.Play();
            }
            else
            {
                Music.Stop();
            }
        }

        if (!isResetting)
        {
#if UNITY_EDITOR
            int index = 0;
            foreach (KeyCode kc in codes)
            {
                if (Input.GetKeyDown(kc))
                {
                    currentLevel = index;
                    StartCoroutine(Reset(false));
                }
                index++;
            }
#endif

            if (Input.GetKeyDown(KeyCode.R))
            {
                StopCoroutine(lerpCoroutine);
                isLerpingMove = false;
                StartCoroutine(Reset(false));
            }
            else
            {
                PlayerController pc = playerObject.GetComponent <PlayerController>();

                if (pc.PressedMoveKey())
                {
                    if (isLerpingMove)
                    {
                        StopCoroutine(lerpCoroutine);
                        isLerpingMove = false;
                        // Position the objects at their destinations immediately, so the player doesn't need to wait for the lerp to finish.
                        PositionObjects(levelState.Current);
                        HandleMoveResultDelayed(lastMoveResult);
                    }
                }

                if (!isResetting) // Because we may have killed the player ^^
                {
                    ClearMoveWorker();
                    bool wasJump;
                    if (pc.MovePlayer(generatedLevel, ref constants, levelState.Objects, moveWorker, out wasJump))
                    {
                        if (wasJump)
                        {
                            JumpSound.Play(forceNew: true);
                        }
                        else
                        {
                            WalkSound.Play();
                        }

                        Title.SetActive(false);

                        //Debug.Log("player at: " + levelState.Current.YCamera);

                        lastMoveResult = ProcessMoveResultsImmediately(pc);
                        lerpCoroutine  = StartCoroutine(LerpToNewResults(pc, lastMoveResult));
                    }
                    else if (Input.GetKeyDown(KeyCode.X))
                    {
                        GoBack();
                    }
                }
            }


            EvaluateTips();
        }
    }