コード例 #1
0
ファイル: Liquid.cs プロジェクト: DuckKnightDuel/Adam
        public void Update(Tile t)
        {
            GameWorld gameWorld = GameWorld.Instance;
            this.Player = GameWorld.Instance.Player;

            if (CollRectangle.Intersects(GameWorld.Instance.Player.GetCollRectangle()))
            {
                Player.TakeDamage(this, Player.MaxHealth);
            }

            //if (!isOnTop)
            //    return;

            if (_currentType == Type.Lava)
            {
                if (GameWorld.Instance.TileArray[GetTileIndex() - GameWorld.Instance.WorldData.LevelWidth].Id == 0)
                {
                    _particleTimer += GameWorld.Instance.GetGameTime().ElapsedGameTime.TotalSeconds;
                    if (_particleTimer > _restartTime)
                    {
                        Particle par = new Particle();
                        par.CreateLavaParticle(this, gameWorld);
                        gameWorld.Particles.Add(par);
                        _particleTimer = 0;
                    }
                }
            }
        }
コード例 #2
0
ファイル: Liquid.cs プロジェクト: DuckKnightDuel/Adam
 public void CheckOnTop(Tile[] array, GameWorld gameWorld)
 {
     //this.gameWorld = gameWorld;
     //int indexAbove = TileIndex - gameWorld.worldData.LevelWidth;
     //if (array[indexAbove].ID == 0)
     //{
     //    this.isOnTop = true;
     //}
 }
コード例 #3
0
ファイル: FallingBoulder.cs プロジェクト: DuckKnightDuel/Adam
        public void OnCollisionWithTerrainBelow(Entity entity, Tile tile)
        {
            Velocity.Y = 0;
            GravityStrength = 0;
            _hasFallen = true;

            StompSmokeParticle.Generate(10, this);
            _fallingSound.PlayNewInstanceOnce();
        }
コード例 #4
0
ファイル: Chest.cs プロジェクト: DuckKnightDuel/Adam
 public Chest(Tile tile)
 {
     //hello
     _openSound = new SoundFx("Sounds/Chest/open");
     _collRectangle = new Rectangle(tile.DrawRectangle.X, tile.DrawRectangle.Y, Main.Tilesize * 2, Main.Tilesize);
     _sourceTile = tile;
     _sourceTile.OnTileUpdate += Update;
     _sourceTile.OnTileDestroyed += SourceTile_OnTileDestroyed;
     _sourceTile.AnimationStopped = true;
 }
コード例 #5
0
ファイル: Particle.cs プロジェクト: DuckKnightDuel/Adam
 public DestructionTileParticle(Tile tile, Rectangle source)
 {
     Texture = tile.Texture;
     CollRectangle = new Rectangle(tile.DrawRectangle.Center.X, tile.DrawRectangle.Center.Y, 8, 8);
     SourceRectangle = source;
     Velocity.X = (float)(GameWorld.RandGen.NextDouble() * GameWorld.RandGen.Next(-5, 6));
     Velocity.Y = (float)(GameWorld.RandGen.NextDouble() * GameWorld.RandGen.Next(-5, 6));
     Position = new Vector2(CollRectangle.X, CollRectangle.Y);
     Opacity = 2;
 }
コード例 #6
0
ファイル: Liquid.cs プロジェクト: DuckKnightDuel/Adam
        public Liquid(Tile sourceTile, Type type)
        {
            CollRectangle = new Rectangle(sourceTile.DrawRectangle.X + 8, sourceTile.DrawRectangle.Y + 8, Main.Tilesize / 2, Main.Tilesize / 2);
            _particleTimer = GameWorld.RandGen.Next(0, 8) * GameWorld.RandGen.NextDouble();
            _restartTime = GameWorld.RandGen.Next(5, 8) * GameWorld.RandGen.NextDouble();
            if (_restartTime < 1)
                _restartTime = 1;
            _currentType = type;

            sourceTile.OnTileUpdate += Update;
            sourceTile.OnTileDestroyed += SourceTile_OnTileDestroyed;
        }
コード例 #7
0
ファイル: Chest.cs プロジェクト: DuckKnightDuel/Adam
 public void Update(Tile t)
 {
     Player.Player player = GameWorld.Instance.Player;
     if (player.GetCollRectangle().Intersects(_collRectangle) && !_isOpen)
     {
         // If player presses open button, open chest.
         if (InputHelper.IsKeyDown(Keys.W))
         {
             t.AnimationStopped = false;
             Open();
         }
     }
 }
コード例 #8
0
ファイル: Tile.cs プロジェクト: DuckKnightDuel/Adam
        /// <summary>
        ///     This is used for the tiles that have special textures for corners. In the spritesheet they are arranged in the same
        ///     way. This includes grass, sand, stone, and mesa.
        /// </summary>
        /// <param name="array">The tile array that will be analyzed.</param>
        /// <param name="mapWidth">The width of the map in tiles.</param>
        public void FindConnectedTextures(Tile[] array, int mapWidth)
        {
            _cornerPieces = new List<Tile>();

            // Wallpaper.
            if (Id == 109)
            {
                var indexAbove = TileIndex - mapWidth;
                var indexBelow = TileIndex + mapWidth;
                if (array[indexAbove].Id != 109)
                {
                    SubId = 1;
                }
                else if (array[indexBelow].Id != 109)
                {
                    SubId = 2;
                }
                else SubId = 0;
            }

            //Marble columns
            if (Id == 18)
            {
                var indexAbove = TileIndex - mapWidth;
                var indexBelow = TileIndex + mapWidth;
                if (array[indexAbove].Id != 18)
                {
                    SubId = 1;
                }
                else if (array[indexBelow].Id != 18)
                {
                    SubId = 2;
                }
                else SubId = 0;
            }

            //Marble Floor
            else if (Id == 3)
            {
                if (array[TileIndex - 1].Id != 3)
                    SubId = 2;
                else if (array[TileIndex + 1].Id != 3)
                    SubId = 1;
                else SubId = 0;
            }

            //Marble Ceiling
            else if (Id == 29)
            {
                if (array[TileIndex + 1].Id != 29)
                    SubId = 1;
                else if (array[TileIndex - 1].Id != 29)
                    SubId = 2;
                else SubId = 0;
            }

            //Fences
            else if (Id == 103)
            {
                if (array[TileIndex - mapWidth].Id != 103)
                    SubId = 1;
                else SubId = 0;
            }

            // Water.
            else if (Id == 23)
            {
                if (array[TileIndex - mapWidth].Id == 0)
                    SubId = 1;
                else SubId = 0;
            }

            // Lava.
            else if (Id == 24)
            {
                if (array[TileIndex - mapWidth].Id == 0)
                    SubId = 1;
                else SubId = 0;
            }

            //Default Connected Textures Pattern
            //"Please don't change this was a headache to make." -Lucas 2015

            if (!_hasConnectPattern)
                return;

            _mapWidth = mapWidth;
            _array = array;

            var m = TileIndex;
            var t = m - mapWidth;
            var b = m + mapWidth;
            var tl = t - 1;
            var tr = t + 1;
            var ml = m - 1;
            var mr = m + 1;
            var bl = b - 1;
            var br = b + 1;

            if (br >= array.Length || tl < 0)
                return;

            var topLeft = array[tl];
            var top = array[t];
            var topRight = array[tr];
            var midLeft = array[ml];
            var mid = array[m];
            var midRight = array[mr];
            var botLeft = array[bl];
            var bot = array[b];
            var botRight = array[br];

            if (topLeft.Id == mid.Id &&
                top.Id == mid.Id &&
                topRight.Id == mid.Id &&
                midLeft.Id == mid.Id &&
                midRight.Id == mid.Id &&
                botLeft.Id == mid.Id &&
                bot.Id == mid.Id &&
                botRight.Id == mid.Id)
                SubId = 0;

            if (topLeft.Id == mid.Id &&
                top.Id == mid.Id &&
                topRight.Id == mid.Id &&
                midLeft.Id == mid.Id &&
                midRight.Id == mid.Id &&
                botLeft.Id == mid.Id &&
                bot.Id == mid.Id &&
                botRight.Id != mid.Id)
                SubId = 0;

            if (topLeft.Id == mid.Id &&
                top.Id == mid.Id &&
                topRight.Id == mid.Id &&
                midLeft.Id == mid.Id &&
                midRight.Id == mid.Id &&
                botLeft.Id != mid.Id &&
                bot.Id == mid.Id &&
                botRight.Id == mid.Id)
                SubId = 0;

            if (topLeft.Id != mid.Id &&
                top.Id == mid.Id &&
                topRight.Id == mid.Id &&
                midLeft.Id == mid.Id &&
                midRight.Id == mid.Id &&
                botLeft.Id == mid.Id &&
                bot.Id == mid.Id &&
                botRight.Id == mid.Id)
                SubId = 0;

            if (top.Id != mid.Id &&
                midLeft.Id != mid.Id &&
                midRight.Id == mid.Id &&
                bot.Id == mid.Id)
                SubId = 4;

            if (top.Id != mid.Id &&
                midLeft.Id == mid.Id &&
                midRight.Id == mid.Id &&
                bot.Id == mid.Id)
                SubId = 5;

            if (top.Id != mid.Id &&
                midLeft.Id == mid.Id &&
                midRight.Id != mid.Id &&
                bot.Id == mid.Id)
                SubId = 6;

            if (topLeft.Id == mid.Id &&
                top.Id == mid.Id &&
                topRight.Id != mid.Id &&
                midLeft.Id == mid.Id &&
                midRight.Id == mid.Id &&
                botLeft.Id == mid.Id &&
                bot.Id == mid.Id &&
                botRight.Id == mid.Id)
                SubId = 0;

            if (top.Id == mid.Id &&
                midLeft.Id != mid.Id &&
                midRight.Id == mid.Id &&
                bot.Id == mid.Id)
                SubId = 8;

            if (top.Id != mid.Id &&
                midLeft.Id != mid.Id &&
                midRight.Id != mid.Id &&
                bot.Id != mid.Id)
                SubId = 9;

            if (top.Id == mid.Id &&
                midLeft.Id == mid.Id &&
                midRight.Id != mid.Id &&
                bot.Id == mid.Id)
                SubId = 10;

            if (top.Id != mid.Id &&
                midLeft.Id != mid.Id &&
                midRight.Id != mid.Id &&
                bot.Id == mid.Id)
                SubId = 11;

            if (top.Id == mid.Id &&
                midLeft.Id != mid.Id &&
                midRight.Id == mid.Id &&
                bot.Id != mid.Id)
                SubId = 12;

            if (top.Id == mid.Id &&
                midLeft.Id == mid.Id &&
                midRight.Id == mid.Id &&
                bot.Id != mid.Id)
                SubId = 13;

            if (top.Id == mid.Id &&
                midLeft.Id == mid.Id &&
                midRight.Id != mid.Id &&
                bot.Id != mid.Id)
                SubId = 14;

            if (top.Id == mid.Id &&
                midLeft.Id != mid.Id &&
                midRight.Id != mid.Id &&
                bot.Id == mid.Id)
                SubId = 15;

            if (top.Id != mid.Id &&
                midLeft.Id != mid.Id &&
                midRight.Id == mid.Id &&
                bot.Id != mid.Id)
                SubId = 16;

            if (top.Id != mid.Id &&
                midLeft.Id == mid.Id &&
                midRight.Id == mid.Id &&
                bot.Id != mid.Id)
                SubId = 17;

            if (top.Id != mid.Id &&
                midLeft.Id == mid.Id &&
                midRight.Id != mid.Id &&
                bot.Id != mid.Id)
                SubId = 18;

            if (top.Id == mid.Id &&
                midLeft.Id != mid.Id &&
                midRight.Id != mid.Id &&
                bot.Id != mid.Id)
                SubId = 19;

            //Special
            if (botRight.Id != mid.Id &&
                midRight.Id == mid.Id &&
                bot.Id == mid.Id)
            {
                var corner = new Tile();
                corner.Id = mid.Id;
                corner.DrawRectangle = DrawRectangle;
                corner.Texture = Texture;
                corner.SubId = 1;
                _cornerPieces.Add(corner);
            }

            if (botLeft.Id != mid.Id &&
                midLeft.Id == mid.Id &&
                bot.Id == mid.Id)
            {
                var corner = new Tile();
                corner.Id = mid.Id;
                corner.DrawRectangle = DrawRectangle;
                corner.Texture = Texture;
                corner.SubId = 2;
                _cornerPieces.Add(corner);
            }

            if (topLeft.Id != mid.Id &&
                midLeft.Id == mid.Id &&
                top.Id == mid.Id)
            {
                var corner = new Tile();
                corner.Id = mid.Id;
                corner.DrawRectangle = DrawRectangle;
                corner.Texture = Texture;
                corner.SubId = 3;
                _cornerPieces.Add(corner);
            }

            if (topRight.Id != mid.Id &&
                midRight.Id == mid.Id &&
                top.Id == mid.Id)
            {
                var corner = new Tile();
                corner.Id = mid.Id;
                corner.DrawRectangle = DrawRectangle;
                corner.Texture = Texture;
                corner.SubId = 7;
                _cornerPieces.Add(corner);
            }

            foreach (var corners in _cornerPieces)
            {
                corners.DefineTexture();
            }
        }
コード例 #9
0
ファイル: PlayerScript.cs プロジェクト: DuckKnightDuel/Adam
 private void Player_CollidedWithTileBelow(Entity entity, Tile tile)
 {
     entity.IsJumping = false;
 }
コード例 #10
0
ファイル: PlayerScript.cs プロジェクト: DuckKnightDuel/Adam
 private void OnTouchGround(Entity entity, Tile tile)
 {
     _airTimer.Reset();
     entity.IsJumping = false;
     entity.RemoveAnimationFromQueue("fall");
     entity.RemoveAnimationFromQueue("jump");
 }
コード例 #11
0
ファイル: Chest.cs プロジェクト: DuckKnightDuel/Adam
 private void SourceTile_OnTileDestroyed(Tile t)
 {
     _sourceTile.OnTileUpdate -= Update;
     _sourceTile.OnTileDestroyed -= SourceTile_OnTileDestroyed;
 }
コード例 #12
0
ファイル: Gem.cs プロジェクト: DuckKnightDuel/Adam
 /// <summary>
 /// Generates specified number of a particular type of gem in gameworld.
 /// </summary>
 /// <param name="gemId"></param>
 /// <param name="tile"></param>
 /// <param name="count"></param>
 public static void GenerateIdentical(byte gemId, Tile tile, int count)
 {
     for (int i = 0; i < count; i++)
     {
         Gem gem = new Gem(tile.DrawRectangle.Center.X, tile.DrawRectangle.Y - Main.Tilesize / 2, gemId);
         GameWorld.Instance.Entities.Add(gem);
     }
 }
コード例 #13
0
ファイル: Particle.cs プロジェクト: DuckKnightDuel/Adam
 public void CreateTileParticleEffect(Tile tile, Player.Player player)
 {
     CurrentParticle = ParticleType.TileParticle;
     Texture = tile.Texture;
     CollRectangle = new Rectangle(player.GetCollRectangle().Center.X - 2, player.GetCollRectangle().Y + player.GetCollRectangle().Height, 8, 8);
     SourceRectangle = new Rectangle(tile.SourceRectangle.X, tile.SourceRectangle.Y, 4, 4);
     SourceRectangle.X += (GameWorld.RandGen.Next(0, 4) * Main.Tilesize / 4);
     Velocity.X = (-player.GetVelocity().X / 2) * (float)GameWorld.RandGen.NextDouble();
     Velocity.Y = GameWorld.RandGen.Next(-1, 1);
     Opacity = 1;
 }
コード例 #14
0
ファイル: Particle.cs プロジェクト: DuckKnightDuel/Adam
 public Particle(Projectile projectile, Tile[] tileArray)
 {
     SourceRectangle = new Rectangle(0, 0, 32, 32);
     CurrentParticle = ParticleType.Impact;
     Texture = ContentHelper.LoadTexture("Explosion");
     if (projectile.GetVelocity().X > 0)
         CollRectangle = new Rectangle(tileArray[projectile.TileHit].DrawRectangle.X - 32, projectile.GetCollRectangle().Center.Y - 32, 64, 64);
     else CollRectangle = new Rectangle(tileArray[projectile.TileHit].DrawRectangle.X + 32, projectile.GetCollRectangle().Center.Y - 32, 64, 64);
     _frameCount = new Vector2(Texture.Width / 32, Texture.Height / 32);
 }
コード例 #15
0
ファイル: Item.cs プロジェクト: DuckKnightDuel/Adam
 private void Item_CollidedWithTerrain(Entity entity, Tile tile)
 {
     if (Math.Abs(Velocity.Y) > 3)
     {
         BounceSound?.Play();
     }
 }
コード例 #16
0
ファイル: Tile.cs プロジェクト: DuckKnightDuel/Adam
        public void AddRandomlyGeneratedDecoration(Tile[] array, int mapWidth)
        {
            //Add decoration on top of grass tile.
            if (Id == 1 && SubId == 5)
            {
                var indexAbove = TileIndex - mapWidth;
                if (array[indexAbove].Id == 0)
                {
                    var rand = GameWorld.RandGen.Next(0, 10);
                    if (rand == 0) //flower
                    {
                        array[indexAbove].Id = 17;
                    }
                    else if (rand == 1 || rand == 2) //tall grass
                    {
                        array[indexAbove].Id = 9;
                    }
                    else //short grass
                    {
                        array[indexAbove].Id = 7;
                    }

                    array[indexAbove].DefineTexture();
                }
            }

            // Random decorations for sand.
            if (Id == 5 && SubId == 5)
            {
                var indexAbove = TileIndex - mapWidth * 2;
                var indexToRight = TileIndex - mapWidth + 1;
                var indexTopRight = indexAbove + 1;
                if (array[indexAbove].Id == 0 && array[indexToRight].Id == 0 && array[indexTopRight].Id == 0)
                {
                    var rand = GameWorld.RandGen.Next(0, 100);
                    if (rand > 80)
                        array[indexAbove].Id = 44;

                    array[indexAbove].DefineTexture();
                }
            }

            // Random decoration for hellstone.
            if (Id == 4 && SubId == 5)
            {
                var indexAbove = TileIndex - mapWidth;
                if (array[indexAbove].Id == 0)
                {
                    var rand = GameWorld.RandGen.Next(0, 10);

                    // Skull.
                    if (rand == 0)
                    {
                        array[indexAbove].Id = 55;
                    }
                    array[indexAbove].DefineTexture();
                }
            }

            // Hellstone stalagmmite.
            if (Id == 4 && SubId == 13)
            {
                if (GameWorld.RandGen.Next(0, 5) == 1)
                {
                    var indexBelow = TileIndex + mapWidth;
                    var indexTwoBelow = indexBelow + mapWidth;
                    if (array[indexBelow].Id == 0 && array[indexTwoBelow].Id == 0)
                    {
                        array[indexBelow].Id = 56;
                        array[indexBelow].DefineTexture();
                    }
                }
            }

            // Randomly generate different plain textures for certain tiles.
            // Grass
            if (Id == 1 && SubId == 0 && GameWorld.RandGen.Next(0, 100) > 80)
            {
                switch (GameWorld.RandGen.Next(0, 4))
                {
                    case 0:
                        SubId = 101;
                        break;
                    case 1:
                        SubId = 102;
                        break;
                    case 2:
                        SubId = 103;
                        break;
                    case 3:
                        SubId = 104;
                        break;
                }

                DefineTexture();
            }
        }
コード例 #17
0
ファイル: Projectile.cs プロジェクト: DuckKnightDuel/Adam
 public void OnCollisionWithTerrainAnywhere(Entity entity, Tile tile)
 {
     Destroy();
 }
コード例 #18
0
ファイル: Gem.cs プロジェクト: DuckKnightDuel/Adam
 public void OnCollisionWithTerrainBelow(Entity entity, Tile tile)
 {
     BounceSound?.PlayNewInstanceOnce();
     BounceSound?.Reset();
     for (int i = 0; i < 5; i++)
     {
         GameWorld.Instance.Particles.Add(new StompSmokeParticle(this));
     }
 }