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 Sprite : PictureBox { private static int SPEED = 3; private int limit; private bool goingRight; public Sprite() { InitializeComponent(); } public void Start(string filename) { SizeMode = PictureBoxSizeMode.Zoom; Image = Image.FromFile(filename); Size = new Size(128, 128); limit = 0; goingRight = true; } public void UpdateBehavior() { if (goingRight) { Location = new Point(Location.X+SPEED, Location.Y); limit += SPEED; if (limit >= 200) { goingRight = false; } } else { Location = new Point(Location.X-SPEED, Location.Y); limit -= SPEED; if (limit <= 0) { goingRight = true; } } } } }