Exemple #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            game = new Game();

            game.Initialize(panel1, panel1.DisplayRectangle.Size);
            game.InitializeGraphics();
            game.InitializeSound();
            game.InitializeResources();
            game.InternalUpdate();

            this.Show();
            gameTickTimer.Enabled = true;
            animationTimer.Enabled = true;

            control = new GameController(game, new GameMap(new Size(32, 32), new Size(24, 24)));

            hoverTile = new GameEntity();
            hoverTile.AddSprite("hover", new GameSprite(new SpriteFrame(new SpriteImage("resources/images/hover_tile.png", Color.Transparent), 1)));
            hoverTile.SetSprite("hover");
            hoverTile.ZIndex = 200; // * Hold den nær jorden ift. infantry som er på 100
            hoverTile.IsSelectable = false;

            RifleInfantry testUnit1 = new RifleInfantry();
            RifleInfantry testUnit2 = new RifleInfantry();
            RifleInfantry testUnit3 = new RifleInfantry();
            RifleInfantry testUnit4 = new RifleInfantry();

            testUnit1.WorldPosition = new Point(2, 2);
            testUnit2.WorldPosition = new Point(4, 1);
            testUnit3.WorldPosition = new Point(4, 2);
            testUnit4.WorldPosition = new Point(4, 3);

            testUnit1.MoveSpeed = 20;
            testUnit2.MoveSpeed = 50;
            testUnit3.MoveSpeed = 50;
            testUnit4.MoveSpeed = 40;

            control.PlaceEntity(testUnit1);
            control.PlaceEntity(testUnit2);
            control.PlaceEntity(testUnit3);
            control.PlaceEntity(testUnit4);

            control.PlaceEntity(hoverTile);

            // * Lav lidt skov
            Random rand = new Random();
            for(int i = 0; i < 15; i++)
            {
                GameEntity tree = new GameEntity();

                tree.AddSprite("idle", new GameSprite(new SpriteFrame(new SpriteImage(
                    GameController.resourceRoot + "/images/trees/" + rand.Next(1, 6) + ".png", Color.Transparent), 1))
                );
                tree.OccupationMatrix = new bool[2, 2] {
                    { false, true },
                    { false,  false }
                };
                tree.IsSelectable = false;
                tree.SetSprite("idle");
                tree.WorldPosition = new Point(
                    rand.Next(0, control.map.GetSize().Width),
                    rand.Next(0, control.map.GetSize().Height)
                );

                control.PlaceEntity(tree);
            }

            shouldRun = true;

            /*
            RenderThread renderThread = new RenderThread(new RenderDelegate(this.RenderGame));
            ThreadStart threadStart = new ThreadStart(renderThread.Start);
            new Thread(threadStart).Start(); // * Start renderingstråden
            */
        }