public TankFish(FishTankFurniture tank, Item item) { _tank = tank; _texture = _tank.GetAquariumTexture(); string[] aquarium_fish_split = _tank.GetAquariumData()[item.ParentSheetIndex].Split('/'); fishIndex = int.Parse(aquarium_fish_split[0]); currentFrame = fishIndex; zPosition = Utility.RandomFloat(4f, 10f); Dictionary <int, string> fish_sheet_data = Game1.content.Load <Dictionary <int, string> >("Data\\Fish"); fishScale = 0.75f; if (fish_sheet_data.ContainsKey(item.ParentSheetIndex)) { string[] fish_split = fish_sheet_data[item.ParentSheetIndex].Split('/'); if (!(fish_split[1] == "trap")) { minimumVelocity = Utility.RandomFloat(0.25f, 0.35f); if (fish_split[2] == "smooth") { minimumVelocity = Utility.RandomFloat(0.5f, 0.6f); } if (fish_split[2] == "dart") { minimumVelocity = 0f; } } } if (aquarium_fish_split.Length > 1) { string fish_type_string = aquarium_fish_split[1]; if (fish_type_string == "eel") { fishType = FishType.Eel; minimumVelocity = Utility.Clamp(fishScale, 0.3f, 0.4f); } else if (fish_type_string == "cephalopod") { fishType = FishType.Cephalopod; minimumVelocity = 0f; } else if (fish_type_string == "ground") { fishType = FishType.Ground; zPosition = 4f; minimumVelocity = 0f; } else if (fish_type_string == "static") { fishType = FishType.Static; } else if (fish_type_string == "crawl") { fishType = FishType.Crawl; minimumVelocity = 0f; } else if (fish_type_string == "front_crawl") { fishType = FishType.Crawl; zPosition = 3f; minimumVelocity = 0f; } else if (fish_type_string == "float") { fishType = FishType.Float; } } if (aquarium_fish_split.Length > 2) { string[] array = aquarium_fish_split[2].Split(' '); idleAnimation = new List <int>(); string[] array2 = array; foreach (string frame4 in array2) { idleAnimation.Add(int.Parse(frame4)); } SetAnimation(idleAnimation); } if (aquarium_fish_split.Length > 3) { string animation_string3 = aquarium_fish_split[3]; string[] animation_split3 = animation_string3.Split(' '); dartStartAnimation = new List <int>(); if (animation_string3 != "") { string[] array2 = animation_split3; foreach (string frame3 in array2) { dartStartAnimation.Add(int.Parse(frame3)); } } } if (aquarium_fish_split.Length > 4) { string animation_string2 = aquarium_fish_split[4]; string[] animation_split2 = animation_string2.Split(' '); dartHoldAnimation = new List <int>(); if (animation_string2 != "") { string[] array2 = animation_split2; foreach (string frame2 in array2) { dartHoldAnimation.Add(int.Parse(frame2)); } } } if (aquarium_fish_split.Length > 5) { string animation_string = aquarium_fish_split[5]; string[] animation_split = animation_string.Split(' '); dartEndAnimation = new List <int>(); if (animation_string != "") { string[] array2 = animation_split; foreach (string frame in array2) { dartEndAnimation.Add(int.Parse(frame)); } } } Rectangle tank_bounds_local = _tank.GetTankBounds(); tank_bounds_local.X = 0; tank_bounds_local.Y = 0; position = Vector2.Zero; position = Utility.getRandomPositionInThisRectangle(tank_bounds_local, Game1.random); nextSwim = Utility.RandomFloat(0.1f, 10f); nextBubble = Utility.RandomFloat(0.1f, 10f); facingLeft = (Game1.random.Next(2) == 1); if (facingLeft) { velocity = new Vector2(-1f, 0f); } else { velocity = new Vector2(1f, 0f); } velocity *= minimumVelocity; if (fishType == FishType.Ground || fishType == FishType.Crawl || fishType == FishType.Static) { position.Y = 0f; } ConstrainToTank(); }
public virtual void Draw(SpriteBatch b, float alpha, float draw_layer) { SpriteEffects sprite_effects = SpriteEffects.None; int draw_offset = -12; int slice_size = 8; if (fishType == FishType.Eel) { slice_size = 4; } int slice_offset = slice_size; if (facingLeft) { sprite_effects = SpriteEffects.FlipHorizontally; slice_offset *= -1; draw_offset = -draw_offset - slice_size + 1; } float bob = (float)Math.Sin(Game1.currentGameTime.TotalGameTime.TotalSeconds * 1.25 + (double)(position.X / 32f)) * 2f; if (fishType == FishType.Crawl || fishType == FishType.Ground || fishType == FishType.Static) { bob = 0f; } float scale = GetScale(); int cols = _texture.Width / 24; int sprite_sheet_x = currentFrame % cols * 24; int sprite_sheet_y = currentFrame / cols * 48; int wiggle_start_pixels = 10; float wiggle_amount = 1f; if (fishType == FishType.Eel) { wiggle_start_pixels = 20; bob *= 0f; } if (fishType == FishType.Ground || fishType == FishType.Crawl || fishType == FishType.Static) { float angle = 0f; b.Draw(_texture, Game1.GlobalToLocal(GetWorldPosition() + new Vector2(0f, bob) * 4f * scale), new Rectangle(sprite_sheet_x, sprite_sheet_y, 24, 24), Color.White * alpha, angle, new Vector2(12f, 12f), 4f * scale, sprite_effects, draw_layer); } else if (fishType == FishType.Cephalopod || fishType == FishType.Float) { float angle2 = Utility.Clamp(velocity.X, -0.5f, 0.5f); b.Draw(_texture, Game1.GlobalToLocal(GetWorldPosition() + new Vector2(0f, bob) * 4f * scale), new Rectangle(sprite_sheet_x, sprite_sheet_y, 24, 24), Color.White * alpha, angle2, new Vector2(12f, 12f), 4f * scale, sprite_effects, draw_layer); } else { for (int slice = 0; slice < 24 / slice_size; slice++) { float multiplier3 = (float)(slice * slice_size) / (float)wiggle_start_pixels; multiplier3 = 1f - multiplier3; float velocity_multiplier2 = velocity.Length() / 1f; float time_multiplier = 1f; float position_multiplier = 0f; velocity_multiplier2 = Utility.Clamp(velocity_multiplier2, 0.2f, 1f); multiplier3 = Utility.Clamp(multiplier3, 0f, 1f); if (fishType == FishType.Eel) { multiplier3 = 1f; velocity_multiplier2 = 1f; time_multiplier = 0.1f; position_multiplier = 4f; } if (facingLeft) { position_multiplier *= -1f; } b.Draw(_texture, Game1.GlobalToLocal(GetWorldPosition() + new Vector2(draw_offset + slice * slice_offset, bob + (float)(Math.Sin((double)(slice * 20) + Game1.currentGameTime.TotalGameTime.TotalSeconds * 25.0 * (double)time_multiplier + (double)(position_multiplier * position.X / 16f)) * (double)wiggle_amount * (double)multiplier3 * (double)velocity_multiplier2)) * 4f * scale), new Rectangle(sprite_sheet_x + slice * slice_size, sprite_sheet_y, slice_size, 24), Color.White * alpha, 0f, new Vector2(0f, 12f), 4f * scale, sprite_effects, draw_layer); } } b.Draw(Game1.shadowTexture, Game1.GlobalToLocal(new Vector2(GetWorldPosition().X, (float)_tank.GetTankBounds().Bottom - zPosition * 4f)), null, Color.White * alpha * 0.75f, 0f, new Vector2(Game1.shadowTexture.Width / 2, Game1.shadowTexture.Height / 2), new Vector2(4f * scale, 1f), SpriteEffects.None, _tank.GetFishSortRegion().X - 1E-07f); }