public void MoveTo(Spirits Other) { PictureBox.BringToFront(); int xSpeed = (Other.X - this.X) / 50; int ySpeed = (Other.Y - this.Y) / 50; while (!Tool.IsCrash(this, Other)) { PictureBox.Left = X + xSpeed; PictureBox.Top = Y + ySpeed; X += xSpeed; Y += ySpeed; Thread.Sleep(10); } while (Math.Abs(X - OriginalX) >= 10) { PictureBox.Left = X - xSpeed; PictureBox.Top = Y - ySpeed; X -= xSpeed; Y -= ySpeed; Thread.Sleep(10); } X = OriginalX; Y = OriginalY; PictureBox.Left = OriginalX; PictureBox.Top = OriginalY; }
public static bool IsCrash(Spirits a, Spirits b) { if (Math.Abs((b.X + b.Width / 2) - (a.X + a.Width / 2)) < Math.Abs((a.Width + b.Width) / 2)) { if (Math.Abs((b.Y + b.Height / 2) - (a.Y + a.Height) / 2) < Math.Abs((a.Height + b.Height) / 2)) { return(true); } return(false); } return(false); }
/* public void Shoot(Spirits Other) * { *//* Graphics g = new Graphics();*//* * }*/ public void Attack(Spirits Other) { /* if (AttackKind == 1) * { * MoveTo(Other); * } * else if (AttackKind == 2) * { * Shoot(Other); * }*/ MoveTo(Other); int random = new Random().Next(140, 160); Other.HP -= random; Other.HPLabel.Width -= (int)(random * 1.0 / 1000 * 256); Other.HPLabel.Left += (int)(random * 1.0 / 1000 * 256); }