public static void SetupCrazyMode() { Level = -1; Program.Referee.ClearRules(); Program.Referee.OutofControl = true; for (int i = 0; i < 50; i++) { string rule = Rule.GetNameRandomRule(); while (Rule.Rules[rule].Type == Rule.RuleType.POP) { rule = Rule.GetNameRandomRule(); } Referee.AddRule(rule); } Program.Referee.AddRule(Rule.Rules["top-down"]); Program.Referee.AddRule(Rule.Rules["Enemy hurty"]); Program.Referee.AddRule(Rule.Rules["control Player"]); Program.Referee.AddRule(Rule.Rules["Goal victory"]); Engine.SetLocation(new Location(new Description2D(0, 0, ScreenWidth, ScreenHeight))); Engine.AddEntity(Player.Create(Program.ScreenWidth / 4, Program.ScreenHeight / 2)); Point center = new Point(Program.ScreenWidth * 3 / 4, Program.ScreenHeight / 2); Engine.AddEntity(Goal.Create(center.X + Program.Random.Next(-32, 48), center.Y + Program.Random.Next(-48, 48))); Action <Location, Entity> moving = (location, entity) => { Enemy d2d = entity.Description as Enemy; d2d.ChangeCoordsDelta(d2d.VelX, Math.Sin(d2d.VelY)); Description2D locd2d = location.Description as Description2D; if (d2d.X < 0 || d2d.X > locd2d.Width) { d2d.VelX = -d2d.VelX; } if (d2d.Y < 0 || d2d.Y > locd2d.Height) { d2d.VelY = -d2d.VelY; } }; for (int i = 0; i < 20; i++) { Entity enemy = Enemy.Create(center.X + (int)(48 * Math.Cos(i / 20.0 * Math.PI * 2)), center.Y + (int)(48 * Math.Sin(i / 20.0 * Math.PI * 2))); enemy.TickAction = moving; //Engine.AddEntity(Enemy.Create(Program.Random.Next(16, Program.ScreenWidth - 16), Program.Random.Next(16, Program.ScreenHeight - 16))); Engine.AddEntity(enemy); } Engine.AddEntity(HeadsUpDisplay.Create()); Referee.Start(); }
public static void Main(string[] args) { WavPlayer.Init(WavProvider); WavPlayer.Play(); Keyboard = new WindowsKeyController(keyMap.ToDictionary(kvp => (int)kvp.Key, kvp => (int)kvp.Value)); Mouse = new WindowsMouseController(mouseMap.ToDictionary(kvp => (int)kvp.Key, kvp => (int)kvp.Value)); Builder = new GameBuilder(); Builder.GameEngine(new FixedTickEngine(TPS)) .GameView(new GameView2D(ScreenWidth, ScreenHeight, Scale, Scale, Color.DarkSlateGray)) .GameFrame(new GameFrame(new AvaloniaWindowBuilder(), 0, 0, ScreenWidth, ScreenHeight, Scale, Scale)) .Controller(Keyboard) .Controller(Mouse) .Build(); Engine = Builder.Engine; GameFrame frame = Builder.Frame; AvaloniaWindow window = frame.Window as AvaloniaWindow; Referee = new Referee(); Engine.TickEnd += Referee.Tick; Sprites(); Rules(); SetupLevels(); SetupTitleScreen(); Engine.TickEnd += (s, gs) => { if (Iframe > 0) { Iframe--; } if (Program.Keyboard[(int)Actions.ESCAPE].IsPress()) { Program.WavPlayer.Stop(); Program.WavProvider.RemoveAllMixerInputs(); StopMovingWindow(); SetupTitleScreen(); } if (Program.Keyboard[(int)Actions.DIAGS].IsPress()) { ShowDiags = !ShowDiags; } if (Program.Keyboard[(int)Actions.RESTART].IsPress()) { if ((Program.Referee.OutofControl || Program.Level == 7) && !Engine.Location.GetEntities <Banner>().Any()) { return; } if (Engine.Location.GetEntities <Banner>().FirstOrDefault()?.Text == "you win") { if (Level == -1) { for (int i = 0; i < 10; i++) { Referee.AddRule(Rule.GetNameRandomRule()); } } else { Level++; } } StopMovingWindow(); Program.WavPlayer.Stop(); Program.WavProvider.RemoveAllMixerInputs(); // Levels can call the reset with something different Referee.ResetTimer(); switch (Level) { case -1: SetupCrazyMode(); break; case 0: break; case 8: SetupCredits(); Level = 9; break; case 9: if (CreditsFinished) { SetupThanksForPlaying(); Level = 10; } break; case 10: SetupTitleScreen(); break; default: if (CreditsFinished) { StartingLevel = Level; Levels[Level - 1].SetupLevel(); } break; } if (Program.Diff == Difficulty.NORMAL && Level == 7) { Lives = 3; } else if (Program.Diff == Difficulty.EASY && Level == 7) { Lives = 4; } else { Lives = 1; } } }; Engine.Start(); while (true) { } }
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()); } }