protected Rect GenerateSpot(bool noGetConnectionSpace = false) { if (noGetConnectionSpace) { if (Rnd.Chance()) { return(GetCenterRect()); } } else { var r = Rnd.Float(); if (r < 0.33f) { return(GetConnectionSpace()); } else if (r < 0.66f) { return(GetCenterRect()); } } return(new Rect(new Dot(Rnd.Int(Left + 2, Right - 2), Rnd.Int(Top + 2, Bottom - 2)))); }
public override void Paint(Level level) { Painter.Fill(level, this, 3, Tile.Chasm); var c = Rnd.Int(2, 4); var p = Rnd.Chance(30); for (var i = 0; i < c; i++) { var platform = new MovingPlatform(); platform.X = Rnd.Int(Left + 4, Right - 4) * 16; platform.Y = Rnd.Int(Top + 4, Bottom - 4) * 16; platform.Controller = Rnd.Chance() ? PlatformController.ClockWise : PlatformController.CounterClockWise; level.Area.Add(platform); if (p && Rnd.Chance()) { var turret = new RotatingTurret(); level.Area.Add(turret); turret.Center = platform.Position + new Vector2(16, 12); } } }
public override void Update(float dt) { base.Update(dt); delay -= dt; if (delay <= 0) { delay = Rnd.Float(1f, 3f); var cn = Rnd.Int(1, 4); for (var i = 0; i < cn; i++) { Timer.Add(() => { var part = new ParticleEntity(new Particle(Controllers.Float, new TexturedParticleRenderer(CommonAse.Particles.GetSlice($"heart_{Rnd.Int(1, 4)}")))); part.Position = Center; if (TryGetComponent <ZComponent>(out var z)) { part.Position -= new Vector2(0, z.Z); } Area.Add(part); part.Particle.Velocity = new Vector2(Rnd.Float(8, 16) * (Rnd.Chance() ? -1 : 1), -Rnd.Float(30, 56)); part.Particle.Angle = 0; part.Particle.Alpha = 0.9f; part.Depth = Layers.InGameUi; }, i * 0.3f); } } }
public override void Init() { base.Init(); angle = Self.AngleTo(Self.Target) - (Rnd.Chance() ? -1 : 1) * 1.2f; Self.WarnLaser(angle); }
public override void Update(float dt) { base.Update(dt); lastParticle += dt; if (lastParticle >= 0.5f) { lastParticle = 0; var part = new ParticleEntity(new Particle(Controllers.Float, new TexturedParticleRenderer(CommonAse.Particles.GetSlice($"poison_{Rnd.Int(1, 4)}")))); part.Position = Entity.Center; if (Entity.TryGetComponent <ZComponent>(out var z)) { part.Position -= new Vector2(0, z.Z); } Entity.Area.Add(part); part.Particle.Velocity = new Vector2(Rnd.Float(8, 16) * (Rnd.Chance() ? -1 : 1), -Rnd.Float(30, 56)); part.Particle.Angle = 0; part.Particle.Alpha = 0.8f; part.Depth = Layers.InGameUi; } tillDamage -= dt; if (tillDamage <= 0) { tillDamage = Delay; Entity.GetComponent <HealthComponent>().ModifyHealth(-2, Entity); } }
public override void Update(float dt) { base.Update(dt); if (T >= 3f) { T = 0; for (var i = 0; i < 3; i++) { Timer.Add(() => { var part = new ParticleEntity(new Particle(Controllers.Float, new TexturedParticleRenderer(CommonAse.Particles.GetSlice($"sleep")))); part.Position = Self.Center; if (Self.TryGetComponent <ZComponent>(out var z)) { part.Position -= new Vector2(0, z.Z); } Self.Area.Add(part); part.Particle.Velocity = new Vector2(Rnd.Float(8, 16) * (Rnd.Chance() ? -1 : 1), -Rnd.Float(30, 56)); part.Particle.Angle = 0; part.Particle.Alpha = 0.9f; part.Depth = Layers.InGameUi; }, i * 0.5f); } } }
public override void Use(Entity entity, Item item) { if (!item.Used && (!Broken || Rnd.Chance())) { entity.GetComponent <HealthComponent>().Phases += (byte)Amount; } }
public override void Init() { base.Init(); a = Rnd.Chance(); Flip(); }
public override void Paint(Level level) { var fl = Rnd.Chance() ? Tiles.RandomFloorOrSpike() : Tiles.RandomSolid(); var w = GenerateSpot(); PaintTunnel(level, fl, w, true); if (fl == Tile.Lava) { PaintTunnel(level, Tiles.RandomFloorOrSpike(), w); } if (Rnd.Chance()) { PaintTunnel(level, Tiles.RandomFloorOrSpike(), w, true); } if (Rnd.Chance()) { PaintTunnel(level, fl.Matches(Tile.Dirt, Tile.Lava) ? Rnd.Chance() ? Tile.Water : Tile.Dirt : Tiles.RandomFloorOrSpike(), GenerateSpot()); } PaintTunnel(level, fl.Matches(Tile.Dirt, Tile.Lava) ? Rnd.Chance() ? Tile.Water : Tile.Dirt : Tiles.RandomFloorOrSpike(), w); }
public ConsumableParticle(TextureRegion r, Player p, bool item = false, Action call = null, bool emerald = false) { AlwaysActive = true; AlwaysVisible = true; region = r; Width = region.Width; Height = region.Height; player = p; offset = new Vector2(Rnd.Int(-4, 4), Height + Rnd.Int(-4, 4)); speed = Rnd.Float(1, 2f) * (Rnd.Chance() ? -1 : 1); var s = item ? Display.UiScale : Rnd.Float(1f, 2f); Tween.To(s, scale.X, x => scale.X = x, 0.3f); Tween.To(s, scale.Y, x => scale.Y = x, 0.3f); if (item) { target += new Vector2(Display.UiWidth, Display.UiHeight); } else if (emerald) { target += new Vector2(Display.UiWidth, 0); } callback = call; }
public override void Update(float dt) { if (Self.Target == null) { return; } base.Update(dt); if (T >= (Self.Raging ? 1f : 2f)) { if (Rnd.Chance(95)) { Self.lastAttack = (Self.lastAttack + 1) % 2; } if (Self.lastAttack == 0) { Become <SkullAttack>(); } else { Become <JumpState>(); } } }
public override void Update(float dt) { base.Update(dt); t += dt; if (GetComponent <HealthComponent>().HasNoHealth || disk == 0) { return; } tillNext -= dt; if (tillNext <= 0) { tillNext = Rnd.Float(1, 3f); var part = new ParticleEntity(new Particle(Controllers.Float, new TexturedParticleRenderer(CommonAse.Particles.GetSlice($"note_{Rnd.Int(1, 3)}")))); part.Position = Center; Area.Add(part); part.Particle.Velocity = new Vector2(Rnd.Float(8, 16) * (Rnd.Chance() ? -1 : 1), -Rnd.Float(40, 66)); part.Particle.Angle = 0; part.Depth = Layers.InGameUi; } }
public override bool HandleEvent(Event e) { if (e is ProjectileCreatedEvent pce && !pce.Projectile.Artificial) { pce.Projectile.OnHurt += (p, en) => { var room = p.Owner.GetComponent <RoomComponent>().Room; if (room == null || room.Tagged[Tags.MustBeKilled].Count == 0 || Rnd.Chance(20)) { return; } var target = room.FindClosest(p.Center, Tags.MustBeKilled, ent => ent != en); if (target != null) { var c = p.HasComponent <CircleBodyComponent>(); var pr = Projectile.Make(pce.Owner, p.Slice, p.AngleTo(target), 10, c, -1, p, p.Scale); pr.EntitiesHurt.AddRange(p.EntitiesHurt); pr.Center = p.Center; } }; } return(false); }
public override bool HandleEvent(Event e) { if (e is ProjectileCreatedEvent pce) { if (pce.Projectile.Parent?.Parent != null || Rnd.Chance(20)) { return(false); } pce.Projectile.OnHurt += (p, en) => { var v = p.GetAnyComponent <BodyComponent>(); var a = v.Velocity.ToAngle(); var s = v.Velocity.Length(); var c = p.HasComponent <CircleBodyComponent>(); for (var i = 0; i < 2; i++) { var pr = Projectile.Make(pce.Owner, p.Slice, a + 0.2f * (i == 0 ? -1 : 1), s, c, -1, p, p.Scale); pr.EntitiesHurt.AddRange(p.EntitiesHurt); pr.Center = p.Center; } p.Break(); }; } return(false); }
public override void Update(float dt) { base.Update(dt); if (T >= 0.1f) { count++; T = 0; if (count == 32) { Become <IdleState>(); return; } var a = (count * 3 / 8f * Math.PI) + Rnd.Float(-0.5f, 0.5f); var p = Projectile.Make(Self, "circle", a, 30f, scale: Rnd.Float(1f, 2f)); p.Color = Rnd.Chance() ? ProjectileColor.Yellow : ProjectileColor.Orange; p.AddLight(64f, p.Color); Camera.Instance.Shake(2); Self.GetComponent <AudioEmitterComponent>().EmitRandomized("mob_bee_swirly_shot"); } }
public static void Place(Vector2 where, Area area) { var sells = Rnd.Chance(60); if (sells) { where.Y -= 24; } var vampire = new Vampire(); area.Add(vampire); vampire.BottomCenter = where; if (!sells) { return; } var pool = Items.GeneratePool(Items.GetPool(ItemPool.Vampire)); var c = Rnd.Int(1, 4); var s = (int)Math.Floor(c / 2f) * 18; for (var i = 0; i < c; i++) { var stand = new VampireStand(); area.Add(stand); stand.Center = where + new Vector2((stand.Width + 4) * i - s, 4 + stand.Height); var id = Items.GenerateAndRemove(pool, null, true); stand.SetItem(Items.CreateAndAdd(id, area, false), null); } }
public override void PaintInside(Level level) { var m = Rnd.Int(4, 6); Painter.Fill(level, this, m, Tiles.RandomSolid()); m = Math.Max(3, m - (Rnd.Chance() ? 1 : 2)); var v = Rnd.Chance(); var h = !v || Rnd.Chance(); if (v) { PlaceStand(level, new Dot(Left + m, Top + m)); PlaceStand(level, new Dot(Right - m, Bottom - m)); } if (h) { PlaceStand(level, new Dot(Left + m, Bottom - m)); PlaceStand(level, new Dot(Right - m, Top + m)); } SetupStands(level); }
public override void Paint(Level level) { var w = GetWidth(); var h = GetHeight(); var s = Math.Min(w, h); s = Math.Max(5, Rnd.Int(5, s - 5)); var center = GetTileCenter(); var stand = new ItemStand(); level.Area.Add(stand); stand.Center = center * 16 + new Vector2(8, 8); stand.SetItem(Items.CreateAndAdd(Items.Generate(ItemPool.Treasure), level.Area), null); var c = (int)Math.Floor(s / 2f); var t = Rnd.Chance() ? Tile.Rock : Tile.MetalBlock; for (var x = center.X - c; x <= center.X + c; x++) { for (var y = center.Y - c; y <= center.Y + c; y++) { if (Math.Abs(x - center.X) + Math.Abs(y - center.Y) <= c && (center.X != x || center.Y != y)) { Painter.Set(level, new Dot(x, y), t); } } } Painter.Rect(level, this, 1, Tiles.RandomFloor()); }
public static Entity PlaceRandom(Vector2 where, Area area) { try { var chest = (Chest)Activator.CreateInstance(Instance.Generate()); if (!(chest is GlassChest || chest is ProtoChest) && Rnd.Chance(LevelSave.MimicChance)) { var mimic = new Mimic { Kind = chest.GetSprite(), Pool = chest.GetPool() }; area.Add(mimic); mimic.BottomCenter = where; return(mimic); } area.Add(chest); chest.BottomCenter = where; return(chest); } catch (Exception ex) { Log.Error(ex); } return(null); }
public static void Init() { t = Rnd.Float(1000); Time = Rnd.Float(24); if (Events.XMas && Run.Depth == 0) { Snows = true; return; } if (Rnd.Chance(10)) { if (!Events.XMas && Rnd.Chance(90)) { Rains = true; } else { Snows = true; } RainLeft = Rnd.Float(12f, 128f); } else { RainLeft = Rnd.Float(1f, 48f); } }
public override void Use(Entity entity, Item item) { base.Use(entity, item); var level = Run.Level; Audio.PlaySfx("item_map"); foreach (var e in entity.Area.Tagged[Tags.Room]) { var room = (Room)e; if (room.Type == RoomType.DarkMarket || room.Type == RoomType.Hidden) { continue; } if (Rnd.Chance(95) && room.Type != RoomType.Secret && room.Type != RoomType.Granny && room.Type != RoomType.OldMan) { for (var y = room.MapY; y < room.MapY + room.MapH; y++) { for (var x = room.MapX; x < room.MapX + room.MapW; x++) { level.Explored[level.ToIndex(x, y)] = true; } } room.Explored = true; } } }
public static void Update(float dt) { var d = dt * 0.01f; t += dt; RainLeft -= d; Time += d; if (RainLeft <= 0) { var rained = Rains || Snows; RainLeft = rained ? Rnd.Float(12f, 128f) : Rnd.Float(1f, 48f); if (!(Events.XMas && Run.Depth == 0)) { if (rained) { Rains = Snows = false; } else { if (Rnd.Chance(90)) { Rains = true; } else { Snows = true; } } } } RainAngle = (float)(Math.PI * 0.5f + Math.Sin(t * 0.01f) * 0.5f); }
private void StartLasers() { lasers.Clear(); spinV = 0; spinDir = Rnd.Chance() ? 1 : -1; Timer.Add(() => { GetComponent <AudioEmitterComponent>().EmitRandomizedPrefixed("item_laser", 4); }, 1f); for (var i = 0; i < 4; i++) { var angle = AngleTo(Target) + (i / 4f + 1 / 8f) * (float)Math.PI * 2f; WarnLaser(angle); Timer.Add(() => { var laser = Laser.Make(this, 0, 0, damage: 2, scale: 3, range: 64); laser.LifeTime = 10f; laser.Position = Center; laser.Angle = angle; lasers.Add(laser); }, 1f); } }
public override void AddComponents() { base.AddComponents(); AlwaysActive = true; Width = 12; Height = 10; AddComponent(new AnimationComponent("duck")); var b = new RectBodyComponent(0, 0, Width, Height); AddComponent(b); b.KnockbackModifier = 0; quantom = Rnd.Chance(1); if (Run.Depth == -2) { AddComponent(new CloseDialogComponent("control_4")); } else { AddComponent(new CloseDialogComponent($"duck_{(quantom ? 20 : 19)}")); } Become <IdleState>(); GetComponent <DialogComponent>().Dialog.Voice = 4; }
protected virtual void ProcessItem(Item item) { if (consumeChance > 0 && Rnd.Chance(consumeChance * 100)) { item.Done = true; } }
protected void PlaceStand(Level level, Dot where) { var stand = new SingleChoiceStand(); level.Area.Add(stand); stand.Center = where * 16 + new Vector2(8, 8); stands.Add(stand); standPositions.Add(where); if (!DisableBarrier && !SpawnedBarrier && Rnd.Chance(20)) { SpawnedBarrier = true; var t = Tiles.Pick(Tile.SpikeOnTmp, Tile.Rock); Painter.Set(level, where + new Dot(-1, 0), t); Painter.Set(level, where + new Dot(1, 0), t); Painter.Set(level, where + new Dot(0, -1), t); Painter.Set(level, where + new Dot(0, 1), t); if (t == Tile.Rock) { t = Tile.Rock; // Tiles.Pick(Tile.Chasm, Tile.Rock); Painter.Set(level, where + new Dot(-1, 1), t); Painter.Set(level, where + new Dot(1, 1), t); Painter.Set(level, where + new Dot(1, -1), t); Painter.Set(level, where + new Dot(-1, -1), t); } } }
public override void Paint(Level level) { if (Rnd.Chance()) { var x = Rnd.Int(Left + 1, Right - 2); Painter.Fill(level, new Rect().Setup(x, Top + 1, 2, Bottom - 1), Tile.Chasm); var platform = new MovingPlatform(); platform.X = x * 16; platform.Y = (Rnd.Int(Top + 1, Bottom - 2)) * 16; platform.Controller = PlatformController.UpDown; level.Area.Add(platform); } else { var y = Rnd.Int(Top + 1, Bottom - 2); Painter.Fill(level, new Rect().Setup(Left + 1, y, Right - 1, 2), Tile.Chasm); var platform = new MovingPlatform(); platform.X = (Rnd.Int(Left + 1, Right - 2)) * 16; platform.Y = y * 16; platform.Controller = PlatformController.LeftRight; level.Area.Add(platform); } }
public override void Paint(Level level) { if ((LevelSave.BiomeGenerated is JungleBiome && Rnd.Chance(50))) { var clip = Painter.Clip; Painter.Clip = null; Painter.Rect(level, this, 0, Tile.WallB); Painter.Clip = clip; } scourged = Rnd.Chance(Run.Scourge * 2 + 2); PaintInside(level); if (scourged) { for (var i = Left + 1; i <= Right - 1; i++) { for (var j = Top + 1; j <= Bottom - 1; j++) { if (level.Get(i, j) == Tile.FloorD) { level.Set(i, j, Tile.EvilFloor); } } } } }
public override void PaintInside(Level level) { var w = (GetWidth() - 1) / 2; var h = (GetHeight() - 1) / 2; var vr = Rnd.Chance(); var hr = !vr || Rnd.Chance(); var a = Rnd.Chance(); if (!a && Rnd.Chance()) { Painter.Set(level, GetTileCenter(), Tiles.RandomSolid()); } if (vr) { PlaceStand(level, new Dot(Left + w, Top + 3)); PlaceStand(level, new Dot(Left + w, Bottom - 3)); } if (hr) { PlaceStand(level, new Dot(Right - 3, Top + h)); PlaceStand(level, new Dot(Left + 3, Top + h)); } if (a) { PlaceStand(level, new Dot(Left + w, Top + h)); } SetupStands(level); }
public override void Paint(Level level) { base.Paint(level); var spot = new Dot(Rnd.Int(Left + 2, Right - 2), Rnd.Int(Top + 2, Bottom - 2)); try { ChestRegistry.PlaceRandom(spot * 16 + new Vector2(8, 12), level.Area); } catch (Exception e) { Log.Error(e); } for (var x = Left + 1; x < Right - 1; x++) { for (var y = Top + 1; y < Bottom - 1; y++) { if (Rnd.Chance(30)) { continue; } var prop = new BreakableProp { Sprite = infos[Rnd.Int(infos.Length)] }; level.Area.Add(prop); prop.BottomCenter = new Vector2(x + 0.5f, y + 1f) * 16 + Rnd.Vector(-4, 4); } } Painter.Set(level, spot, Tile.FloorD); }