Exemplo n.º 1
0
    public void JumpControl()
    {
        if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0))
        {
            if (grounded)
            {
                myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
                stoppedJumping       = false;
                jumpSound.Play();
            }

            if (!grounded && doubleJump)
            {
                myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
                jumpTimeCounter      = jumpTime;
                doubleJump           = false;
                stoppedJumping       = false;
                jumpSound.Play();
            }
        }

        if ((Input.GetKey(KeyCode.Space) || Input.GetMouseButton(0)) && !stoppedJumping)
        {
            if (jumpTimeCounter > 0)
            {
                myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
                jumpTimeCounter     -= Time.deltaTime;
            }
        }

        if (Input.GetKeyUp(KeyCode.Space) || Input.GetMouseButtonUp(0))
        {
            jumpTimeCounter = 0;
            stoppedJumping  = true;
        }

        if (grounded)
        {
            jumpTimeCounter = jumpTime;
            doubleJump      = true;
        }

        myAnimator.SetFloat("Speed", myRigidbody.velocity.x);
        myAnimator.SetBool("Grounded", grounded);
        myAnimator.SetBool("SafeMode", thePowerupManager.GetSafeMode());
        myAnimator.SetBool("FlyingMode", thePowerupManager.GetFlyingMode());
    }
Exemplo n.º 2
0
    void Update()
    {
        // if we pass generation point
        // Note: position changes so order of generation matters
        if (transform.position.x < generationPoint.position.x)
        {
            distanceBetween = Random.Range(distanceBetweenMin, distanceBetweenMax);

            platformSelector = Random.Range(0, platformPools.Length);

            heightChange = transform.position.y + Random.Range(-maxHeightChange, maxHeightChange);

            if (heightChange > maxHeight)
            {
                heightChange = maxHeight;
            }
            else if (heightChange < minHeight)
            {
                heightChange = minHeight;
            }

            generatePowerup();

            // move generator (this) to new platform position and generate platform
            transform.position = new Vector3(transform.position.x + (platformWidths[platformSelector] / 2) + distanceBetween, heightChange, transform.position.z);

            generatePlatform();

            generateCoins();

            if (!powerupManager.GetSafeMode())
            {
                generateSpikes();
            }

            // this is moving the generator to the edge of the new platform
            // prepping for the next platform to spawn
            transform.position = new Vector3(transform.position.x + (platformWidths[platformSelector] / 2), transform.position.y, transform.position.z);
        }
    }
Exemplo n.º 3
0
    void Update()
    {
        if (transform.position.x < generationPoint.position.x)
        {
            float gap = 0;
            if (Random.Range(0f, 100f) < platformGapThreshold)
            {
                gap = Random.Range(1f, 5f);
            }
            // Generating Constant Ground
            transform.position = new Vector3(transform.position.x + 5 + gap, transform.position.y, transform.position.z);
            GameObject constantPlatform = theConstantPlatformPool.GetPooledObject();
            constantPlatform.transform.position = transform.position;
            constantPlatform.transform.rotation = transform.rotation;
            constantPlatform.SetActive(true);

            // Select which game object to spawn on ground
            switch (Random.Range(1, 6))
            {
            //Fruits
            case 1:
                fruitCount++;
                if (fruitCount <= 2)
                {
                    float randomHeight = Random.Range(1f, 6f);
                    theFruitGenerator.SpawnCoins(Random.Range(2, 6), new Vector3(transform.position.x, transform.position.y + randomHeight, transform.position.z));
                }
                else
                {
                    fruitCount = 0;
                }
                break;

            // Enemy kill box
            case 2:
                enemyCount++;
                if (enemyCount <= 2)
                {
                    theEnemyGenerator.spawnEnemy(new Vector3(transform.position.x, transform.position.y + 0.5f, transform.position.z), thePowerupManager.GetSafeMode());
                }
                else
                {
                    enemyCount = 0;
                }
                break;

            // Obstacles
            case 3:
                obstacleCount++;
                if (obstacleCount <= 2)
                {
                    theObstacleGenerator.spawnObstacle(new Vector3(transform.position.x, transform.position.y + 0.5f, transform.position.z));
                }
                else
                {
                    obstacleCount = 0;
                }
                break;

            // Powerups
            case 4:
                powerupCount++;
                if (powerupCount <= 2)
                {
                    GameObject newPowerup = powerupPool.GetPooledObject();

                    newPowerup.transform.position = transform.position + new Vector3(transform.position.x, Random.Range(1f, powerupHeight), 0f);
                    //float finalMaxHeight = 0.0f;
                    if (!(Physics2D.OverlapArea(new Vector2(newPowerup.transform.position.x - 0.5f, newPowerup.transform.position.y + 0.5f), new Vector2(newPowerup.transform.position.x + 0.5f, newPowerup.transform.position.y + 0.5f))))
                    {
                        newPowerup.SetActive(true);
                    }
                }
                else
                {
                    powerupCount = 0;
                }
                break;
            }
        }
    }