aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Main/Apps/Pong.cs
diff options
context:
space:
mode:
authorRichie Moch <[email protected]>2018-12-23 19:15:07 -0600
committerRichie Moch <[email protected]>2018-12-23 19:15:07 -0600
commitbca879db94bc6395dbfa77628747080311fdb226 (patch)
tree24103811cd3df0957f2450bbe579e05d7dc7c4e6 /ShiftOS.Main/Apps/Pong.cs
parentd94c79dbf5183230e5fd3342848408f776de60ea (diff)
downloadshiftos-rewind-bca879db94bc6395dbfa77628747080311fdb226.tar.gz
shiftos-rewind-bca879db94bc6395dbfa77628747080311fdb226.tar.bz2
shiftos-rewind-bca879db94bc6395dbfa77628747080311fdb226.zip
started work on the pong, implemented "ShiftToolStrip". (note: pong is very buggy)
Diffstat (limited to 'ShiftOS.Main/Apps/Pong.cs')
-rw-r--r--ShiftOS.Main/Apps/Pong.cs72
1 files changed, 72 insertions, 0 deletions
diff --git a/ShiftOS.Main/Apps/Pong.cs b/ShiftOS.Main/Apps/Pong.cs
new file mode 100644
index 0000000..aa0c792
--- /dev/null
+++ b/ShiftOS.Main/Apps/Pong.cs
@@ -0,0 +1,72 @@
+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;
+
+ cpuPaddle.Top += speed;
+
+ if (cpuPaddle.Top < 0 || cpuPaddle.Top > this.Height) speed = -speed;
+
+ if (ball.Left < 0)
+ {
+ ResetToRest();
+ ballX = -ballX;
+ }
+ if (ball.Left + ball.Width > this.Height)
+ {
+ 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;
+
+ }
+ }
+}