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 animation { public partial class Form1 : Form { // gravity is global to everyone public const double ACCEL_GRAVITY = 0.02; // frame time should match the timer interval public const int FRAME_TIME = 10; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // enable the timer to start ticking timer1.Interval = FRAME_TIME; timer1.Enabled = true; } private void timer1_Tick(object sender, EventArgs e) { // this is where the action is - every tick, update all sprites sprite1.UpdateBehavior(this); } private void Form1_KeyDown(object sender, KeyEventArgs e) { // pass key up/down to the player sprite so it knows what keys are being held down if (e.KeyCode == Keys.A) { sprite1.CmdLeft = true; } else if (e.KeyCode == Keys.D) { sprite1.CmdRight = true; } else if (e.KeyCode == Keys.Space) { sprite1.CmdJump = true; } } private void Form1_KeyUp(object sender, KeyEventArgs e) { // pass key up/down to the player sprite so it knows what keys are being held down if (e.KeyCode == Keys.A) { sprite1.CmdLeft = false; } else if (e.KeyCode == Keys.D) { sprite1.CmdRight = false; } else if (e.KeyCode == Keys.Space) { sprite1.CmdJump = false; } } } }