Answer the question
In order to leave comments, you need to log in
How to fix - I'm trying to move the bitmap across the field?
Hello. In general, I load the map / level:
private void Form1_Paint(object sender, PaintEventArgs e)
{
var lines = File.ReadAllLines(@"C:\Users\MAKSIM\source\repos\LoadLevel\WindowsFormsApp5\Level\level1.txt");
width = lines[0].Length;
height = lines.Length;
for (int j = 0; j < height; j++)
{
for (int i = 0; i < width; i++)
{
switch (lines[j][i])
{
case 'x':
g.DrawImage(image1, i * 32, j * 32, 32, 32);
coordBoll[i, j] = 1;
break;
case 'b':
g.DrawImage(image2, i * 32, j * 32, 32, 32);
coordBoll[i, j] = 2;
break;
case ' ':
g.DrawImage(image3, i * 32, j * 32, 32, 32);
coordBoll[i, j] = 0;
break;
case 'p':
g.DrawImage(image4, i * 32, j * 32, 32, 32);
coordBoll[i, j] = 3;
break;
case 's':
g.DrawImage(image5, i * 32, j * 32, 32, 32); posSX = i; posSY = j;
coordBoll[i, j] = 4;
break;
}
}
}
}
case Keys.Left:
image5 = new Bitmap(@"C:\Users\MAKSIM\source\repos\LoadLevel\WindowsFormsApp5\Image\left.png");
g.DrawImage(image3, posSX * 32, posSY * 32);
g.DrawImage(image5, posSX * 32 - 32, posSY * 32);
posSX -= 1;
if (coordBoll[posSX, posSY] == 2)
{
for (int j = 0; j < height; j++)
{
for (int i = 0; i < width; i++)
{
g.DrawImage(image2, posSX * 32 - 32, posSY * 32);
}
}
}
g.DrawImage(image2, posSX * 32 - 32, posSY * 32);
break;
Answer the question
In order to leave comments, you need to log in
case Keys.Left:
image5 = new Bitmap(@"C:\Users\MAKSIM\source\repos\LoadLevel\WindowsFormsApp5\Image\left.png");
g.DrawImage(image3, posSX * 32, posSY * 32);
g.DrawImage(image5, posSX * 32 - 32, posSY * 32);
posSX -= 1;
if (coordBoll[posSX, posSY] == 2)
{
for (int j = 0; j < height; j++)
{
for (int i = 0; i < width; i++)
{
g.DrawImage(image2, posSX * 32 - 32, posSY * 32);
}
}
}
g.DrawImage(image2, posSX * 32 - 32, posSY * 32); // а зачем в условии эта последняя строчка с прорисованием image2 вновь....
break;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question