Exemple #1
0
        private void Tick(Location location, Entity entity)
        {
            if (Program.Engine.Location.GetEntities <DialogBox>().Any())
            {
                return;
            }

            if (sound == null)
            {
                Boom();
            }

            Description2D d2d = entity.Description as Description2D;

            d2d.ChangeCoordsDelta(Math.Cos(dir) * 8, Math.Sin(dir) * 8);
            foreach (T enemy in location.GetEntities <T>())
            {
                if (d2d.IsCollision(enemy))
                {
                    location.RemoveEntity(enemy.Id);
                }
            }

            if (Program.Collision(d2d, location.GetEntities <Wall>().Select(w => (Description2D)w).ToList()))
            {
                location.RemoveEntity(Id);
            }
        }
Exemple #2
0
        public static bool Move(Description2D d2d, double deltaX, double deltaY, List <Description2D> walls)
        {
            bool undo = false;

            d2d.ChangeCoordsDelta(deltaX, 0);
            if (Program.Collision(d2d, walls))
            {
                undo = true;
                for (int i = 0; i < Math.Abs(deltaX); i++)
                {
                    d2d.ChangeCoordsDelta(-Math.Clamp(deltaX, -1, 1), 0);
                    if (!Program.Collision(d2d, walls))
                    {
                        break;
                    }
                }
            }

            d2d.ChangeCoordsDelta(0, deltaY);
            if (Program.Collision(d2d, walls))
            {
                undo = true;
                for (int i = 0; i < Math.Abs(deltaY); i++)
                {
                    d2d.ChangeCoordsDelta(0, -Math.Clamp(deltaY, -1, 1));
                    if (!Program.Collision(d2d, walls))
                    {
                        break;
                    }
                }
            }

            return(!undo);
        }
Exemple #3
0
        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();
        }
Exemple #4
0
        public static void Platformer(Location location, object obj)
        {
            if (obj == null)
            {
                return;
            }

            Description2D d2d = obj as Description2D;

            double speed = 3 * (Program.Referee.Piles[Rule.RuleType.SPEED].FirstOrDefault()?.Action(location, obj) ?? 1);

            List <Description2D> walls = location.GetEntities <Wall>().Select(w => w as Description2D).ToList();

            d2d.ChangeCoordsDelta(0, 1);
            bool onGround = Program.Collision(d2d, walls);

            d2d.ChangeCoordsDelta(0, -1);

            if (!onGround)
            {
                if (velocity < 10)
                {
                    velocity += 1.0;
                }
            }

            if (Program.Keyboard[(int)Actions.RIGHT].IsDown())
            {
                Move(d2d, speed, 0, walls);
            }
            if (Program.Keyboard[(int)Actions.UP].IsPress())
            {
                if (d2d.Y + velocity >= ((Description2D)location.Description).Height || onGround)
                {
                    velocity = -10;
                }
            }
            if (Program.Keyboard[(int)Actions.LEFT].IsDown())
            {
                Move(d2d, -speed, 0, walls);
            }

            if (d2d.Y + velocity <= ((Description2D)location.Description).Height)
            {
                //d2d.ChangeCoordsDelta(0, velocity);
                if (!Move(d2d, 0, velocity, walls))
                {
                    velocity = 0;
                }
            }
            else
            {
                d2d.SetCoords(d2d.X, ((Description2D)location.Description).Height);
                velocity = 0;
            }
        }
Exemple #5
0
        public static void WalkIndexing(Description2D d2d)
        {
            LivingEntity le = d2d as LivingEntity;

            if (le == null)
            {
                return;
            }

            le.walkIndex += 0.25;
        }
Exemple #6
0
        public static bool Collision(Description2D d1, List <Description2D> d2s)
        {
            foreach (Description2D d2 in d2s)
            {
                if (Collision(d1, d2))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #7
0
        private bool IsCollision(List <WallDescription> walls, Description2D description)
        {
            foreach (WallDescription wall in walls)
            {
                if (description.IsCollision(wall))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #8
0
 public void Draw(Description2D description)
 {
     if (description is TileMap)
     {
         AddDrawing(description.ZIndex, (g) => Draw(g, description as TileMap));
     }
     else
     {
         Description2D d2d = description as Description2D;
         if (d2d != null)
         {
             AddDrawing(description.ZIndex, (g) => Draw(g, d2d));
         }
     }
 }
Exemple #9
0
        public static void TopDown(Location location, object obj)
        {
            if (obj == null)
            {
                return;
            }

            if (location.GetEntities <Banner>().Any())
            {
                return;
            }

            Description2D d2d = obj as Description2D;

            MouseControllerInfo mci = Program.Mouse[(int)Actions.MOUSEINFO].Info as MouseControllerInfo;

            double dir = 0;

            if (mci != null)
            {
                dir = d2d.Direction(new Point(mci.X, mci.Y));
            }

            List <Description2D> walls = location.GetEntities <Wall>().Select(w => w as Description2D).ToList();

            double speed = 3 * (Program.Referee.Piles[Rule.RuleType.SPEED].FirstOrDefault()?.Action(location, obj) ?? 1);

            if (Program.Keyboard[(int)Actions.RIGHT].IsDown())
            {
                Move(d2d, speed * Math.Cos(dir + Math.PI / 2), speed * Math.Sin(dir + Math.PI / 2), walls);
            }
            if (Program.Keyboard[(int)Actions.UP].IsDown())
            {
                Move(d2d, speed * Math.Cos(dir), speed * Math.Sin(dir), walls);
            }
            if (Program.Keyboard[(int)Actions.LEFT].IsDown())
            {
                Move(d2d, speed * Math.Cos(dir - Math.PI / 2), speed * Math.Sin(dir - Math.PI / 2), walls);
            }
            if (Program.Keyboard[(int)Actions.DOWN].IsDown())
            {
                Move(d2d, speed * Math.Cos(dir + Math.PI), speed * Math.Sin(dir + Math.PI), walls);
            }
        }
Exemple #10
0
        public static void SetupCredits()
        {
            Engine.SetLocation(new Location(new Description2D(0, 0, ScreenWidth, ScreenHeight)));

            int         time = Program.ScreenHeight / 2 + 8;
            TickHandler t    = null;

            CreditsFinished = false;

            t = (s, o) =>
            {
                if (time-- <= 0)
                {
                    Engine.TickEnd -= t;
                    CreditsFinished = true;
                }
            };

            Engine.TickEnd += t;

            Action <Location, Entity> scroll = (loc, ent) =>
            {
                Description2D entd = ent.Description as Description2D;

                if (time > 0)
                {
                    entd.ChangeCoordsDelta(0, -1);
                }
            };

            int y = Program.ScreenHeight / 2;

            Engine.AddEntity(Text.Create("Credits", new Font("Arial", 32, FontStyle.Underline), ScreenWidth / 2, y + 16).AddTickAction(scroll));

            Engine.AddEntity(Text.Create("Developed by", new Font("Arial", 16, FontStyle.Underline), ScreenWidth / 2, y + 64).AddTickAction(scroll));
            Engine.AddEntity(Text.Create("Nicholas Denaro", new Font("Arial", 12), ScreenWidth / 2, y + 96).AddTickAction(scroll));

            Engine.AddEntity(Text.Create("Art by", new Font("Arial", 16, FontStyle.Underline), ScreenWidth / 2, y + 128).AddTickAction(scroll));
            Engine.AddEntity(Text.Create("System.Drawing.Common", new Font("Arial", 12), ScreenWidth / 2, y + 160).AddTickAction(scroll));

            Engine.AddEntity(Text.Create("Special thanks to", new Font("Arial", 16, FontStyle.Underline), ScreenWidth / 2, y + 192).AddTickAction(scroll));
            Engine.AddEntity(Text.Create("My faithful Twitch chat <3", new Font("Arial", 10), ScreenWidth / 2, y + 224).AddTickAction(scroll));
        }
Exemple #11
0
        public void Draw(DrawingContext gfx, Description2D description)
        {
            if (description != null)
            {
                if (description.HasImage())
                {
                    Rect dest = new Rect((int)(description.X + description.DrawOffsetX) - (description?.Sprite?.X ?? 0), (int)(description.Y + description.DrawOffsetY) - (description?.Sprite?.Y ?? 0), description.Width, description.Height);

                    System.Drawing.Image img = description.Image();
                    if (!storedBitmaps.ContainsKey(description.Image()))
                    {
                        using MemoryStream stream = new MemoryStream();
                        img.Save(stream, ImageFormat.Png);
                        stream.Position = 0;
                        storedBitmaps.Add(img, new Bitmap(stream));
                    }

                    gfx?.DrawImage(storedBitmaps[img], new Rect(0, 0, description.Width, description.Height), dest);
                }
            }
        }
Exemple #12
0
        public static void Main(string[] args)
        {
            GameBuilder builder = new GameBuilder();

            Bitmap bmp = BitmapExtensions.CreateBitmap(320 * 4, 240 * 4);

            bmp.MakeTransparent();
            Graphics gfx = Graphics.FromImage(bmp);

            gfx.Clear(Color.Transparent);

            VectorD[][] vectors = GenerateNoise(0, 20);

            double[][] val = new double[240 * 4][];
            Func <double, int, int, int> step = (val, steps, max) => ((int)(val * steps) * max) / steps;

            for (int y = 0; y < 240 * 4; y++)
            {
                val[y] = new double[320 * 4];
                for (int x = 0; x < 320 * 4; x++)
                {
                    //val[y][x] = (Noise(vectors, x, y, 320 * 5,  240 * 5) * 0.2 + Noise(vectors, x, y, 320, 240) * 0.1 + Noise(vectors, x, y, 320 * 10, 240 * 10) * 0.7);
                    double[] noises = new double[] {
                        Noise(vectors, x, y, 10, 10) * 0.1,
                        Noise(vectors, x, y, 20 * 5, 20 * 5) * 0.8,
                        Noise(vectors, x, y, 5, 5) * 0.08,
                        Noise(vectors, x, y, 3, 3) * 0.02,
                    };
                    val[y][x] = noises.Aggregate((total, v) => total + v);
                    int v = StepWithPercent(val[y][x], 255, 0.6, 0.65, 0.8, 1);
                    bmp.SetPixel(x, y, Color.FromArgb(255, v, v, v));
                }
            }

            MemoryStream stream = new MemoryStream();

            bmp.Save(stream, ImageFormat.Bmp);

            stream.Position = 0;
            new Sprite("tilemap", "Sprites/SunnysideWorld_Tileset_V0.1.png", 16, 16);
            //new Sprite("player", "Sprites/player.png", 16, 16);
            TileMap map = new TileMap(Sprite.Sprites["tilemap"], 320 * 2, 240 * 2);

            map.BackgroundColor = Brushes.Bisque;
            Tile[,] mapTiles    = new Tile[map.Width / 16, map.Height / 16];
            for (int y = 0; y < map.Height / 16; y++)
            {
                for (int x = 0; x < map.Width / 16; x++)
                {
                    double[] noises = new double[] {
                        Noise(vectors, x * 16, y * 16, 10, 10) * 0.1,
                        Noise(vectors, x * 16, y * 16, 20 * 5, 20 * 5) * 0.8,
                        Noise(vectors, x * 16, y * 16, 5, 5) * 0.08,
                        Noise(vectors, x * 16, y * 16, 3, 3) * 0.02,
                    };
                    int v = 3 - StepWithPercent(noises.Aggregate((total, v) => total + v), 4, 0.5, 0.6, 0.8, 1);
                    mapTiles[x, y] = new Tile((TileType)v);
                    //map[x, y] = f(1 + ((x + y) % 2), 1);
                }
            }

            for (int y = 0; y < map.Height / 16; y++)
            {
                for (int x = 0; x < map.Width / 16; x++)
                {
                    NeighborCalc(mapTiles, x, y);
                }
            }

            for (int y = 0; y < map.Height / 16; y++)
            {
                for (int x = 0; x < map.Width / 16; x++)
                {
                    //NeighborCalc2(mapTiles, x, y);
                    NeighborTransform(mapTiles, x, y);
                    map[x, y] = mapTiles[x, y].Modifier;
                }
            }

            new Sprite("noise", stream, 0, 0);

            Description2D noiseImg = new Description2D(Sprite.Sprites["noise"], 0, 0, 320 * 4, 240 * 4);

            builder.GameEngine(new FixedTickEngine(60))
            .GameView(new GameView2D(320 * 2, 240 * 2, 2, 2, Color.Bisque))
            .GameFrame(new GameEngine.UI.GameFrame(new AvaloniaWindowBuilder(), 0, 0, 320 * 2, 240 * 2, 2, 2))
            .StartingLocation(new Location(map))
            .Build();

            ////builder.Engine.AddEntity(new Entity(noiseImg));

            ////builder.Engine.TickEnd += (sender, state) => { d2d.ChangeCoordsDelta(0.1, 0); };

            builder.Engine.Start();

            while (true)
            {
            }
        }
Exemple #13
0
        public override void SetupLevel()
        {
            bool   wobbleDialog = false;
            Entity movingEnemy  = null;

            Program.Level = 5;

            Program.Engine.SetLocation(new Location(new Description2D(0, 0, Program.ScreenWidth, Program.ScreenHeight)));

            Stack <Action> deck = new Stack <Action>();

            Action spawnPowerups = () =>
            {
                Program.Engine.AddEntity(Powerup.Create("platformer", 224 - 8, Program.ScreenHeight / 2 + 80));
                Program.Engine.AddEntity(Powerup.Create("top-down", 256 - 8, Program.ScreenHeight / 2 + 80));
                Program.Engine.AddEntity(Powerup.Create("platformer", 288 - 8, Program.ScreenHeight / 2 + 80));
                Entity ent = Powerup.Create("top-down", 314 - 8, Program.ScreenHeight / 2 + 80);
                ent.TickAction = (loc, e) =>
                {
                    if (!wobbleDialog && ((Description2D)movingEnemy.Description).Distance((Description2D)e.Description) < 12)
                    {
                        Program.Engine.AddEntity(DialogBox.Create("It'll be hard to keep my orientation.\nBetter keep an eye on it."));
                        wobbleDialog = true;
                    }
                };
                Program.Engine.AddEntity(ent);
            };

            deck.Push(spawnPowerups);
            deck.Push(spawnPowerups);
            deck.Push(spawnPowerups);
            deck.Push(spawnPowerups);
            deck.Push(spawnPowerups);
            deck.Push(spawnPowerups);

            Program.Referee.ClearRules();

            Program.Referee.AddRule(Rule.Rules["Goal victory"]);
            Program.Referee.AddRule(Rule.Rules["Enemy hurty"]);
            Program.Referee.AddRule(Rule.Rules["Any pickup Powerup"]);
            Program.Referee.AddRule(Rule.Rules["control Player"]);
            Program.Referee.AddRule(Rule.Rules["platformer"]);

            Program.Engine.AddEntity(DialogBox.Create("Something seems different."));

            SinWaveSound sound = new SinWaveSound(true,
                                                  80, 44100 / Program.TPS * 30, 0, 44100 / Program.TPS * 5, 100, 44100 / Program.TPS * 5, 70, 44100 / Program.TPS * 5,
                                                  150, 44100 / Program.TPS * 30, 0, 44100 / Program.TPS * 5, 120, 44100 / Program.TPS * 5,
                                                  100, 44100 / Program.TPS * 30, 0, 44100 / Program.TPS * 5, 80, 44100 / Program.TPS * 5, 100, 44100 / Program.TPS * 5, 60, 44100 / Program.TPS * 5,
                                                  120, 44100 / Program.TPS * 30, 0, 44100 / Program.TPS * 5, 90, 44100 / Program.TPS * 5, 150, 44100 / Program.TPS * 5);

            sound.SetWaveFormat(44100, 2);

            Entity deckFlipper = new Entity(new Description2D(0, 0, 0, 0));
            int    timer       = 0;

            deckFlipper.TickAction = (loc, ent) =>
            {
                if (Program.Engine.Location.GetEntities <DialogBox>().Any() || Program.Engine.Location.GetEntities <Banner>().Any())
                {
                    return;
                }

                if (Program.Referee.IsStarted && deck.Any() && timer++ % (Program.TPS * 3.3) == 0)
                {
                    deck.Pop().Invoke();
                }
            };

            Program.Engine.AddEntity(deckFlipper);

            Program.Engine.AddEntity(Player.Create(Program.ScreenWidth / 2 - 32, Program.ScreenHeight - 24));

            Program.Engine.AddEntity(Goal.Create(Program.ScreenWidth - 64, Program.ScreenHeight / 2));

            Program.Engine.AddEntity(Enemy.Create(Program.ScreenWidth - 64 - 16, Program.ScreenHeight / 2));
            Program.Engine.AddEntity(Enemy.Create(Program.ScreenWidth - 64, Program.ScreenHeight / 2 - 16));
            Program.Engine.AddEntity(Enemy.Create(Program.ScreenWidth - 64 + 16, Program.ScreenHeight / 2));
            Program.Engine.AddEntity(Enemy.Create(Program.ScreenWidth - 64, Program.ScreenHeight / 2 + 16));

            //border
            Program.Engine.AddEntity(Wall.Create(0, 0, 16, Program.ScreenHeight));
            Program.Engine.AddEntity(Wall.Create(Program.ScreenWidth, 0, 16, Program.ScreenHeight));
            Program.Engine.AddEntity(Wall.Create(0, 0, Program.ScreenWidth, 16));
            Program.Engine.AddEntity(Wall.Create(0, Program.ScreenHeight, Program.ScreenWidth + 16, 16));

            //others
            Program.Engine.AddEntity(Wall.Create(0, Program.ScreenHeight / 2 + 32, 80, 16));

            Program.Engine.AddEntity(Wall.Create(80, Program.ScreenHeight / 2 + 80, 112, 16));

            Program.Engine.AddEntity(Wall.Create(112, Program.ScreenHeight / 2 + 32, 64, 16));
            Program.Engine.AddEntity(Wall.Create(176, Program.ScreenHeight / 2 - 80, 16, 208));

            Entity ent         = Powerup.Create("clicky attack", 32, 32);
            bool   dialogShown = false;

            ent.TickAction = (loc, e) =>
            {
                if (!dialogShown && loc.GetEntities <Player>().First().Distance((Description2D)e.Description) < 12)
                {
                    Program.Engine.AddEntity(DialogBox.Create("I bet I can use this to clear a path."));
                    dialogShown = true;
                }
            };
            Program.Engine.AddEntity(ent);

            Program.Engine.AddEntity(Powerup.Create("Enemy pickup Powerup", 176, 24));

            movingEnemy = Enemy.Create(224, Program.ScreenHeight / 2 + 80);
            double deltaX = 0.5f;

            movingEnemy.TickAction += (loc, ent) =>
            {
                if (Program.Engine.Location.GetEntities <DialogBox>().Any())
                {
                    return;
                }

                Description2D d2d = movingEnemy.Description as Description2D;
                if (d2d.X == Program.ScreenWidth - 16 || d2d.X == 208)
                {
                    deltaX = -deltaX;
                }

                d2d.ChangeCoordsDelta(deltaX, 0);
            };

            Program.Engine.AddEntity(movingEnemy);

            Program.Engine.AddEntity(HeadsUpDisplay.Create());

            Program.Referee.Start();

            Program.WavProvider.AddMixerInput((ISampleProvider)sound);
            Program.WavPlayer.Play();
        }
Exemple #14
0
        public static void SetupTitleScreen()
        {
            Referee.OutofControl = false;
            Level = 0;
            Referee.Stop();
            Engine.SetLocation(new Location(new Description2D(0, 0, ScreenWidth, ScreenHeight)));
            Description2D logoDescription = new Description2D(Sprite.Sprites["gmtklogo"], ScreenWidth / 2, ScreenHeight / 2);
            Entity        logo            = new Entity(logoDescription);
            int           timer           = TPS * 2;

            logo.TickAction = (loc, ent) =>
            {
                bool isPress = Program.Mouse[(int)Actions.ACTION].IsPress();

                if (logoDescription.ImageIndex < Sprite.Sprites["gmtklogo"].HImages - 1 && timer == TPS * 2)
                {
                    if (isPress)
                    {
                        logoDescription.ImageIndex = Sprite.Sprites["gmtklogo"].HImages - 1;
                    }
                    else
                    {
                        logoDescription.ImageIndex++;
                    }
                }
                else
                {
                    if (timer-- == 0 || timer > 0 && isPress)
                    {
                        timer = -1;
                        logoDescription.ImageIndex = 0;

                        Engine.AddEntity(Text.Create("RuleScramble", new Font("", 24, FontStyle.Italic | FontStyle.Bold | FontStyle.Underline), ScreenWidth / 2, 16));
                        Engine.AddEntity(Button.Create("Story Mode", () =>
                        {
                            Levels[StartingLevel - 1].SetupLevel();

                            if (Program.Diff == Difficulty.NORMAL && Level == 7)
                            {
                                Lives = 3;
                            }
                            else if (Program.Diff == Difficulty.EASY && Level == 7)
                            {
                                Lives = 4;
                            }
                            else
                            {
                                Lives = 1;
                            }
                        }, ScreenWidth / 2 - 128 / 2, ScreenHeight / 2 - 48));
                        Engine.AddEntity(Button.Create("Arcade Mode", SetupCrazyMode, ScreenWidth / 2 - 128 / 2, ScreenHeight / 2 + 8));
                        Engine.AddEntity(Button.Create("Credits", SetupCredits, ScreenWidth / 2 - 128 / 2, ScreenHeight / 2 + 64));


                        Engine.AddEntity(Text.Create("Story:", new Font("Arial", 10, FontStyle.Regular), ScreenWidth / 2 + 112, ScreenHeight / 2 - 40));
                        Button easyButton   = null;
                        Button normalButton = null;
                        Button hardButton   = null;

                        Entity button = Button.Create("easy", () =>
                        {
                            Program.Diff            = Difficulty.EASY;
                            easyButton.IsSelected   = true;
                            normalButton.IsSelected = false;
                            hardButton.IsSelected   = false;
                        }, ScreenWidth / 2 + 80, ScreenHeight / 2 - 16, 64, 32);
                        Engine.AddEntity(button);
                        easyButton = button.Description as Button;
                        if (Program.Diff == Difficulty.EASY)
                        {
                            easyButton.IsSelected = true;
                        }

                        button = Button.Create("normal", () =>
                        {
                            Program.Diff            = Difficulty.NORMAL;
                            easyButton.IsSelected   = false;
                            normalButton.IsSelected = true;
                            hardButton.IsSelected   = false;
                        }, ScreenWidth / 2 + 80, ScreenHeight / 2 + 16, 64, 32);
                        Engine.AddEntity(button);
                        normalButton = button.Description as Button;
                        if (Program.Diff == Difficulty.NORMAL)
                        {
                            normalButton.IsSelected = true;
                        }

                        button = Button.Create("hard", () =>
                        {
                            Program.Diff            = Difficulty.HARD;
                            easyButton.IsSelected   = false;
                            normalButton.IsSelected = false;
                            hardButton.IsSelected   = true;
                        }, ScreenWidth / 2 + 80, ScreenHeight / 2 + 48, 64, 32);
                        Engine.AddEntity(button);
                        hardButton = button.Description as Button;
                        if (Program.Diff == Difficulty.HARD)
                        {
                            hardButton.IsSelected = true;
                        }

                        Engine.AddEntity(Text.Create("Controls:\nWASD+Mouse\n[Radial\nmove toward\nmouse]\nR: Reset\nEsc: Title", new Font("Arial", 10, FontStyle.Regular), ScreenWidth / 8 + 8, ScreenHeight / 2 - 48));
                    }
                }
            };

            Engine.AddEntity(logo);
        }
Exemple #15
0
        public static void VVVVVVPlatformer(Location location, object obj)
        {
            if (obj == null)
            {
                return;
            }

            Description2D d2d = obj as Description2D;

            List <Description2D> walls = location.GetEntities <Wall>().Select(w => w as Description2D).ToList();

            d2d.ChangeCoordsDelta(0, Math.Clamp(velocityDirection, -1, 1));
            bool onGround = Program.Collision(d2d, walls);

            d2d.ChangeCoordsDelta(0, Math.Clamp(-velocityDirection, -1, 1));

            double speed = 3 * (Program.Referee.Piles[Rule.RuleType.SPEED].FirstOrDefault()?.Action(location, obj) ?? 1); //.Aggregate(1.0, (a, rule) => rule.Action(location) * a );

            if (!onGround)
            {
                velocity += velocityDirection;
            }

            velocity = Math.Clamp(velocity, -10, 10);

            // Rule.List.Contains(playstyle type value=top/down)
            if (Program.Keyboard[(int)Actions.RIGHT].IsDown())
            {
                Move(d2d, speed, 0, walls);
            }
            if (Program.Keyboard[(int)Actions.UP].IsPress())
            {
                if (onGround || d2d.Y + velocity >= ((Description2D)location.Description).Height || d2d.Y + velocity <= 0)
                {
                    velocityDirection = -velocityDirection;
                    velocity          = velocityDirection * 4;
                }
            }
            if (Program.Keyboard[(int)Actions.LEFT].IsDown())
            {
                Move(d2d, -speed, 0, walls);
            }

            if (velocityDirection > 0)
            {
                if (d2d.Y + velocity <= ((Description2D)location.Description).Height)
                {
                    if (!Move(d2d, 0, velocity, walls))
                    {
                        velocity = 0;
                    }
                }
                else
                {
                    d2d.SetCoords(d2d.X, ((Description2D)location.Description).Height);
                }
            }
            else
            {
                if (d2d.Y + velocity >= 0)
                {
                    if (!Move(d2d, 0, velocity, walls))
                    {
                        velocity = 0;
                    }
                }
                else
                {
                    d2d.SetCoords(d2d.X, 0);
                }
            }
        }
Exemple #16
0
        public void Hit(Description2D hitter, bool finisher, int balanceDiff, int damage)
        {
            if (this is Enemy)
            {
                this.Target = hitter as LivingEntity;
            }

            LivingEntity leHitter = hitter as LivingEntity;

            if (leHitter != null && ActiveSkill != null)
            {
                if (ActiveSkill.Name == "block")
                {
                    Program.Frame.PlaySound("Sounds.GAME_MENU_SCORE_SFX001755.wav");
                    ActiveSkill.Cooldown();
                    if (balanceDiff != 100)
                    {
                        ActiveSkill = null;
                        health     -= damage;
                        leHitter.animations.Queue(new AnimationChain(AnimationManager.Instance["blocked"].MakeInterruptable().MakePausing()));

                        return;
                    }
                }
                else if (ActiveSkill.Name == "counter")
                {
                    ActiveSkill.Cooldown();
                    leHitter.Hit(this, true, 100, damage);
                    ActiveSkill = null;
                    return;
                }
            }

            Program.Frame.PlaySound("Sounds.GAME_MENU_SCORE_SFX001771.wav");
            this.PreppedSkill = null;
            this.skillActivation?.Reset();
            stun        = 15;
            DrawOffsetX = 0;
            DrawOffsetY = 0;
            if (animations.Any() && animations.Peek().Peek().IsInterruptable())
            {
                animations.Pop();
                combo.Reset();
            }

            ActiveSkill = null;
            health     -= damage;
            balance    -= balanceDiff;
            if (balance <= 0 || IsDead())
            {
                if (animations.Any())
                {
                    animations.Pop();
                }

                if (!IsDead())
                {
                    animations.Push(new AnimationChain(AnimationManager.Instance["getup"].MakeInterruptable().MakePausing()));
                }

                animations.Push(new AnimationChain(AnimationManager.Instance[finisher || IsDead() ? "knockback" : "slideback"].MakeInterruptable().MakePausing()));
                knockbackFrom = hitter.Position;
                stun          = 0;
            }
        }
Exemple #17
0
        public static bool Collision(Description2D d1, Description2D d2)
        {
            return(d1.IsCollision(d2));

            /*double d1Size = Math.Sqrt(d1.Width * d1.Width + d1.Height * d1.Height / 4);
             * double d2Size = Math.Sqrt(d2.Width * d2.Width + d2.Height * d2.Height / 4);
             *
             * double dist = d1.Distance(d2);
             *
             * if (dist <= (d1Size + d2Size) / 1.5)
             * {
             *  Bitmap bmp = BitmapExtensions.CreateBitmap((int)(d1Size + d2Size) + 20, (int)(d1Size + d2Size) + 20);
             *  Graphics gfx = Graphics.FromImage(bmp);
             *  float minX = (float)Math.Min(d1.X - d1.Sprite.X, d2.X - d2.Sprite.X);
             *  float minY = (float)Math.Min(d1.Y - d1.Sprite.X, d2.Y - d2.Sprite.X);
             *  gfx.TranslateTransform(-minX + 10, -minY + 10);
             *
             *  Bitmap b1 = (Bitmap)d1.Image();
             *  Bitmap b2 = (Bitmap)d2.Image();
             *
             *  gfx.DrawImage(b1, (float)d1.X - d1.Sprite.X, (float)d1.Y - d1.Sprite.X);
             *  gfx.DrawImage(b2, (float)d2.X - d2.Sprite.X, (float)d2.Y - d2.Sprite.Y);
             *
             *  int total = 0;
             *  for (int i = 0; i < b1.Width; i++)
             *  {
             *      for (int j = 0; j < b1.Height; j++)
             *      {
             *          if (b1.GetPixel(i, j).A != 0)
             *          {
             *              total++;
             *          }
             *      }
             *  }
             *
             *  for (int i = 0; i < b2.Width; i++)
             *  {
             *      for (int j = 0; j < b2.Height; j++)
             *      {
             *          if (b2.GetPixel(i, j).A != 0)
             *          {
             *              total++;
             *          }
             *      }
             *  }
             *
             *  int count = 0;
             *  for (int i = 0; i < bmp.Width; i++)
             *  {
             *      for (int j = 0; j < bmp.Height; j++)
             *      {
             *          Color c = bmp.GetPixel(i, j);
             *          if (c.A != 0)
             *          {
             *              count++;
             *          }
             *      }
             *  }
             *
             *  return count != total;
             * }
             *
             * return false;*/
        }
Exemple #18
0
        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;
                }
            }
        }