Пример #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // Setting size and position of formular.
            this.Location    = new Point(0, 0);
            this.Size        = new Size(1000, 500);
            this.WindowState = FormWindowState.Maximized;

            formControl = new FormControl(this);
            formControl.MaximizeForm();

            // Initializing variables.
            saveDirectory = Environment.GetEnvironmentVariable("USERPROFILE")
                            + @"\AppData\Roaming\Jeinzi\RectangleGame\";
            screenshotDirectory = saveDirectory + @"screenshots\";
            showDebugInfo       = false;
            requestedFps        = 30;
            gameStateManager    = new Gamestate.GameStateManager();
            fpsStopwatch        = new Stopwatch();
            backBuffer          = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
            backGraphics        = Graphics.FromImage(backBuffer);
            screenGraphics      = this.CreateGraphics();

            // Create directory structure and database.
            CreateDirectories();
            Database.Connect(saveDirectory);

            // Starting threads.
            mainThread = new Thread(GameLoop);
            mainThread.IsBackground = true;
            mainThread.Start();
        }
Пример #2
0
        /******** Functions ********/

        public LevelState(GameStateManager gameStateManager)
        {
            // Randomize using ticks.
            random = new Random((int)DateTime.Now.Ticks);

            this.gameStateManager = gameStateManager;
            firstBlood            = false;
            victory        = false;
            stopwatch      = new Stopwatch();
            entities       = new List <Entity.Entity>();
            map            = new Map.Map(Program.mainForm.ClientSize.Width / 4 * 3, Program.mainForm.ClientSize.Height / 4 * 3);
            map.position.X = Program.mainForm.ClientSize.Width / 2 - map.size.Width;
            map.position.Y = Program.mainForm.ClientSize.Height / 2 - map.size.Height;

            layout = new Layout.Layout();
            layout.backgroundBrush = Brushes.Transparent;

            Layout.Box statusBox = new Layout.Box("statusBox");
            statusBox.percentageWidth    = 10;
            statusBox.percentageHeight   = 20;
            statusBox.percentageLocation = new PointF(89, 12.5f);

            // Redefining textbox standards.
            Textbox.SaveDefaultStyle();
            Textbox.defaultAnchor     = Anchor.Left;
            Textbox.defaultBorderline = Pens.Transparent;
            Textbox.defaultFill       = Brushes.Transparent;

            // Labels.
            Textbox timerLabel        = new Layout.Textbox("timerLabel");
            Textbox shotCounterLabel  = new Layout.Textbox("shotCounterLabel");
            Textbox enemyCounterLabel = new Layout.Textbox("enemyCounterLabel");
            Textbox scoreCounterLabel = new Layout.Textbox("scoreCounterLabel");

            timerLabel.parent             = statusBox;
            shotCounterLabel.parent       = statusBox;
            enemyCounterLabel.parent      = statusBox;
            scoreCounterLabel.parent      = statusBox;
            timerLabel.percentageY        = 5;
            shotCounterLabel.percentageY  = 30;
            enemyCounterLabel.percentageY = 55;
            scoreCounterLabel.percentageY = 80;
            timerLabel.text        = "Time:";
            shotCounterLabel.text  = "Shots:";
            enemyCounterLabel.text = "Hits:";
            scoreCounterLabel.text = "Score:";

            // Infoboxes.
            Textbox.defaultAnchor = Anchor.Right;

            Textbox timer        = new Textbox("timer");
            Textbox shotCounter  = new Textbox("shotCounter");
            Textbox enemyCounter = new Textbox("enemyCounter");
            Textbox scoreCounter = new Textbox("scoreCounter");

            timer.parent             = statusBox;
            shotCounter.parent       = statusBox;
            enemyCounter.parent      = statusBox;
            scoreCounter.parent      = statusBox;
            timer.percentageY        = timerLabel.percentageY;
            shotCounter.percentageY  = shotCounterLabel.percentageY;
            enemyCounter.percentageY = enemyCounterLabel.percentageY;
            scoreCounter.percentageY = scoreCounterLabel.percentageY;

            Textbox.RestoreDefaultStyle();

            // Adding boxes to layout.
            layout.AddBox(statusBox);
            layout.AddBox(timer);
            layout.AddBox(timerLabel);
            layout.AddBox(shotCounter);
            layout.AddBox(shotCounterLabel);
            layout.AddBox(enemyCounter);
            layout.AddBox(enemyCounterLabel);
            layout.AddBox(scoreCounter);
            layout.AddBox(scoreCounterLabel);

            // Already setting up victory dialogue.
#warning You may not set the relative position after setting the anchor or every child box will not show up correctly
            centerBox = new Layout.Box("centerBox");
            centerBox.percentageSize      = new SizeF(25, 15);
            centerBox.anchor              = Layout.Anchor.Center;
            centerBox.borderLine.Width    = 3;
            centerBox.borderLine.LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel;
            centerBox.fill = Brushes.LightBlue;

            caption             = new Layout.Textbox("caption");
            caption.parent      = centerBox;
            caption.text        = "Please enter your name:";
            caption.percentageY = 20;
            caption.anchor      = Layout.Anchor.CenterX;

            inputBox                     = new Layout.Inputbox("inputBox");
            inputBox.parent              = centerBox;
            inputBox.percentageY         = 60;
            inputBox.anchor              = Layout.Anchor.CenterX;
            inputBox.text                = "";
            inputBox.maxLength           = 15;
            inputBox.maxSize             = true;
            inputBox.textAnchor          = Layout.Anchor.Center;
            inputBox.OnDelimiterEntered += NameEntered;

            layout.AddBox(centerBox);
            layout.AddBox(caption);
            layout.AddBox(inputBox);
        }
Пример #3
0
        /******** Functions ********/

        public HighscoreState(GameStateManager gameStateManager)
        {
            this.gameStateManager = gameStateManager;
            timeRows = new List <string>();
            rushRows = new List <string>();

            // Creating layout.
            layout = new Layout.Layout();

            // Vertical division.
            Layout.Box upperBox = new Layout.Box("upperBox");
            upperBox.percentageSize = new SizeF(100, 20);
            upperBox.visible        = false;

            Layout.Box lowerBox = new Layout.Box("lowerBox");
            lowerBox.percentageSize = new SizeF(100, 80);
            lowerBox.location       = new Point(0, (int)((float)lowerBox.parent.height / 10 * 2));
            lowerBox.visible        = false;

            // Horizontal division.
            Layout.Box leftBox = new Layout.Box("leftBox");
            leftBox.parent         = lowerBox;
            leftBox.percentageSize = new SizeF((float)33.3, 100);
            leftBox.anchor         = Layout.Anchor.Left | Layout.Anchor.Top;
            leftBox.visible        = false;

            Layout.Box centerBox = new Layout.Box("centerBox");
            centerBox.parent         = lowerBox;
            centerBox.percentageSize = new SizeF((float)33.3, 100);
            centerBox.anchor         = Layout.Anchor.CenterX;
            centerBox.visible        = false;

            Layout.Box rightBox = new Layout.Box("rightBox");
            rightBox.parent         = lowerBox;
            rightBox.percentageSize = new SizeF((float)33.3, 100);
            rightBox.anchor         = Layout.Anchor.Right | Layout.Anchor.Top;
            rightBox.visible        = false;

            // Lists.
            Layout.Textbox caption = new Layout.Textbox("caption");
            caption.borderLine = new Pen(Brushes.Black, 3);
            caption.font       = new Font("ARIAL", 60);
            caption.text       = "Highscore";
            caption.parent     = upperBox;
            caption.anchor     = Layout.Anchor.Center;

            Layout.Box leftList = new Layout.Box("leftList");
            leftList.parent = leftBox;
            leftList.y      = 100;
            leftList.width  = 300;
            leftList.height = 400;
            leftList.anchor = Layout.Anchor.CenterX;

            Layout.Box centerList = new Layout.Box("centerList");
            centerList.parent = centerBox;
            centerList.y      = 100;
            centerList.width  = 300;
            centerList.height = 400;
            centerList.anchor = Layout.Anchor.CenterX;

            // Captions.
            Layout.Textbox leftCaption = new Layout.Textbox("leftCaption");
            leftCaption.parent = leftBox;
            leftCaption.text   = "Time mode:";
            leftCaption.x      = leftList.x;

            Layout.Textbox centerCaption = new Layout.Textbox("centerCaption");
            centerCaption.parent = centerBox;
            centerCaption.text   = "Rush mode:";
            centerCaption.x      = centerList.x;

            // Adding all to layout.
            layout.AddBox(upperBox);
            layout.AddBox(lowerBox);

            layout.AddBox(leftBox);
            layout.AddBox(centerBox);
            layout.AddBox(rightBox);

            layout.AddBox(leftList);
            layout.AddBox(centerList);

            layout.AddBox(caption);
            layout.AddBox(leftCaption);
            layout.AddBox(centerCaption);
        }
Пример #4
0
 public QuitState(GameStateManager gameStateManager)
 {
     this.gameStateManager = gameStateManager;
 }