我试着在长方形上做一个启示录。我用计时器在x和y方向移动启示录。我的想法是创建一个if语句,以查看“启示”的坐标是否与矩形的坐标相匹配。
以下是我到目前为止编写的代码:
public partial class Form1 : Form
{
Class1 square = new Class1();
public int before;
public int after;
public int c;
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
after = 590 - (b * b) / 100;
before = 100 + (a * a) / 100;
c = a + b;
Graphics g = e.Graphics;
SolidBrush Brush = new SolidBrush(Color.White);
g.FillEllipse(Brush, a, before, 10, 10);
square.Draw(g);
if (k >= square.y && a >= square.x && a <= square.x + 40)
{
a=c;
before= after;
timer1.Start();
timer2.Stop();
}
else if (k >= square.y + 10)
{
timer2.Stop();
MessageBox.Show("You lost");
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
square.x = e.X;
Cursor.Hide();
}
public int a = 0;
public int b = 0;
public void timer2_Tick(object sender, EventArgs e)
{
a += 1;
Invalidate();
}
private void timer1_Tick(object sender, EventArgs e)
{
b += 1;
Invalidate();
}
}我知道有些问题。我有一些问题:
我知道这个问题可能有些模糊或抽象,但任何帮助都是见仁见智的。如果你想让我在某些方面更清楚,请告诉我!谢谢
发布于 2013-06-03 15:03:00
一个简单的方法,使椭圆反弹的边缘是检查它的边缘点与边界,然后只是反转正确的方向。所以,如果你能原谅伪代码的话,这样的东西应该可以用。
loop used to animate the ellipse
before moving, check the position:
if right-most position == right wall
invert x velocity
if left-most position == left wall
invert x velocity
if top-most position == top wall
invert y velocity
if bottom-most position == bottom wall
invert y velocity
move ellipse to next position这是一个相当简单的模拟,但它应该给你一个如何进步和发展一个更复杂的模型的想法。希望这能有所帮助!
https://stackoverflow.com/questions/16899710
复制相似问题