コード例 #1
0
        public void CreateSplitShot(World physics, Layer playLayer)
        {
            for (int i = 0; i < 3; i++)
            {
                splitShot[i].IsExpired = false;
                splitShot[i].IsVisible = true;
                splitShot[i].IsHit = false;
                splitShot[i].IsAwake = true;
                splitShot[i].IsCollidable = true;
                splitShot[i].Scale = shot.Scale;
                splitShot[i].SpriteType = Sprite.Type.FruitShot;
                splitShot[i].TintColor = new Color(255f, 255f, 255f, 255f);
                Vector2 position = ConvertUnits.ToSimUnits(shot.Location + shot.SpriteOrigin);
                if (i == 0) position = new Vector2(position.X - ConvertUnits.ToSimUnits(24f), position.Y);
                if (i == 2) position = new Vector2(position.X + ConvertUnits.ToSimUnits(24f), position.Y);
                splitShot[i].spriteBody = BodyFactory.CreateEllipse(physicsWorld, ConvertUnits.ToSimUnits(16f), ConvertUnits.ToSimUnits(16f), 6, 1.0f, position, splitShot[i]);
                splitShot[i].spriteBody.BodyType = BodyType.Dynamic;
                splitShot[i].spriteBody.Mass = GameSettings.FruitMass/3f;
                splitShot[i].Location = ConvertUnits.ToDisplayUnits( splitShot[i].spriteBody.Position);
                splitShot[i].spriteBody.Rotation = shot.spriteBody.Rotation;
                splitShot[i].spriteBody.LinearVelocity = shot.spriteBody.LinearVelocity;
                if (i == 0) splitShot[i].spriteBody.LinearVelocity = new Vector2(splitShot[i].spriteBody.LinearVelocity.X - ConvertUnits.ToSimUnits(100f), splitShot[i].spriteBody.LinearVelocity.Y);
                if (i == 2) splitShot[i].spriteBody.LinearVelocity = new Vector2(splitShot[i].spriteBody.LinearVelocity.X + ConvertUnits.ToSimUnits(100f), splitShot[i].spriteBody.LinearVelocity.Y);
                splitShot[i].spriteBody.AngularVelocity = shot.spriteBody.AngularVelocity+LevelDataManager.rand.Next(-10,11);
                splitShot[i].spriteBody.IgnoreGravity = false;
                splitShot[i].spriteBody.IsBullet = true;
                splitShot[i].spriteBody.Restitution = GameSettings.FruitBouncy;
                splitShot[i].spriteBody.Friction = GameSettings.FruitFriction;
                splitShot[i].HitPoints = (GameSettings.FruitHP/3)+1;
                playLayer.AddSpriteToLayer(splitShot[i]);
            }

            shot.spriteBody.ResetDynamics();
            shot.spriteBody.Enabled = false;
            shot.IsVisible = false;
            shot.spriteBody.Position = ConvertUnits.ToSimUnits(new Vector2 (-100f,-100f));
            shot.spriteBody.IgnoreGravity = true;
            shot.IsCollidable = false;
            isSplit = true;
            return;
        }
コード例 #2
0
        public DecoManager(ParallaxManager _parallaxManager, bool _isSound)
        {
            IsSound = _isSound;

            DecoSprites = new List<Sprite>();
            StarSprites = new List<Sprite>();
            CloudSprites = new List<Sprite>();
            WeatherSprites = new List<Sprite>();
            parallaxEngine = _parallaxManager;
            SoundManager.ClearSounds();

            int decoworld = LevelDataManager.world;

            if (decoworld == 6) //bonus world
            {
                switch (LevelDataManager.level)
                {
                    case 1:
                    case 2:
                    case 4:
                        {
                            decoworld = 1; //play grass
                            break;
                        }
                    case 5:
                    case 13:
                        {
                            decoworld = 2; //forest
                            break;
                        }
                    case 6:
                    case 7:
                    case 8:
                        {
                            decoworld = 3; //desert
                            break;
                        }
                    case 3:
                    case 14:
                        {
                            decoworld = 4; //snow
                            break;
                        }
                    case 9:
                    case 10:
                    case 11:
                    case 12:
                    case 15:
                        {
                            decoworld = 5; //factory
                            break;
                        }
                    default:
                        break;
                }
            }

            if (decoworld != 5)
            {
                #region ROLL RANDOM TIME DAY, SUNSET, NIGHT
                int timeRoll = LevelDataManager.rand.Next(1, 11);
                if (timeRoll < 5) //day 40%
                {
                    for (int i = 0; i < parallaxEngine.worldLayers[0].layerSprites.Count; i++)
                    {
                        parallaxEngine.worldLayers[0].layerSprites[i].TextureID = 34;
                    }
                    IsSunset = false;
                    IsNight = false;
                }
                if (timeRoll == 5 || timeRoll == 6) //sunset 20%
                {
                    for (int i = 0; i < parallaxEngine.worldLayers[0].layerSprites.Count; i++)
                    {
                        parallaxEngine.worldLayers[0].layerSprites[i].TextureID = 35;
                    }
                    IsSunset = true;
                    IsNight = false;
                }
                if (timeRoll > 6) //night 40%
                {
                    for (int i = 0; i < parallaxEngine.worldLayers[0].layerSprites.Count; i++)
                    {
                        parallaxEngine.worldLayers[0].layerSprites[i].TextureID = 36;
                    }
                    IsNight = true;
                    IsSunset = false;
                    if (IsSound) SoundManager.Play(SoundManager.Sound.EffectCricketsLoop, true, false);
                }
                #endregion
            }

            if (LevelDataManager.world == 5 && LevelDataManager.level == 5)
            {
                for (int i = 0; i < parallaxEngine.worldLayers[0].layerSprites.Count; i++)
                {
                    parallaxEngine.worldLayers[0].layerSprites[i].TextureID = 36;
                }
                IsNight = true;
            }

            #region REMOVE PLACED MOON OR ADD MOON
            if (!IsNight && parallaxEngine.worldLayers[1].layerSprites[0].TextureID == 33) parallaxEngine.worldLayers.RemoveAt(1);
            if (IsNight && parallaxEngine.worldLayers[1].layerSprites[0].TextureID != 33)
            {
                int maxMoonHeight = (int)Math.Sqrt(Camera.ViewportHeight) * 70;
                Layer moonLayer = new Layer("moon", Vector2.Zero, false, true, false, 0f, Vector2.Zero, false, 0f, Vector2.Zero);
                Vector2 moonLocation = new Vector2( LevelDataManager.rand.Next(-400,Camera.ViewportWidth+150), (float)Math.Pow((float)LevelDataManager.rand.Next(0, maxMoonHeight) / 100f, (2.0)));
                Sprite moon = new Sprite(33, 0, moonLocation, false);
                moonLayer.AddSpriteToLayer(moon);
                parallaxEngine.worldLayers.Insert(1, moonLayer);
            }
            #endregion

            #region CREATE STARS
            if (IsNight)
            {
                starPerCycle = numberOfStars / 10;
                int maxStarHeight = (int)Math.Sqrt(Camera.ViewportHeight) * 70;
                Layer starLayer = new Layer("stars", Vector2.Zero, false, true, false, 0f, Vector2.Zero, false, 0f, Vector2.Zero);
                for (int i = 0; i < numberOfStars; i++)
                {
                    int starID = 21 + LevelDataManager.rand.Next(0, 2);
                    Vector2 starLocation = new Vector2(LevelDataManager.rand.Next(0, Camera.ViewportWidth), (float)Math.Pow((float)LevelDataManager.rand.Next(0, maxStarHeight) / 100f, (2.0)));
                    Sprite star = new Sprite(starID, 0, starLocation, true);
                    star.IsAwake = false;
                    star.Scale = (float)LevelDataManager.rand.Next(50, 101) / 100f;
                    star.TotalRotation = MathHelper.ToRadians(LevelDataManager.rand.Next(0, 361));
                    star.TintColor *= (float)LevelDataManager.rand.Next(0, 101) / 100f;
                    StarSprites.Add(star);
                    starLayer.AddSpriteToLayer(star);
                }
                parallaxEngine.worldLayers.Insert(1, starLayer);
            }

            #endregion

            if (parallaxEngine.worldLayers[0].layerSprites[0].TextureID == 36 || parallaxEngine.worldLayers[0].layerSprites[0].TextureID == 35 || parallaxEngine.worldLayers[0].layerSprites[0].TextureID == 34)
            {
                #region CREATE CLOUD LAYER
                cloudsPerCycle = numberOfClouds / 10;
                int maxCloudHeight = 400;
                Layer cloudLayer = new Layer("clouds", Vector2.Zero, false, true, false, 0f, Vector2.Zero, false, 0f, Vector2.Zero);
                for (int i = 0; i < numberOfClouds; i++)
                {
                    Vector2 cloudLocation = new Vector2(LevelDataManager.rand.Next(-200, Camera.ViewportWidth + 200), LevelDataManager.rand.Next(-100, maxCloudHeight));
                    Sprite cloud = new Sprite(23, LevelDataManager.rand.Next(0, 3), cloudLocation, true);
                    cloud.IsAwake = false;
                    if (IsSunset) cloud.TextureIndex += 3;
                    if (IsNight) cloud.TextureIndex += 6;
                    cloud.Scale = (float)LevelDataManager.rand.Next(100, 401) / 100f;
                    if (LevelDataManager.rand.Next(0, 2) == 0) cloud.IsFlippedHorizontally = true;
                    if (IsSunset) cloud.TintColor = duskTint;
                    if (IsNight) cloud.TintColor = nightTint;
                    cloud.TintColor *= (float)LevelDataManager.rand.Next(0, 51) / 100f;
                    cloud.Velocity = LevelDataManager.rand.Next(20, 60);
                    if (LevelDataManager.rand.Next(0, 2) == 0) cloud.Velocity *= -1;
                    CloudSprites.Add(cloud);
                    cloudLayer.AddSpriteToLayer(cloud);
                }
                if (IsNight) parallaxEngine.worldLayers.Insert(3, cloudLayer);
                if (IsSunset) parallaxEngine.worldLayers.Insert(1, cloudLayer);
                if (!IsSunset && !IsNight) parallaxEngine.worldLayers.Insert(1, cloudLayer);
                #endregion
            }

            #region CREATE WEATHER
            if (decoworld == 0) weather = Weather.Pollen;
            if (decoworld == 1) weather = Weather.Pollen;
            if (decoworld == 2) weather = Weather.Leaf;
            if (numberOfClouds > 70 && LevelDataManager.rand.Next(0, 2) == 0) weather = Weather.Rain; //50% chance of rain if cloud cover in top 20% (10% chance total)
            if (decoworld == 4) weather = Weather.Snow;
            if (decoworld == 3) weather = Weather.None;
            if (decoworld == 5) weather = Weather.None;

            int partID = 0;
            int tiles = 1;
            weatherLayer = new Layer("weather",weatherParallax,false,true,false,0f,Vector2.Zero,false,0f,Vector2.Zero);
            if (weather == Weather.Rain)
            {
                partID = 26;
                numberOfWeatherParticles = Math.Max(0, numberOfClouds - 60) * LevelDataManager.rand.Next(6,13);
                if (IsSound) SoundManager.Play(SoundManager.Sound.EffectRainLoop, true, false);
            }
            if (weather == Weather.Snow)
            {
                numberOfWeatherParticles = Math.Max(0, numberOfClouds - 30) * LevelDataManager.rand.Next(2,5);
                partID = 27;
                tiles = 5;
            }
            if (weather == Weather.Pollen)
            {
                numberOfWeatherParticles = LevelDataManager.rand.Next(10, 21);
                partID = 25;
                tiles = 3;
            }
            if (weather == Weather.Leaf)
            {
                numberOfWeatherParticles = LevelDataManager.rand.Next(8, 16);
                partID = 24;
                tiles = 9;
            }
            //weatherPartPerCycle = numberOfWeatherParticles / 10;
            weatherPartPerCycle = numberOfWeatherParticles;
            for (int i = 0; i < numberOfWeatherParticles; i++)
            {
                Vector2 weatherParticleLocation = Camera.ScreenToWorld(new Vector2(LevelDataManager.rand.Next(0, Camera.Viewport.Width),
                                                              LevelDataManager.rand.Next(0, Camera.Viewport.Height)),weatherLayer.LayerParallax);
                Sprite weatherP = new Sprite(partID, LevelDataManager.rand.Next(0, tiles), Vector2.Zero, true);
                weatherP.IsAwake = false;
                if (weather == Weather.Rain) NewRain(weatherP, weatherParticleLocation);
                if (weather == Weather.Snow) NewSnow(weatherP,weatherParticleLocation);
                if (weather == Weather.Pollen) NewPollen(weatherP,weatherParticleLocation);
                if (weather == Weather.Leaf) NewLeaf(weatherP,weatherParticleLocation);
                WeatherSprites.Add(weatherP);
                weatherLayer.AddSpriteToLayer(weatherP);
            }

            #endregion

            #region TINT
            for (int i = 0; i < parallaxEngine.worldLayers.Count; i++)
            {
                for (int j = 0; j < parallaxEngine.worldLayers[i].SpriteCount; j++)
                {
                    if (parallaxEngine.worldLayers[i].layerSprites[j].TextureID < 20 ||
                        (parallaxEngine.worldLayers[i].layerSprites[j].IsEffect && parallaxEngine.worldLayers[i].layerSprites[j].TextureID >= 24))
                    {
                        TintSprite(parallaxEngine.worldLayers[i].layerSprites[j]);
                    }

                    //tint for rain
                    if (weather == Weather.Rain)
                    {
                        if (parallaxEngine.worldLayers[i].layerSprites[j].TextureID < 20 || parallaxEngine.worldLayers[i].layerSprites[j].SpriteType == Sprite.Type.Deco ||
                            parallaxEngine.worldLayers[i].layerSprites[j].TextureID == 34 || parallaxEngine.worldLayers[i].layerSprites[j].TextureID == 35 || parallaxEngine.worldLayers[i].layerSprites[j].TextureID == 36 ||
                            parallaxEngine.worldLayers[i].layerSprites[j].IsEffect)
                        {
                            parallaxEngine.worldLayers[i].layerSprites[j].TintColor = Color.Lerp(parallaxEngine.worldLayers[i].layerSprites[j].TintColor, Color.Gray,0.5f);
                        }
                        Tint = Color.Lerp(Tint, Color.Gray, 0.5f);
                    }
                }
            }
            #endregion
        }