Inheritance: CCNode
示例#1
0
        private void FruitVsBorders(Fruit fruit)
        {
            if(fruit.PositionX - fruit.Radius < 0 && fruit.Velocity.X < 0)
            {
                fruit.Velocity.X *= -1 * GameCoefficients.FruitCollisionElasticity;
                CCAudioEngine.SharedEngine.PlayEffect("FruitEdgeBounce");
            }
            if(fruit.PositionX + fruit.Radius > gameplayLayer.ContentSize.Width && fruit.Velocity.X > 0)
            {
                fruit.Velocity.X *= -1 * GameCoefficients.FruitCollisionElasticity;
                CCAudioEngine.SharedEngine.PlayEffect("FruitEdgeBounce");

            }
            if (fruit.PositionY + fruit.Radius > gameplayLayer.ContentSize.Height && fruit.Velocity.Y > 0)
            {
                fruit.Velocity.Y *= -1 * GameCoefficients.FruitCollisionElasticity;
                CCAudioEngine.SharedEngine.PlayEffect("FruitEdgeBounce");
            }
        }
示例#2
0
        // made public for debugging, may make it private later:
        private void Spawn()
		{
			var fruit = new Fruit ();

            if(Layer == null)
            {
                throw new InvalidOperationException("Need to set Layer before spawning");
            }

            fruit.PositionX = CCRandom.GetRandomFloat(0 + fruit.Radius, Layer.ContentSize.Width - fruit.Radius);
            fruit.PositionY = Layer.ContentSize.Height + fruit.Radius;

            if(CCRandom.Float_0_1() > .5f)
            {
                fruit.FruitColor = FruitColor.Red;
            }
            else
            {
                fruit.FruitColor = FruitColor.Yellow;
            }


			if(FruitSpawned != null)
			{
				FruitSpawned(fruit);
			}

		}
示例#3
0
        private static bool FruitPolygonCollision(Fruit fruit, Polygon polygon, CCPoint polygonVelocity)
        {
            // Test whether the fruit collides
            bool didCollide = polygon.CollideAgainst(fruit.Collision);

            if (didCollide)
            {
                var circle = fruit.Collision;

                // Get the separation vector to reposition the fruit so it doesn't overlap the polygon
                var separation = CollisionResponse.GetSeparationVector(circle, polygon);
                fruit.Position += separation;

                // Adjust the fruit's Velocity to make it bounce:
                var normal = separation;
                normal.Normalize();
                fruit.Velocity = CollisionResponse.ApplyBounce(
                    fruit.Velocity, 
                    polygonVelocity, 
                    normal, 
                    GameCoefficients.FruitCollisionElasticity);

            }
            return didCollide;
        }
示例#4
0
 private void Destroy(Fruit fruit)
 {
     fruit.RemoveFromParent();
     fruitList.Remove(fruit);
 }
示例#5
0
        private void FruitVsBins(Fruit fruit)
        {
            foreach(var bin in fruitBins)
            {
                if(bin.Polygon.CollideAgainst(fruit.Collision))
                {
                    if(bin.FruitColor == fruit.FruitColor)
                    {
                        // award points:
                        score += 1 + fruit.ExtraPointValue;
                        scoreText.Score = score;
                        Destroy(fruit);
                        CCAudioEngine.SharedEngine.PlayEffect("FruitInBin");
                    }
                    else
                    {
                        EndGame();
                        CCAudioEngine.SharedEngine.PlayEffect("GameOver");
                    }

                    break;
                }
            }
        }
示例#6
0
        private void FruitVsPaddle(Fruit fruit)
        {
            bool didCollideWithPaddle = FruitPolygonCollision(fruit, paddle.Polygon, paddle.Velocity);
            if (didCollideWithPaddle)
            {
                bool didAddPoint = fruit.TryAddExtraPointValue();
                if(didAddPoint)
                {
                    CCAudioEngine.SharedEngine.PlayEffect("FruitPaddleBounce");
                }

            }
        }
示例#7
0
        private void HandleFruitAdded(Fruit fruit)
		{
			fruitList.Add (fruit);
			gameplayLayer.AddChild (fruit);
		}