private void Tick(Location location, Entity entity) { if (Program.Engine.Location.GetEntities <DialogBox>().Any()) { return; } if (sound == null) { sound = new SinWaveSound(true, 120, 44100 / Program.TPS * 20, 150, 44100 / Program.TPS * 30, 120, 44100 / Program.TPS * 10f, 0, 44100 / Program.TPS * 10f, 180, 44100 / Program.TPS * 5, 150, 44100 / Program.TPS * 20, 100, 44100 / Program.TPS * 30, 180, 44100 / Program.TPS * 10f, 0, 44100 / Program.TPS * 10f, 200, 44100 / Program.TPS * 5); sound.SetWaveFormat(44100, 2); Program.WavProvider.AddMixerInput((ISampleProvider)sound); Program.WavPlayer.Play(); } foreach (Bullet <BulletNull> bullet in location.GetEntities <Bullet <BulletNull> >()) { if (bullet.IsCollision(this)) { health -= 1; location.RemoveEntity(bullet.Id); } } if (health == 80 && !firstTransitionShown) { Program.Engine.AddEntity(DialogBox.Create($"[{machineName}] Try this on for size. >=^)")); savedHealth = 81; savedStealAttack = stealAttack; savedShiftRoom = shiftRoom; Program.Referee.AddRule("platformer"); attackTimerMax = 30; Program.Referee.AddRule(Rule.Rules["Goal hurty"]); firstTransitionShown = true; sound.Silent = true; sound = new SinWaveSound(true, 120, 44100 / Program.TPS * 10, 150, 44100 / Program.TPS * 15, 180, 44100 / Program.TPS * 5, 200, 44100 / Program.TPS * 5, 0, 44100 / Program.TPS * 15, 200, 44100 / Program.TPS * 5, 180, 44100 / Program.TPS * 10, 200, 44100 / Program.TPS * 15, 150, 44100 / Program.TPS * 5, 0, 44100 / Program.TPS * 15, 150, 44100 / Program.TPS * 10, 100, 44100 / Program.TPS * 15, 180, 44100 / Program.TPS * 5, 150, 44100 / Program.TPS * 5, 0, 44100 / Program.TPS * 15); sound.SetWaveFormat(44100, 2); Program.WavProvider.AddMixerInput((ISampleProvider)sound); Program.WavPlayer.Play(); } if (health == 70 && stealAttack == 0) { Program.Engine.AddEntity(DialogBox.Create($"[{machineName}] Quit it with that. >=^(")); Program.Referee.AddRule("no attack. haha."); location.AddEntity(Powerup.Create("shoot Boss", Program.ScreenWidth - 64, Program.ScreenHeight - 16)); stealAttack++; } if (health == 69) { attackTimerMax = 60; } if (health == 60 && !shiftRoom) { Program.Engine.AddEntity(DialogBox.Create($"[{machineName}] I bet you can't handle\nthis. >=^)")); savedHealth = 61; savedStealAttack = stealAttack; savedShiftRoom = shiftRoom; Program.Referee.AddRule("vvvvvv-platformer"); attackTimerMax = 60; Program.Referee.AddRule(Rule.Rules["Powerup hurty"]); Program.Referee.AddRule("be fast"); shiftRoom = true; for (int i = 0; i < 4; i++) { Entity wall = Powerup.Create("pop SPAWN", Program.ScreenWidth / 2 - 80 + i * 16, Program.ScreenHeight / 2); centerWalls.Add(wall.Id); location.AddEntity(wall); } attackTimerMax = 30; sound.Silent = true; sound = new SinWaveSound(true, 80, 44100 / Program.TPS * 30, 150, 44100 / Program.TPS * 15, 120, 44100 / Program.TPS * 30, 80, 44100 / Program.TPS * 7.5f, 0, 44100 / Program.TPS * 7.5f, 80, 44100 / Program.TPS * 7.5f, 120, 44100 / Program.TPS * 30); sound.SetWaveFormat(44100, 2); Program.WavProvider.AddMixerInput((ISampleProvider)sound); Program.WavPlayer.Play(); } if (health == 50 && stealAttack == 1) { Program.Engine.AddEntity(DialogBox.Create($"[{machineName}] I'll just take that\nagain. >=^D")); Program.Referee.AddRule("no attack. haha."); Entity trigger = Powerup.Create("shoot Boss", Program.ScreenWidth - 128, Program.ScreenHeight / 2); Guid triggerId = trigger.Id; trigger.AddTickAction((loc, ent) => { if (loc.GetEntities <Player>().First().Distance((Description2D)ent.Description) < 20) { Program.Referee.AddRule("shoot Boss"); loc.RemoveEntity(triggerId); } }); location.AddEntity(trigger); stealAttack++; } if (health == 40 && shiftRoom) { Program.Engine.AddEntity(DialogBox.Create($"[{machineName}] Why don't you\njust go? [ o\\ _ /o ]")); savedHealth = 41; savedStealAttack = stealAttack; savedShiftRoom = shiftRoom; Program.Referee.AddRule("pop SPEED"); Program.Referee.AddRule("top-down"); Program.Referee.AddRule("Enemy hurty"); attackTimer = 30; attackTimerMax = 30; shiftRoom = false; foreach (Guid guid in centerWalls) { location.RemoveEntity(guid); } double dir = location.GetEntities <Player>().First().Direction(new Point(Program.ScreenWidth / 2, Program.ScreenHeight / 2)) + Math.PI / 4; centerWalls.Clear(); for (int j = 0; j < 4; j++) { for (int i = 0; i < 12; i++) { int xoffset = (int)(Math.Cos(dir + j * Math.PI / 2) * i * 16); int yoffset = (int)(Math.Sin(dir + j * Math.PI / 2) * i * 16); Entity rotaty = Enemy.Create(Program.ScreenWidth / 2 + xoffset, Program.ScreenHeight / 2 + yoffset).AddTickAction((loc, ent) => { if (Program.Engine.Location.GetEntities <DialogBox>().Any()) { return; } Description2D enemyd = ent.Description as Description2D; double instantdir = enemyd.Direction(new Point(Program.ScreenWidth / 2, Program.ScreenHeight / 2)); double dist = enemyd.Distance(new Point(Program.ScreenWidth / 2, Program.ScreenHeight / 2)); enemyd.ChangeCoordsDelta(Math.Cos(instantdir + Math.PI / 2) * dist / 50, Math.Sin(instantdir + Math.PI / 2) * dist / 50); }); centerWalls.Add(rotaty.Id); location.AddEntity(rotaty); } sound.Silent = true; sound = new SinWaveSound(true, 60, 44100 / Program.TPS * 2, 80, 44100 / Program.TPS * 2, 100, 44100 / Program.TPS * 2, 120, 44100 / Program.TPS * 2, 0, 44100 / Program.TPS * 10, 100, 44100 / Program.TPS * 2, 120, 44100 / Program.TPS * 2, 140, 44100 / Program.TPS * 2, 160, 44100 / Program.TPS * 2, 0, 44100 / Program.TPS * 10, 140, 44100 / Program.TPS * 2, 160, 44100 / Program.TPS * 2, 180, 44100 / Program.TPS * 2, 200, 44100 / Program.TPS * 2, 0, 44100 / Program.TPS * 10); sound.SetWaveFormat(44100, 2); Program.WavProvider.AddMixerInput((ISampleProvider)sound); Program.WavPlayer.Play(); } } if (health == 30 && stealAttack == 2) { Program.Engine.AddEntity(DialogBox.Create($"[{machineName}] Good luck getting\nit back. [ x\\ _ /o ]")); Program.Referee.AddRule("no attack. haha."); location.AddEntity(Powerup.Create("shoot Boss", Program.ScreenWidth - 128, Program.ScreenHeight / 2)); stealAttack++; } if (health == 20 && !finalTransitionShown) { Program.Engine.AddEntity(DialogBox.Create($"[{machineName}] STO0oOOo0oOO0OPPpP")); savedHealth = 21; savedStealAttack = stealAttack; savedShiftRoom = shiftRoom; Program.Referee.AddRule("pop DEATH"); Program.Referee.AddRule("pop DEATH"); Program.Referee.AddRule("pop DEATH"); Program.Referee.AddRule("pop DEATH"); foreach (Guid guid in centerWalls) { location.RemoveEntity(guid); } attackTimer = 10; attackTimerMax = 10; originalWindowPosition = window.Position; finalTransitionShown = true; sound.Silent = true; sound = new SinWaveSound(true, 100, 44100 / Program.TPS * 10, 0, 44100 / Program.TPS * 10); sound.SetWaveFormat(44100, 2); Program.WavProvider.AddMixerInput((ISampleProvider)sound); Program.WavPlayer.Play(); } if (health == 0) { location.RemoveEntity(this.Id); Program.Engine.AddEntity(DialogBox.Create($"[{machineName}] NOOOOooOooooOooooooo...")); location.AddEntity(Banner.Create("you win")); if (windowAction != null) { Program.Engine.TickEnd -= windowAction; } window.Position = originalWindowPosition; health--; savedHealth = 100; savedStealAttack = 0; savedShiftRoom = false; sound.Silent = true; } if (health <= 0) { window.Position = originalWindowPosition; if (windowAction != null) { Program.Engine.TickEnd -= windowAction; } } if (attackTimer-- == 0) { attackTimer = attackTimerMax; //top-down if (health > 80) { int count = 6; for (int i = 0; i < count; i++) { double dir = this.Direction(location.GetEntities <Player>().First()) + (Math.PI / 3) - (i * 1.0 / count) * (Math.PI * 2.0 / 3) + (Program.Random.NextDouble() - 0.5) * Math.PI / 10; location.AddEntity(Enemy.Create((int)this.X, (int)this.Y).AddTickAction((l, e) => { if (Program.Engine.Location.GetEntities <DialogBox>().Any()) { return; } ((Description2D)e.Description).ChangeCoordsDelta(2 * Math.Cos(dir), 2 * Math.Sin(dir)); Enemy ed = (Enemy)e.Description; if (ed.X < 0 || ed.Y < 0 || ed.X > Program.ScreenWidth || ed.Y > Program.ScreenHeight) { l.RemoveEntity(ed.Id); } })); } } // platformer else if (health > 60) { attackTimer += Program.Random.Next(-10, 10); for (int i = 0; i < 3; i++) { location.AddEntity(Goal.Create(Program.ScreenWidth, Program.ScreenHeight - 16 - 16 * i).AddTickAction((l, e) => { if (Program.Engine.Location.GetEntities <DialogBox>().Any()) { return; } ((Description2D)e.Description).ChangeCoordsDelta(-5, 0); })); } } // vvvvvv-platformer else if (health > 40) { int y = attackTop ? 0 : Program.ScreenHeight / 2; for (int i = 0; i < 6; i++) { location.AddEntity(Powerup.Create("pop SPAWN", Program.ScreenWidth, y + 16 + 16 * i).AddTickAction((l, e) => { if (Program.Engine.Location.GetEntities <DialogBox>().Any()) { return; } ((Description2D)e.Description).ChangeCoordsDelta(-5, 0); })); } attackTop = !attackTop; } // top-down spinny else if (health > 20) { int yPos = Program.Random.Next(16, Program.ScreenHeight - 16); double delta = 0; location.AddEntity(Enemy.Create(Program.ScreenWidth, yPos).AddTickAction((l, e) => { if (Program.Engine.Location.GetEntities <DialogBox>().Any()) { return; } ((Description2D)e.Description).ChangeCoordsDelta(-delta, 0); delta += 0.25; })); } // just wait else { int velocity = (20 - health) * 2; double direction = Program.Random.NextDouble() * Math.PI * 2; if (windowAction != null) { Program.Engine.TickEnd -= windowAction; } location.AddEntity(Goal.Create(Program.Random.Next(16, Program.ScreenWidth - 16), Program.Random.Next(16, Program.ScreenHeight - 16))); location.AddEntity(Powerup.Create("pop SPEED", Program.Random.Next(16, Program.ScreenWidth - 16), Program.Random.Next(16, Program.ScreenHeight - 16))); location.AddEntity(Enemy.Create(Program.Random.Next(16, Program.ScreenWidth - 16), Program.Random.Next(16, Program.ScreenHeight - 16))); windowAction = (s, gs) => { if (Program.Engine.Location.GetEntities <DialogBox>().Any()) { return; } double shake = Program.Random.NextDouble() * Math.PI / 8; window.Position = window.Position .WithX((int)Math.Clamp(window.Position.X + Math.Cos(direction + shake - Math.PI / 4) * velocity, 0, 1920 - Program.ScreenWidth * Program.Scale)) .WithY((int)Math.Clamp(window.Position.Y + Math.Sin(direction + shake - Math.PI / 4) * velocity, 0, 1080 - Program.ScreenHeight * Program.Scale)); }; Program.Engine.TickEnd += windowAction; } } }
public void Tick(object sender, GameState state) { if (!IsStarted) { return; } if (Timer <= 0) { if (!state.Location.GetEntities <Banner>().Any()) { Program.Engine.AddEntity(Banner.Create("time expired")); } return; } if (state.Location.GetEntities <Banner>().Any() || state.Location.GetEntities <DialogBox>().Any()) { return; } Timer--; foreach (Stack <Rule> stack in Piles.Values) { if (stack.Any()) { if (stack.Peek().Type == Rule.RuleType.POP) { Rule.RuleType popType = (Rule.RuleType)Enum.Parse(typeof(Rule.RuleType), stack.Peek().Name.Split(' ')[1]); if (Piles[popType].Any()) { Piles[popType].Pop(); } if (stack.Any()) { stack.Pop(); } } else if (stack.Peek().Type != Rule.RuleType.SPAWN || Timer % Program.TPS == 0) { stack.Peek().Action(state.Location, null); } } } if (OutofControl) { if (Timer % Program.TPS == 0) { state.Location.AddEntity(Powerup.Create(Rule.GetNameRandomRule(), Program.Random.Next(16, Program.ScreenWidth - 16), Program.Random.Next(16, Program.ScreenWidth - 16))); } if (Timer % Program.TPS * 3 == 0) { // scroll through the list of rule types one by one string name = Rule.GetNameRandomRule(ruleTypes[ruleIndex++ % ruleTypes.Count]); if (name != null) { AddRule(name); } } } }
public static void Rules() { // TODO: Make it so the "Player" is what is being controlled new TouchRule <Player, Goal>("Goal victory", Rule.RuleType.VICTORY, (location, obj) => { if (!location.GetEntities <Banner>().Any() && Referee.IsStarted) { Referee.Stop(); Program.Engine.AddEntity(Banner.Create("you win")); if (Referee.OutofControl) { ArcadeWins++; } } }); new TouchRule <Player, Enemy>("Enemy victory", Rule.RuleType.VICTORY, (location, obj) => { if (!location.GetEntities <Banner>().Any() && Referee.IsStarted) { Referee.Stop(); Program.Engine.AddEntity(Banner.Create("you win")); if (Referee.OutofControl) { ArcadeWins++; } } }); new TouchRule <Player, Powerup>("Powerup victory", Rule.RuleType.VICTORY, (location, obj) => { if (!location.GetEntities <Banner>().Any() && Referee.IsStarted) { Referee.Stop(); Program.Engine.AddEntity(Banner.Create("you win")); if (Referee.OutofControl) { ArcadeWins++; } } }); new TouchRule <Player, Enemy>("Enemy hurty", Rule.RuleType.DEATH, (location, obj) => { if (!location.GetEntities <Banner>().Any() && Referee.IsStarted) { if (Iframe == 0 && Lives-- == 1) { Referee.Stop(); if (!Referee.OutofControl) { Program.Engine.AddEntity(Banner.Create("you lose")); } else { Program.Engine.AddEntity(Banner.Create($"you lose. Score: {ArcadeWins}")); ArcadeWins = 0; } } if (Iframe == 0) { Iframe = TPS; } } }); new TouchRule <Player, Powerup>("Powerup hurty", Rule.RuleType.DEATH, (location, obj) => { if (!location.GetEntities <Banner>().Any() && Referee.IsStarted) { if (Iframe == 0 && Lives-- == 1) { Referee.Stop(); if (!Referee.OutofControl) { Program.Engine.AddEntity(Banner.Create("you lose")); } else { Program.Engine.AddEntity(Banner.Create($"you lose. Score: {ArcadeWins}")); ArcadeWins = 0; } } if (Iframe == 0) { Iframe = TPS; } } }); new TouchRule <Player, Goal>("Goal hurty", Rule.RuleType.DEATH, (location, obj) => { if (!location.GetEntities <Banner>().Any() && Referee.IsStarted) { if (Iframe == 0 && Lives-- == 1) { Referee.Stop(); if (!Referee.OutofControl) { Program.Engine.AddEntity(Banner.Create("you lose")); } else { Program.Engine.AddEntity(Banner.Create($"you lose. Score: {ArcadeWins}")); ArcadeWins = 0; } } if (Iframe == 0) { Iframe = TPS; } } }); // TODO: Make it so the "Player" is what is being controlled new TouchRule <Player, Powerup>("Player pickup Powerup", Rule.RuleType.POWERUP, (location, obj) => { Powerup powerup = obj as Powerup; Program.Referee.AddRule(powerup.Rule); location.RemoveEntity(powerup.Id); ////Referee.AddRule(Rule.Rules["Enemy pickup Powerup"]); }); new TouchRule <Enemy, Powerup>("Enemy pickup Powerup", Rule.RuleType.POWERUP, (location, obj) => { Powerup powerup = obj as Powerup; Program.Referee.AddRule(powerup.Rule); location.RemoveEntity(powerup.Id); ////Referee.AddRule(Rule.Rules["Player pickup Powerup"]); }); new TouchRule <Description2D, Powerup>("Any pickup Powerup", Rule.RuleType.POWERUP, (location, obj) => { Powerup powerup = obj as Powerup; Program.Referee.AddRule(powerup.Rule); location.RemoveEntity(powerup.Id); ////Referee.AddRule(Rule.Rules["Player pickup Powerup"]); }); new Rule("clicky attack", Rule.RuleType.ATTACK, (location, obj) => { if (Program.Mouse[(int)Program.Actions.ACTION].IsPress()) { MouseControllerInfo mci = Program.Mouse[(int)Program.Actions.ACTION].Info as MouseControllerInfo; foreach (Enemy enemy in location.GetEntities <Enemy>()) { if (enemy.Distance(new Point(mci.X, mci.Y)) < 8) { location.RemoveEntity(enemy.Id); } } } }); new Rule("shoot Enemy", Rule.RuleType.ATTACK, (location, obj) => { if (location.GetEntities <DialogBox>().Any()) { return; } if (Program.Mouse[(int)Program.Actions.ACTION].IsPress()) { MouseControllerInfo mci = Program.Mouse[(int)Program.Actions.ACTION].Info as MouseControllerInfo; Player player = location.GetEntities <Player>().FirstOrDefault(); if (player == null) { return; } double dir = player.Direction(new Point(mci.X, mci.Y)); int spawnX = (int)(player.X + Math.Cos(dir) * 8); int spawnY = (int)(player.Y + Math.Sin(dir) * 8); location.AddEntity(Bullet <Enemy> .Create(spawnX, spawnY, dir)); } }); int shootTimer = 15; new Rule("shoot Boss", Rule.RuleType.ATTACK, (location, obj) => { if (location.GetEntities <DialogBox>().Any()) { return; } if (shootTimer-- <= 0 && Program.Mouse[(int)Program.Actions.ACTION].IsDown()) { shootTimer = 15; MouseControllerInfo mci = Program.Mouse[(int)Program.Actions.ACTION].Info as MouseControllerInfo; Player player = location.GetEntities <Player>().FirstOrDefault(); if (player == null) { return; } double dir = player.Direction(new Point(mci.X, mci.Y)); int spawnX = (int)(player.X + Math.Cos(dir) * 8); int spawnY = (int)(player.Y + Math.Sin(dir) * 8); location.AddEntity(Bullet <BulletNull> .Create(spawnX, spawnY, dir)); } }); new TouchRule <Player, Enemy>("Player kill Enemy", Rule.RuleType.ATTACK, (location, obj) => { Enemy enemy = obj as Enemy; location.RemoveEntity(enemy.Id); }); new TouchRule <Player, Goal>("Player kill Goal", Rule.RuleType.ATTACK, (location, obj) => { Goal goal = obj as Goal; location.RemoveEntity(goal.Id); }); new Rule("no attack. haha.", Rule.RuleType.ATTACK, (location, obj) => { }); new Rule("be fast", Rule.RuleType.SPEED, (location, obj) => { return(3); }); new Rule("be slow", Rule.RuleType.SPEED, (location, obj) => { return(0.8); }); new Rule("be normal", Rule.RuleType.SPEED, (location, obj) => { return(1); }); new Rule("spawn Powerup", Rule.RuleType.SPAWN, (location, obj) => { location.AddEntity(Powerup.Create(Rule.GetNameRandomRule(), Program.Random.Next(16, Program.ScreenWidth - 16), Program.Random.Next(16, Program.ScreenWidth - 16))); }); new Rule("spawn Enemy", Rule.RuleType.SPAWN, (location, obj) => { location.AddEntity(Enemy.Create(Program.Random.Next(16, Program.ScreenWidth - 16), Program.Random.Next(16, Program.ScreenWidth - 16))); }); new Rule("spawn Goal", Rule.RuleType.SPAWN, (location, obj) => { location.AddEntity(Goal.Create(Program.Random.Next(16, Program.ScreenWidth - 16), Program.Random.Next(16, Program.ScreenWidth - 16))); }); new Rule("control Player", Rule.RuleType.CONTROL, (location, obj) => { foreach (Player player in location.GetEntities <Player>()) { if (Referee.Piles[Rule.RuleType.PERSPECTIVE].Any()) { Referee.Piles[Rule.RuleType.PERSPECTIVE].Peek().Action(location, player); } } }); new Rule("control Enemy", Rule.RuleType.CONTROL, (location, obj) => { foreach (Enemy enemy in location.GetEntities <Enemy>()) { Referee.Piles[Rule.RuleType.PERSPECTIVE].Peek().Action(location, enemy); } }); new Rule("control Goal", Rule.RuleType.CONTROL, (location, obj) => { foreach (Goal goal in location.GetEntities <Goal>()) { Referee.Piles[Rule.RuleType.PERSPECTIVE].Peek().Action(location, goal); } }); new Rule("top-down", Rule.RuleType.PERSPECTIVE, ControlSchemas.TopDown); new Rule("platformer", Rule.RuleType.PERSPECTIVE, ControlSchemas.Platformer); new Rule("vvvvvv-platformer", Rule.RuleType.PERSPECTIVE, ControlSchemas.VVVVVVPlatformer); ////new Rule("colorblind", Rule.RuleType.OVERLAY, (location, obj) => ////{ ////}); ////new Rule("vertical-flip", Rule.RuleType.OVERLAY, (location, obj) => ////{ ////}); foreach (Rule.RuleType type in Enum.GetValues(typeof(Rule.RuleType))) { new Rule($"pop {type}", Rule.RuleType.POP, null); } Referee.AddRule(Rule.Rules["Goal victory"]); Referee.AddRule(Rule.Rules["Enemy hurty"]); Referee.AddRule(Rule.Rules["Player pickup Powerup"]); Referee.AddRule(Rule.Rules["clicky attack"]); Referee.AddRule(Rule.Rules["spawn Powerup"]); Referee.AddRule(Rule.Rules["control Player"]); Referee.AddRule(Rule.Rules["vvvvvv-platformer"]); for (int i = 0; i < 10; i++) { Referee.AddRule(Rule.GetNameRandomRule()); } }