aboutsummaryrefslogtreecommitdiff
path: root/source/WindowsFormsApplication1/Jumper.cs
diff options
context:
space:
mode:
authorMichael VanOverbeek <[email protected]>2016-04-09 13:16:39 -0400
committerMichael VanOverbeek <[email protected]>2016-04-09 13:16:39 -0400
commit14edb9eade65806b531e51a0ed1fba7c62ba848e (patch)
treeb8a0124d66ca9d414870a27de103e7be9a748081 /source/WindowsFormsApplication1/Jumper.cs
parentcfb8690c6fbbb0595f8a3a4cd9f3210054a9680d (diff)
downloadshiftos-c--14edb9eade65806b531e51a0ed1fba7c62ba848e.tar.gz
shiftos-c--14edb9eade65806b531e51a0ed1fba7c62ba848e.tar.bz2
shiftos-c--14edb9eade65806b531e51a0ed1fba7c62ba848e.zip
Uploaded source code for ShiftOS 0.1.1 Beta 2.3
Initial commit of repository.
Diffstat (limited to 'source/WindowsFormsApplication1/Jumper.cs')
-rw-r--r--source/WindowsFormsApplication1/Jumper.cs146
1 files changed, 146 insertions, 0 deletions
diff --git a/source/WindowsFormsApplication1/Jumper.cs b/source/WindowsFormsApplication1/Jumper.cs
new file mode 100644
index 0000000..766c929
--- /dev/null
+++ b/source/WindowsFormsApplication1/Jumper.cs
@@ -0,0 +1,146 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace ShiftOS
+{
+ public partial class Jumper : Form
+ {
+ public Jumper()
+ {
+ InitializeComponent();
+ }
+
+ enum GameStatus
+ {
+ Idle,
+ GameOver,
+ Playing
+ }
+
+ private GameStatus status = GameStatus.Idle;
+ private int JumpingStage = 0; //not jumping
+
+ int gamespeed = 1;
+ int codepointsearned = 0;
+
+ Random rand = new Random();
+
+ private void tmrscreenupdate_Tick(object sender, EventArgs e)
+ {
+ ground.Location = new Point(0, 260);
+ ground.Size = new Size(this.ClientRectangle.Width, 2);
+ ground.BackColor = Color.Black;
+ switch(JumpingStage)
+ {
+ case 0:
+ player.Location = new Point(100, 228);
+ break;
+ case 1:
+ if(player.Location.Y != 200)
+ {
+ player.Location = new Point(player.Location.X, player.Location.Y - 5);
+ } else
+ {
+ JumpingStage = 2;
+ }
+ break;
+ case 2:
+ if (player.Location.Y != 228)
+ {
+ player.Location = new Point(player.Location.X, player.Location.Y + 5);
+ }
+ else
+ {
+ JumpingStage = 0;
+ lbstatus.Text = "Landed";
+ }
+ break;
+
+ }
+ int randres = rand.Next(0, 9);
+ switch(randres)
+ {
+ case 5:
+ Panel enemy = new Panel();
+ this.Controls.Add(enemy);
+ enemy.Location = new Point(this.ClientRectangle.Width, 227);
+ enemy.BackColor = Color.Black;
+ enemy.Size = new Size(32, 27);
+ enemy.Tag = "enemy";
+ enemy.Show();
+ break;
+ }
+
+ foreach (Control ctrl in this.Controls)
+ {
+ string enemytag = "enemy";
+ if (enemytag == (string)ctrl.Tag)
+ {
+ if (ctrl.Location.X < 0 - ctrl.Width)
+ {
+ ctrl.Hide();
+ }
+ else
+ {
+ ctrl.Location = new Point(ctrl.Location.X - (2 * gamespeed), ctrl.Location.Y);
+ }
+ if (ctrl.Left >= player.Left && ctrl.Left <= player.Right)
+ {
+ if(ctrl.Top >= player.Top && ctrl.Bottom <= player.Bottom)
+ {
+ status = GameStatus.GameOver;
+ }
+ }
+ }
+ }
+
+ switch(status)
+ {
+ case GameStatus.Playing:
+ codepointsearned += gamespeed;
+ btnplay.Hide();
+ lbstatus.Text = "Codepoints: " + codepointsearned.ToString();
+ break;
+ case GameStatus.GameOver:
+ tmrscreenupdate.Stop();
+ API.CreateInfoboxSession("You hit an obstacle.", "You have run into an obstacle. You have earned " + codepointsearned.ToString() + " Codepoints.", infobox.InfoboxMode.Info);
+ API.AddCodepoints(codepointsearned);
+ codepointsearned = 0;
+ if(API.Upgrades["multitasking"] == true)
+ {
+ this.Close(); //Close if multitasking is true.
+ }
+ break;
+ }
+ }
+
+ private void btnplay_Click(object sender, EventArgs e)
+ {
+ if(this.status == GameStatus.Idle)
+ {
+ this.status = GameStatus.Playing;
+ this.Focus();
+ this.KeyDown += (object s, KeyEventArgs a) =>
+ {
+ if (a.KeyCode == Keys.Space)
+ {
+ if (JumpingStage == 0)
+ {
+ JumpingStage = 1;
+ lbstatus2.Text = "Jumping...";
+ }
+ a.SuppressKeyPress = true;
+ }
+ };
+ tmrscreenupdate.Start();
+ }
+ }
+ }
+}