Here s the problem:
I ve been working on a little game where monsters bounce off the walls (edges) of the main form, and it s going swimmingly, but it only paints one of each type of monster when it should be iterating through a list of each of them and calling their OnPaint and Move methods:
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
}
Here s the ghost s methods:
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);
}
Any ideas why only one would show up? Thanks!