/// <summary> /// This method is used at the loading and start of the game. It sets the size of the panel to the largest it will be then creates the Graphics according to its max size. /// Then it creates the level and performs a click of Medium size in the toolbar on its own. /// The panel needs to be this big or else the Graphics will be cut off when the user changes the size later to a bigger size. /// </summary> private void Start(int width, int height) { DrawingArea.Size = new Size(GAMEWINDOW_WIDTH * 3, GAMEWINDOW_HEIGHT * 2); g = DrawingArea.CreateGraphics(); _level = new Level(width, height, this, this.gameTimer, g, this.TopLevelControl); }
private void GameWindow_KeyDown(object sender, KeyEventArgs e) { Graphics g = DrawingArea.CreateGraphics(); switch (e.KeyCode) { case (Keys.W): _game.Stop(); MessageBox.Show("W"); _player.MoveUp(); _game.Start(g); break; case (Keys.A): _game.Stop(); MessageBox.Show("A"); _player.MoveLeft(); _game.Start(g); break; case (Keys.S): _game.Stop(); MessageBox.Show("S"); _player.MoveDown(); _game.Start(g); break; case (Keys.D): _game.Stop(); MessageBox.Show("D"); _player.MoveRight(); _game.Start(g); break; } }
private void DrawingArea_Paint(object sender, PaintEventArgs e) { _game.loadLevel(); Graphics g = DrawingArea.CreateGraphics(); _game.Start(g); }
public void RedrawGrid() { DrawingArea.Refresh(); DrawingOffsetHorizontal = (DrawingArea.Width / 2) - ((int)(ScaleNumber.Value * LoadedScreen.Width) / 2); DrawingOffsetVertical = (DrawingArea.Height / 2) - ((int)(ScaleNumber.Value * LoadedScreen.Height) / 2); Graphics g = DrawingArea.CreateGraphics(); SolidBrush n = new SolidBrush(Color.Black); SolidBrush w = new SolidBrush(Color.White); g.FillRectangle(w, DrawingOffsetHorizontal, DrawingOffsetVertical, ((float)(LoadedScreen.Width * ScaleNumber.Value)), ((float)(LoadedScreen.Height * ScaleNumber.Value))); for (ushort i = 0; i < LoadedScreen.Width; i++) { for (ushort x = 0; x < LoadedScreen.Height; x++) { if (LoadedScreen[i, x]) { g.FillRectangle(n, ((float)(i * ScaleNumber.Value)) + DrawingOffsetHorizontal, ((float)(x * ScaleNumber.Value)) + DrawingOffsetVertical, ((float)(ScaleNumber.Value)), ((float)(ScaleNumber.Value))); } } } for (int i = ((int)ScaleNumber.Value) + DrawingOffsetHorizontal; i <= (Math.Min(DrawingArea.Width, (LoadedScreen.Width * ScaleNumber.Value))) + DrawingOffsetHorizontal && ScaleNumber.Value >= 16; i += (int)ScaleNumber.Value) { Pen p = new Pen(Color.Blue); Int32 LowerLimit = Math.Min((int)ScaleNumber.Value * LoadedScreen.Height, DrawingArea.Height); g.DrawLine(p, new Point(i, DrawingOffsetVertical), new Point(i, LowerLimit + DrawingOffsetVertical)); } for (int i = ((int)ScaleNumber.Value) + DrawingOffsetVertical; i <= (Math.Min(DrawingArea.Height, (LoadedScreen.Height * ScaleNumber.Value))) + DrawingOffsetVertical && ScaleNumber.Value >= 16; i += (int)ScaleNumber.Value) { Pen p = new Pen(Color.Blue); Int32 LowerLimit = Math.Min((int)ScaleNumber.Value * LoadedScreen.Width, DrawingArea.Width); g.DrawLine(p, new Point(DrawingOffsetHorizontal, i), new Point(LowerLimit + DrawingOffsetHorizontal, i)); } }
private void RestartGUI_Click(object sender, EventArgs e) { _game.Stop(); _game.loadLevel(); Graphics g = DrawingArea.CreateGraphics(); _game.Start(g); }
void MouseDrag(object sender, MouseEventArgs e) { Int32 LimitX = (int)(ScaleNumber.Value * LoadedScreen.Width); Int32 LimitY = (int)(ScaleNumber.Value * LoadedScreen.Height); if (IsPressed && e.Location.X <= LimitX + DrawingOffsetHorizontal && e.Location.Y + DrawingOffsetVertical <= LimitY && e.Location.X > DrawingOffsetHorizontal && e.Location.Y > 0) { CursorPosition.Text = String.Format("[{0}, {1}]", (Math.Floor((e.Location.X - DrawingOffsetHorizontal) / ScaleNumber.Value)), (Math.Floor(e.Location.Y / ScaleNumber.Value))); UInt16 x = ((UInt16)(Math.Floor((e.Location.X - DrawingOffsetHorizontal) / ScaleNumber.Value))); UInt16 y = ((UInt16)(Math.Floor((e.Location.Y - DrawingOffsetVertical) / ScaleNumber.Value))); SetPixel(x, y, this.ActiveButton); SolidBrush sb = new SolidBrush(Color.LightBlue); Graphics g = DrawingArea.CreateGraphics(); g.FillRectangle(sb, ((float)(x * ScaleNumber.Value)) + DrawingOffsetHorizontal, ((float)(y * ScaleNumber.Value)) + DrawingOffsetVertical, ((float)(ScaleNumber.Value)), ((float)(ScaleNumber.Value))); } }
public Form1() { InitializeComponent(); drawArea = DrawingArea.CreateGraphics(); radioButton2.Checked = true; }