当前位置:网站首页>C # game prototype character map dual movement

C # game prototype character map dual movement

2022-06-10 15:46:00 Forgetful squirrel

1. Design starting point

Prepare to make a short travel video , Want to achieve the effect of a villain or car moving on Baidu map according to the specified route , Take out the code you wrote before , Modified to complete .

Main modifications :

(1) Realized the double movement of character map . That is, if the character moves to the middle of the screen , Mobile character ; People move around the screen , If you can move the map, move the map , Otherwise move the character .

(2) The original one-way moving animation of the character is replaced by four-way moving animation

(3) Fixed the problem of character ghosting after pressing the key

(4) Several variables with ambiguous meanings have been modified

Unresolved bug: When you press the key to control the person to move, it will flash

2. Main update code

(1) Timer code

private void T200_Tick(object sender, EventArgs e)
        {
            t200.Stop();
            Bitmap person1 = new Bitmap(person16.Width/4, person16.Height/4);
            winPoint point = new winPoint(0, 0);
            cnt++;
            if (cnt > 3) cnt = 0;
            point.X = -1*cnt * person1.Width;// Action of different characters x The coordinates are different 
            point.Y = -1 * direct * person1.Height;
            using (Graphics g = Graphics.FromImage(person1))
            {
                g.DrawImage(person16, point);// Complete character switching and action superposition 
            }
            using (Graphics g0 = Graphics.FromImage(pictureBox1.Image))
            {
                //g0.DrawImage()
                g0.DrawImage(allBitmap, mapPoint);// Not good. , But I don't know how to solve it 
                g0.DrawImage(person1, personPt.X,personPt.Y);// Draw the overlay of people and background on the map 
            }
            pictureBox1.Refresh();
            t200.Start();
        }

(2) Character movement and map relative movement code

case 'D':
                    direct = 2;
                    if (personPt.X > (pictureBox1.Size.Width - person16.Width / 4)/2)// Across the middle of the screen 
                    {// If the map can be moved , Then move the map 
                        mapPoint.X -= 10;
                        if (mapPoint.X + allBitmap.Size.Width < currBitmap.Size.Width)// The map is on the edge 
                        {
                            mapPoint.X += 10;
                            personPt.X += 10;
                            if (personPt.X > pictureBox1.Size.Width - person16.Width / 4)
                                personPt.X = pictureBox1.Size.Width - person16.Width / 4;
                        }
                    }
                    else
                    {
                        personPt.X += 10;// It's not in the center of the screen yet , Mobile people 
                        if (personPt.X > pictureBox1.Size.Width - person16.Width / 4)
                            personPt.X = pictureBox1.Size.Width - person16.Width / 4;
                    }
                    break;

原网站

版权声明
本文为[Forgetful squirrel]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101456114087.html