Esempio n. 1
0
        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());
            }
        }