所以我试图在c#中制作一个pacman克隆,Visual studio express 2013.我有迷宫,并且我把标签放在边缘。我对pacman的未来坐标有一点看法。如果该点与标签不相交,则pacmans位置将采用该点的位置。当pacman从右或向下来时,这种方法很好,但如果他来自右边或顶部,它就不起作用。对于鬼魂来说也是如此,鬼魂的运动是随机产生的。他们似乎都认为标签更大。我试图在互联网上搜索为什么会这样,但我似乎无法找到答案。我用碰撞检查和pacman运动放下了这个部分。提前致谢
private void timer_Tick(object sender, EventArgs e)
{
//colision check
PictureBox intermed = new PictureBox
{
Location = new Point(pictureBox1.Location.X + pacdirx, pictureBox1.Location.Y + pacdiry),
};
if (!intermed.Bounds.IntersectsWith(label1.Bounds) )
pictureBox1.Location = new Point(pictureBox1.Location.X + pacdirx, pictureBox1.Location.Y + pacdiry);
private void Form3_KeyDown(object sender, KeyEventArgs e)
{
//pacman movement
if (e.KeyCode == Keys.W)
{
pacdiry = -3;
pacdirx = 0;
pictureBox1.Image = Image.FromFile("eat_up.gif");
}
if (e.KeyCode == Keys.S)
{
pacdiry = 3;
pacdirx = 0;
pictureBox1.Image = Image.FromFile("eat_down.gif");
}
if (e.KeyCode == Keys.D)
{
pacdiry = 0;
pacdirx = 3;
pictureBox1.Image = Image.FromFile("eat_right.gif");
}
if (e.KeyCode == Keys.A)
{
pacdiry = 0;
pacdirx = -3;
pictureBox1.Image = Image.FromFile("eat_left.gif");
}
}