Пример #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "Test_Game.exe";
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.White;

            Console.Clear();

            Console.WriteLine("Debug Console Initialized");

            localEngine = new Game(this);
            localEngine.GameResolutionWidth  = 1280;
            localEngine.GameResolutionHeight = 720;
            //localEngine.Gravity = 1;

            GameObject      BackgroundObj     = new GameObject("BackgroundObj", localEngine);
            SpriteComponent bgspriteComponent = new SpriteComponent(localEngine, BackgroundObj, 0, 0, 1920, 1080, Image.FromFile("city.jpg"));

            BackgroundObj.AddComponent(bgspriteComponent);
            BackgroundObj.isUI = true;
            localEngine.CreateObject(BackgroundObj);

            Player Player = new Player("Player", localEngine);

            GameObject Ground = new GameObject("Ground", localEngine);

            BoxComponent b = new BoxComponent(localEngine, Ground, Color.Brown, new Rectangle(0, 0, localEngine.GameResolutionWidth, 50));

            Ground.AddComponent(b);
            Ground.SetX(0);
            Ground.SetY(localEngine.GameResolutionHeight - 100);
            Ground.GravityScale = 0;
            Console.WriteLine(Ground.GetY());

            localEngine.CreateObject(Ground);

            //Player.CanTick = false;
            Player.GravityScale = 1;

            GameObject GameRenderTextObj = new GameObject("GameRenderTextObj", localEngine);
            GameObject WindowSizeTextObj = new GameObject("WindowSizeTextObj", localEngine);

            localEngine.AddFPSCounter();

            TextComponent tc = new TextComponent(localEngine, GameRenderTextObj, 1, 20, Color.White, "Resolution Width", new FontFamily("Arial"), 12);

            GameRenderTextObj.AddComponent(tc);

            TextComponent tc2 = new TextComponent(localEngine, WindowSizeTextObj, 1, 50, Color.White, "Resolution Width", new FontFamily("Arial"), 12);

            WindowSizeTextObj.AddComponent(tc2);

            GameRenderTextObj.isUI = true;
            WindowSizeTextObj.isUI = true;


            localEngine.CreateUIObject(GameRenderTextObj);
            localEngine.CreateUIObject(WindowSizeTextObj);

            localEngine.PrintText(debugType.Debug, "'localEngine' Defined!");

            localEngine.PrintText(debugType.Debug, "'player' Defined!");

            //localEngine.SetBackgroundColour(255/2, 255/5, 255/2);

            //localEngine.printText(EngineClass.debugType.Debug, "player.Index = " + player.index);

            localEngine.GraphicsSettings.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.None;
            localEngine.GraphicsSettings.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;

            //                       engine reference      obj ref
            //BoxComponent c = new BoxComponent(localEngine, Player, 20 , 0, Color.Blue, 50, 50);
            //Player.AddComponent(c);

            //BoxComponent b = new BoxComponent(localEngine, Player, 0, 0, Color.Blue, 20, 20);
            //Player.AddComponent(b);

            Player.SetX(localEngine.GameResolutionWidth / 2 - Player.GetWidth() / 2);
            Player.SetY(localEngine.GameResolutionHeight / 2 - Player.GetHeight() / 2);

            SpriteComponent spr = new SpriteComponent(localEngine, Player, 0, 0, 50, 50, Image.FromFile("Mario.png"));

            //spr.resizeImage(50, 50);
            //spr.MakeTransparent();
            Player.AddComponent(spr);

            localEngine.CreateObject(Player);

            localEngine.PrintText(debugType.Debug, "Starting Engine");
            localEngine.startGame();

            GMusic.PlaySound();

            localEngine.FPS = 60; // set fps of the game
        }