Вот проблема:
Я работал над маленькой игрой, в которой монстры отскакивают от стен (краев) основной формы, и все идет гладко, но он рисует только одного из каждого типа монстров, когда он должен перебирать список каждый из них и вызывающий их методы OnPaint и Move:
private void Pacmen_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle rect = e.ClipRectangle;
g.Clear(backgroundColor);
foreach (Hydra h in hydraList) {
h.OnPaint(e);
h.Move(e);
} // end foreach
foreach (Ghost gh in ghostList) {
gh.OnPaint(e);
gh.Move(e);
} // end foreach
}
Вот методы призрака:
public void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.HighQuality;
GraphicsPath path = new GraphicsPath();
SolidBrush fillBrush = new SolidBrush(color);
SolidBrush eyeBrush = new SolidBrush(Color.Black);
path.AddArc(pos, (float)180, (float)180);
path.AddLine((float)pos.Right, (float)(pos.Y + pos.Height / 2),
(float)pos.Right, (float)pos.Bottom);
path.AddLine((float)pos.Right, (float)pos.Bottom,
(float)(pos.X + pos.Width / 2), (float)(pos.Bottom - radius / 2));
path.AddLine((float)(pos.X + pos.Width / 2), (float)(pos.Bottom - radius / 2),
(float)pos.Left, (float)pos.Bottom);
path.AddLine((float)pos.Left, (float)pos.Bottom,
(float)pos.Left, (float)(pos.Y + pos.Height / 2));
g.FillPath(fillBrush, path);
g.FillEllipse(eyeBrush, new Rectangle(pos.X + pos.Width / 4, pos.Y + pos.Height / 4, radius / 4, radius / 5));
g.FillEllipse(eyeBrush, new Rectangle(pos.X + 3 * pos.Width / 4, pos.Y + pos.Height / 4, radius / 4, radius / 5));
} // end OnPaint
public void Move(PaintEventArgs e)
{
pos.Offset(xSpeed, ySpeed);
}
Есть идеи, почему появился только один? Спасибо!