diff options
| author | Richie Moch <[email protected]> | 2018-12-23 23:41:07 -0600 |
|---|---|---|
| committer | Richie Moch <[email protected]> | 2018-12-23 23:41:07 -0600 |
| commit | 87546f325f6fb24dcc5ab34851cc06b074d79984 (patch) | |
| tree | 4905888bc331bc9bb9d5ca060a4a5811210213b2 /ShiftOS.Main/Apps | |
| parent | 8f34b3a0c7118abb81526a3dc5f435ba8f8485f8 (diff) | |
| download | shiftos-rewind-87546f325f6fb24dcc5ab34851cc06b074d79984.tar.gz shiftos-rewind-87546f325f6fb24dcc5ab34851cc06b074d79984.tar.bz2 shiftos-rewind-87546f325f6fb24dcc5ab34851cc06b074d79984.zip | |
Wrote Breakout, and only with minimal bugs this time!
Diffstat (limited to 'ShiftOS.Main/Apps')
| -rw-r--r-- | ShiftOS.Main/Apps/Breakout.Designer.cs (renamed from ShiftOS.Main/Apps/Pong.Designer.cs) | 49 | ||||
| -rw-r--r-- | ShiftOS.Main/Apps/Breakout.cs | 112 | ||||
| -rw-r--r-- | ShiftOS.Main/Apps/Breakout.resx (renamed from ShiftOS.Main/Apps/Pong.resx) | 0 | ||||
| -rw-r--r-- | ShiftOS.Main/Apps/Pong.cs | 83 |
4 files changed, 129 insertions, 115 deletions
diff --git a/ShiftOS.Main/Apps/Pong.Designer.cs b/ShiftOS.Main/Apps/Breakout.Designer.cs index 4b9bd01..d36d691 100644 --- a/ShiftOS.Main/Apps/Pong.Designer.cs +++ b/ShiftOS.Main/Apps/Breakout.Designer.cs @@ -1,6 +1,6 @@ namespace ShiftOS.Main.Apps { - partial class Pong + partial class Breakout { /// <summary> /// Required designer variable. @@ -29,37 +29,17 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - this.playerPaddle = new System.Windows.Forms.PictureBox(); - this.cpuPaddle = new System.Windows.Forms.PictureBox(); this.ball = new System.Windows.Forms.PictureBox(); this.gameTimer = new System.Windows.Forms.Timer(this.components); - ((System.ComponentModel.ISupportInitialize)(this.playerPaddle)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.cpuPaddle)).BeginInit(); + this.playerPaddle = new System.Windows.Forms.PictureBox(); ((System.ComponentModel.ISupportInitialize)(this.ball)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.playerPaddle)).BeginInit(); this.SuspendLayout(); // - // playerPaddle - // - this.playerPaddle.BackColor = System.Drawing.Color.White; - this.playerPaddle.Location = new System.Drawing.Point(27, 153); - this.playerPaddle.Name = "playerPaddle"; - this.playerPaddle.Size = new System.Drawing.Size(22, 103); - this.playerPaddle.TabIndex = 0; - this.playerPaddle.TabStop = false; - // - // cpuPaddle - // - this.cpuPaddle.BackColor = System.Drawing.Color.White; - this.cpuPaddle.Location = new System.Drawing.Point(751, 153); - this.cpuPaddle.Name = "cpuPaddle"; - this.cpuPaddle.Size = new System.Drawing.Size(22, 103); - this.cpuPaddle.TabIndex = 1; - this.cpuPaddle.TabStop = false; - // // ball // this.ball.BackColor = System.Drawing.Color.White; - this.ball.Location = new System.Drawing.Point(390, 201); + this.ball.Location = new System.Drawing.Point(393, 229); this.ball.Name = "ball"; this.ball.Size = new System.Drawing.Size(18, 18); this.ball.TabIndex = 2; @@ -70,31 +50,36 @@ this.gameTimer.Interval = 20; this.gameTimer.Tick += new System.EventHandler(this.gameTimer_Tick); // + // playerPaddle + // + this.playerPaddle.BackColor = System.Drawing.Color.White; + this.playerPaddle.Location = new System.Drawing.Point(337, 421); + this.playerPaddle.Name = "playerPaddle"; + this.playerPaddle.Size = new System.Drawing.Size(142, 15); + this.playerPaddle.TabIndex = 3; + this.playerPaddle.TabStop = false; + // // Pong // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.Black; - this.Controls.Add(this.ball); - this.Controls.Add(this.cpuPaddle); this.Controls.Add(this.playerPaddle); + this.Controls.Add(this.ball); this.ForeColor = System.Drawing.Color.White; this.Name = "Pong"; - this.Size = new System.Drawing.Size(801, 470); + this.Size = new System.Drawing.Size(664, 470); this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Pong_KeyDown); this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Pong_KeyUp); - ((System.ComponentModel.ISupportInitialize)(this.playerPaddle)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.cpuPaddle)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.ball)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.playerPaddle)).EndInit(); this.ResumeLayout(false); } #endregion - - private System.Windows.Forms.PictureBox playerPaddle; - private System.Windows.Forms.PictureBox cpuPaddle; private System.Windows.Forms.PictureBox ball; private System.Windows.Forms.Timer gameTimer; + private System.Windows.Forms.PictureBox playerPaddle; } } diff --git a/ShiftOS.Main/Apps/Breakout.cs b/ShiftOS.Main/Apps/Breakout.cs new file mode 100644 index 0000000..db10962 --- /dev/null +++ b/ShiftOS.Main/Apps/Breakout.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ShiftOS.Engine.WindowManager; + +namespace ShiftOS.Main.Apps +{ + public partial class Breakout : UserControl + { + bool goLeft = false; + bool goRight = false; + int speed = 5; + float ballX = 5; + float ballY = 5; + int rows = 5; + int col = 8; + public PictureBox[,] blocks; + public Breakout() + { + InitializeComponent(); + DrawBlocks(); + gameTimer.Start(); + ResetToRest(); + } + void ResetToRest() + { + ball.Location = new Point((int)Math.Round(this.Width / 2d, 0), (int)Math.Round(this.Height / 2d, 0)); + playerPaddle.Location = new Point((int)Math.Round(ClientSize.Width / 2d, 0), playerPaddle.Location.Y); + } + + private void Pong_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.A && playerPaddle.Left > 0) goLeft = true; + if (e.KeyCode == Keys.D && playerPaddle.Left + playerPaddle.Width < this.Width) goRight = true; + } + + private void Pong_KeyUp(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.A) goLeft = false; + if (e.KeyCode == Keys.D) goRight = false; + } + + private void gameTimer_Tick(object sender, EventArgs e) + { + ball.Top += (int)ballY; + ball.Left += (int)ballX; + + if (ball.Bottom > ClientSize.Height || ball.Top < 0) ballY = -ballY; + if (ball.Right > ClientSize.Width || ball.Left < 0) ballX = -ballX; + if (ball.Bounds.IntersectsWith(playerPaddle.Bounds)) ballY = -ballY; + if (goRight) playerPaddle.Left += 8; + if (goLeft) playerPaddle.Left -= 8; + if (playerPaddle.Left < 1) goLeft = false; + if (playerPaddle.Left + playerPaddle.Width > this.Width) goRight = false; + + for (int j = 0; j < rows; j++) + { + for (int i = 0; i < col; i++) + { + if (ball.Bounds.IntersectsWith(blocks[j,i].Bounds) && blocks[j,i].Visible) + { + ballY = -ballY; + blocks[j,i].Visible = false; + } + } + } + if (ball.Top + ball.Height > ClientSize.Height) + { + gameTimer.Stop(); + var infoBox = ShiftWM.StartInfoboxSession("Breakout - You Lose! ", "It appears that you have lost the game, meaning\nall codepoints won were lost. Would you\nlike to try again?", InfoboxTemplate.ButtonType.YesNo); + ShiftWM.StartInfoboxSession(null, infoBox.isOK.ToString(), InfoboxTemplate.ButtonType.Ok); + if (infoBox.isOK) + { + DrawBlocks(); + ResetToRest(); + gameTimer.Start(); + } + } + } + private void DrawBlocks() + { + int h = 20; + int w = 75; + blocks = new PictureBox[rows, col]; + for (int j = 0; j < rows; j++) + { + for (int i = 0; i < col; i++) + { + blocks[j, i] = new PictureBox(); + blocks[j, i].Height = h; + blocks[j, i].Width = w; + blocks[j, i].Top = h * j; + blocks[j, i].Left = w * i; + blocks[j, i].Paint += (o, a) => + { + Rectangle rect = new Rectangle(blocks[j,i].Location.X, blocks[j,i].Location.Y, blocks[j,i].ClientSize.Width, blocks[j,i].ClientSize.Height); + + rect.Inflate(1,1); // border thickness + ControlPaint.DrawBorder(a.Graphics, rect, Color.Black, ButtonBorderStyle.Solid); + }; + this.Controls.Add(blocks[j, i]); + } + } + } + } +} diff --git a/ShiftOS.Main/Apps/Pong.resx b/ShiftOS.Main/Apps/Breakout.resx index a0e8b0d..a0e8b0d 100644 --- a/ShiftOS.Main/Apps/Pong.resx +++ b/ShiftOS.Main/Apps/Breakout.resx diff --git a/ShiftOS.Main/Apps/Pong.cs b/ShiftOS.Main/Apps/Pong.cs deleted file mode 100644 index cde3c31..0000000 --- a/ShiftOS.Main/Apps/Pong.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Drawing; -using System.Data; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace ShiftOS.Main.Apps -{ - public partial class Pong : UserControl - { - bool goUp = false; - bool goDown = false; - int speed = 5; - float ballX = 5; - float ballY = 5; - public Pong() - { - InitializeComponent(); - gameTimer.Start(); - ResetToRest(); - } - void ResetToRest() - { - ball.Location = new Point((int)Math.Round(this.Width / 2d, 0), (int)Math.Round(this.Height / 2d, 0)); - playerPaddle.Location = new Point(playerPaddle.Location.X, (int)Math.Round(this.Height / 2d, 0)); - cpuPaddle.Location = new Point(cpuPaddle.Location.X, (int)Math.Round(this.Height / 2d, 0)); - } - - private void Pong_KeyDown(object sender, KeyEventArgs e) - { - if (e.KeyCode == Keys.W) goUp = true; - if (e.KeyCode == Keys.S) goDown = true; - } - - private void Pong_KeyUp(object sender, KeyEventArgs e) - { - if (e.KeyCode == Keys.W) goUp = false; - if (e.KeyCode == Keys.S) goDown = false; - } - - private void gameTimer_Tick(object sender, EventArgs e) - { - ball.Top -= (int)ballY; - ball.Left -= (int)ballX; - - - - //CPU - if (ballX < 0) - { - if (ball.Top < cpuPaddle.Top + 51) - { - cpuPaddle.Top -= 5; - } - if(ball.Top > cpuPaddle.Top + 51) - { - cpuPaddle.Top += 5; - } - } - - if (ball.Left < 0) - { - ResetToRest(); - ballX = -ballX; - } - if (ball.Left + ball.Width > this.Width) - { - ResetToRest(); - ballX = -ballX; - } - if (ball.Top < 0 || ball.Top + ball.Height > this.Height) ballY = -ballY; - if (ball.Bounds.IntersectsWith(playerPaddle.Bounds) || ball.Bounds.IntersectsWith(cpuPaddle.Bounds)) ballX = -ballX; - - if (goUp && playerPaddle.Top > 0) playerPaddle.Top -= 8; - if (goDown && playerPaddle.Top < this.Height) playerPaddle.Top += 8; - - } - } -} |
