コード例 #1
0
        void CheckCollisons()
        {
            bool collide = false;

            // check player AABB against every platform AABB:
            foreach (AABB platform in Platforms)
            {
                if (player.CollidesWith(platform))
                {
                    Vector3 fix = player.FindFix(platform);
                    player.BroadcastMessage("ApplyFix", fix);
                    collide = true;
                }
            }

            //if player has not collided at all, player is not grounded
            if (!collide)
            {
                playerMove.isGrounded = false;
            }

            // check player AABB against every hazard AABB:
            foreach (AABB hazard in Hazards)
            {
                //if player collides, they are dead
                if (player.CollidesWith(hazard))
                {
                    Vector3 fix = player.FindFix(hazard);
                    player.BroadcastMessage("ApplyFix", fix);

                    //check to see if player has shield powerup. if so, deactivate it. if not, end game.
                    if (playerMove.shieldPowerup == true)
                    {
                        playerMove.shieldPowerup = false;
                    }
                    else if (playerMove.shieldPowerup == false)
                    {
                        playerMove.isDead = true;

                        //play sfx:
                        audioPlayer.PlayOneShot(gameOverSFX, 1f);

                        //activate game over UI:
                        gameOverUI.SetActive(true);
                        gameOverScore.text = "You earned" + playerScore + "points!";
                    }

                    Hazards.Remove(hazard);
                    Destroy(hazard);
                }
            }

            // check player AABB against every spring AABB:
            foreach (AABB spring in Springs)
            {
                //if player collides, they will bounce
                if (player.CollidesWith(spring))
                {
                    Vector3 fix = player.FindFix(spring);
                    player.BroadcastMessage("ApplyFix", fix);

                    //do thing. make player bounce.
                }
            }

            // check player AABB against every slow time AABB:
            foreach (AABB slowTime in SlowTimes)
            {
                //if player collides, they are dead
                if (player.CollidesWith(slowTime))
                {
                    Vector3 fix = player.FindFix(slowTime);
                    player.BroadcastMessage("ApplyFix", fix);

                    //set slow time:
                    playerMove.slowTimePowerup = 600;

                    //play sfx:
                    audioPlayer.PlayOneShot(powerupSFX, 1f);

                    SlowTimes.Remove(slowTime);
                    Destroy(slowTime);
                }
            }

            // check player AABB against every shield AABB:
            foreach (AABB shield in Shields)
            {
                //if player collides, they are dead
                if (player.CollidesWith(shield))
                {
                    Vector3 fix = player.FindFix(shield);
                    player.BroadcastMessage("ApplyFix", fix);

                    //active shield powerup:
                    playerMove.shieldPowerup = true;

                    //play sfx:
                    audioPlayer.PlayOneShot(powerupSFX, 1f);

                    Shields.Remove(shield);
                    Destroy(shield);
                }
            }
        }
コード例 #2
0
        void CheckCollisons()
        {
            bool collide = false;

            // check player AABB against every platform AABB:
            foreach (AABB platform in Platforms)
            {
                if (player.CollidesWith(platform))
                {
                    Vector3 fix = player.FindFix(platform);
                    player.BroadcastMessage("ApplyFix", fix);
                    collide = true;
                }
            }

            //if player has not collided at all, player is not grounded
            if (!collide)
            {
                playerMove.isGrounded = false;
            }

            // check player AABB against edge bounds:
            foreach (AABB edge in Edges)
            {
                //if player collides, stop them
                if (player.CollidesWith(edge))
                {
                    Vector3 fix = player.FindFix(edge);
                    player.BroadcastMessage("ApplyFix", fix);
                    collide = true;
                }
            }

            // check if player AABB has fallen out of bounds
            foreach (AABB bottom in Bottom)
            {
                //if player collides, stop them
                if (player.CollidesWith(bottom))
                {
                    playerMove.isDead = true;
                }
            }

            // check player AABB against every hazard AABB:
            for (int i = Hazards.Count - 1; i >= 0; i--)
            {
                AABB hazard = Hazards[i];

                //if player collides, they are dead
                if (player.CollidesWith(hazard))
                {
                    //check to see if player has shield powerup. if so, deactivate it. if not, end game.
                    if (playerMove.shieldPowerup == true)
                    {
                        playerMove.shieldPowerup = false;
                    }
                    else if (playerMove.shieldPowerup == false)
                    {
                        playerMove.isDead = true;

                        //play sfx:
                        audioPlayer.PlayOneShot(gameOverSFX, 1f);
                    }

                    Hazards.RemoveAt(i);
                    Destroy(hazard.gameObject);
                }
            }

            // check player AABB against every spring AABB:
            for (int i = Springs.Count - 1; i >= 0; i--)
            {
                AABB spring = Springs[i];

                //if player collides, they will bounce
                if (player.CollidesWith(spring))
                {
                    Vector3 fix = player.FindFix(spring);
                    player.BroadcastMessage("ApplyFix", fix);

                    //bounce player
                    playerMove.hitSpring = true;

                    Springs.RemoveAt(i);
                    Destroy(spring.gameObject);
                }
            }

            // check player AABB against every slow time AABB:
            for (int i = SlowTimes.Count - 1; i >= 0; i--)
            {
                AABB slowTime = SlowTimes[i];

                //if player collides, activate time slow powerup
                if (player.CollidesWith(slowTime))
                {
                    //set slow time:
                    playerMove.slowTimePowerup = 300;

                    //play sfx:
                    audioPlayer.PlayOneShot(powerupSFX, 0.75f);

                    SlowTimes.RemoveAt(i);
                    Destroy(slowTime.gameObject);
                }
            }

            // check player AABB against every shield AABB:
            for (int i = Shields.Count - 1; i >= 0; i--)
            {
                AABB shield = Shields[i];

                //if player collides, activate time slow powerup
                if (player.CollidesWith(shield))
                {
                    //active shield powerup:
                    playerMove.shieldPowerup = true;

                    //play sfx:
                    audioPlayer.PlayOneShot(powerupSFX, 0.75f);

                    Shields.RemoveAt(i);
                    Destroy(shield.gameObject);
                }
            }
        }