I am doing this for a school assignment, but I got stuck at the end of the code. For one, I am unable to get the 'man' animation to be redrawn onto the panel. Though, in the picture box it will animate using the array. Secondly, using the key down, the man will not move at all. It works on my first version with the exact same code copy and pasted. I am unsure if there is another, or better way to do it, or if I somehow messed up. The code for the entire program is first, the second is for the key down, the third is for where I think I need to change the redrawing for it to be animated.
public partial class Form1 : Form
for (int i = 1; i <= 7; i++)
{
images[i] = Image.FromFile(Application.StartupPath + @"\Man" + i.ToString() + ".png");
}
PicMan.Image = images[1];
this.Focus();
private void BtnStart_Click(object sender, EventArgs e)
{
TimeMan.Enabled = !TimeMan.Enabled;
if (BtnStart.Text == "Start")
{
myGraphics.Clear(PnlGameContent.BackColor);
BtnStart.Text = "Stop";
BtnExit.Enabled = false;
TxtScore.Text = "0";
for (int i = 0; i < 5; i++)
{
coinY[i] = -coinSize;
coinSpeed[i] = myRandom.Next(4) + 3;
}
manX = (int)(PnlGameContent.Width / 2);
myGraphics.DrawImage(PicMan.Image, manX, PnlGameContent.Height - manSize, manSize, manSize);
this.Focus();
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
myGraphics.FillRectangle(blankBrush, manX, PnlGameContent.Height - manSize, manSize, manSize);
if (e.KeyCode == Keys.F)
{
manX = manX - 5;
}
else if (e.KeyCode == Keys.J)
{
manX = manX + 5;
}
myGraphics.DrawImage(PicMan.Image, manX, PnlGameContent.Height - manSize, manSize, manSize);
}
private void startToolStripMenuItem1_Click(object sender, EventArgs e)
{
private void TimeMan_Tick(object sender, EventArgs e)
{
PicMan.Image = images[count];
count++;
if (count > 7)
count = 0;
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
myGraphics.FillRectangle(blankBrush, manX, PnlGameContent.Height - manSize, manSize, manSize);
if (e.KeyCode == Keys.F)
{
manX = manX - 5;
}
else if (e.KeyCode == Keys.J)
{
manX = manX + 5;
}
myGraphics.DrawImage(PicMan.Image, manX, PnlGameContent.Height - manSize, manSize, manSize);
}
manX = (int)(PnlGameContent.Width / 2);
myGraphics.DrawImage(PicMan.Image, manX, PnlGameContent.Height - manSize, manSize, manSize);
Any help is greatly appreciated, whether is be fixed coding, links, or small suggestions. Thanks in advance.
Sorry for the long code and question, but I am unsure of where I went wrong.