using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Jumping { public partial class Form1 : Form { bool jumping = false; bool falling = false; int startingElevation = 0; public Form1() { InitializeComponent(); Timer Clock; Clock = new Timer(); Clock.Interval = 1; Clock.Start(); Clock.Tick += new EventHandler(Timer_Tick); InitializeComponent(); } public void Timer_Tick(object sender, EventArgs eArgs) { int currentElevation = PBObject.Top + PBObject.Height; if (jumping == true) { if ((currentElevation > (startingElevation - 20)) && (currentElevation <= (startingElevation))) { PBObject.Top -= 5; } else if ((currentElevation > (startingElevation - 40)) && (currentElevation <= (startingElevation - 20))) { PBObject.Top -= 4; } else if ((currentElevation > (startingElevation - 60)) && (currentElevation <= (startingElevation - 40))) { PBObject.Top -= 3; } else if ((currentElevation > (startingElevation - 80)) && (currentElevation <= (startingElevation - 60))) { PBObject.Top -= 2; } else if ((currentElevation > (startingElevation - 100)) && (currentElevation <= (startingElevation - 80))) { PBObject.Top -= 1; } else if (currentElevation <= (startingElevation - 100)) { jumping = false; falling = true; } } else if (falling == true) { if ((currentElevation >= (startingElevation - 100)) && (currentElevation < (startingElevation - 80))) { PBObject.Top += 1; } else if ((currentElevation >= (startingElevation - 80)) && (currentElevation < (startingElevation - 60))) { PBObject.Top += 2; } else if ((currentElevation >= (startingElevation - 60)) && (currentElevation < (startingElevation - 40))) { PBObject.Top += 3; } else if ((currentElevation >= (startingElevation - 40)) && (currentElevation < (startingElevation - 20))) { PBObject.Top += 4; } else if ((currentElevation >= (startingElevation - 20)) && (currentElevation < (startingElevation))) { PBObject.Top += 5; } else if (currentElevation >= startingElevation) { falling = false; PBObject.Top = startingElevation - PBObject.Height; } } } private void button1_Click(object sender, EventArgs e) { if ((jumping == false) && (falling == false)) { startingElevation = PBObject.Top + PBObject.Height; jumping = true; } } } }
InitializeComponent();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)