Exemplo n.º 1
0
        public bool OnCollision(Geom g1, Geom g2, ContactList contactList)
        {
            Sprite s1 = (Sprite)g1.Tag;
            Sprite s2 = (Sprite)g2.Tag;

            if (g1.Tag.GetType() == typeof(Player) && (g2.Tag.GetType() == typeof(Sprite) || g2.Tag.GetType() == typeof(QuarkPlatform)))
            {
                foreach (MovingPlatform m in movingPlatforms)
                {                                 //this is to detatch the player if he crashes into a tile
                    if (m.attachedPlayer != null)
                    {
                        m.dettachPlayer();
                        playerSprite.CanJump = true;

                    }
                }
            }
            if (g2.Tag.GetType() == typeof(Pickup))
            {
                s2.Body.Dispose();
                g2.Dispose();               //pickup should be destroyed disapear and increase energy
                quarkEnergy = gameParam.PickupEnergy + quarkEnergy;
            }

            if (g2.Tag.GetType() == typeof(MovingPlatform))
            {
               //attaches player to platform via a join to stop player sliding
               MovingPlatform platform = (MovingPlatform)s2;
               platform.attachPlayer(playerSprite);
            }

            if (g2.Tag.GetType() == typeof(BouncyTile))
            {
                Cue cue = soundBank.GetCue("Bouncing platform"); //sound should play when player bounces
                cue.Play();

                int maxBounceHeight = 10000; //so if the player lands on multiple bounce tiles at once,
                                             //the force doesnt accumulate

                //code below to set bounce height

                if (playerSprite.Body.LinearVelocity.Y < 0)
                {
                    playerSprite.Body.ApplyImpulse(new Vector2(0, maxBounceHeight));
                }

                if (playerSprite.Body.LinearVelocity.Y > 0)
                {
                    playerSprite.Body.ApplyImpulse(new Vector2(0, -maxBounceHeight));
                }

                playerSprite.Body.LinearVelocity.Y = 0; // this line is incase the sprite hits more than one tile
            }

            if (g1.Tag.GetType() == typeof(Player) && (g2.Tag.GetType() == typeof(Sprite) || g2.Tag.GetType() == typeof(QuarkPlatform) || g2.Tag.GetType() == typeof(MovingPlatform)))
            {
                TicksCollision = Ticks;
                playerSprite.CanJump = true;

            }

            //collision for teleport
            if (g2.Tag.GetType() == typeof(Teleport))
            {
                Cue cue = soundBank.GetCue("Teleport");
                cue.Play();

                if (HasTeleport == true)
                {
                    //transport player to other portal
                    playerSprite.Body.Position = place.Position;
                    HasTeleport = false;
                }

                return false;
            }
            return true;
        }
Exemplo n.º 2
0
 public void Cleanup()
 {
     geom.Dispose();
     space.Dispose();
     OdeTests.Cleanup();
 }