Помогите ограничить движение ракеты в Visual Studio 2017 Paint.
Я нарисовал ракету и сделал чтобы они летала по кругу, но она вылетает за пределы экрана! Мне надо чтобы ракета летала по кругу и не вылетала за пределы экрана! Как это сделать?
Вот код:
namespace WindowsFormsApplication27
{
public partial class Form1 : Form
{
int x = 1000;
int y = 500;
int angle = 1;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void raketa(Graphics g, Pen myPen, int x, int y)
{
int x1 = x;
int y1 = y;
Graphics g1 = CreateGraphics();
Pen myPen1 = new Pen(Color.Red);
g.DrawLine(myPen, x1 - 15, y1 + 60, x1 - 15, y1);
g.DrawLine(myPen, x1 + 15, y1 + 60, x1 + 15, y1);
g.DrawLine(myPen, x1 - 15, y1, x1, y1 - 30);
g.DrawLine(myPen, x1 + 15, y1, x1, y1 - 30);
g.DrawLine(myPen, x1 - 15, y1 + 60, x1 + 15, y1 + 60);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
Graphics g = CreateGraphics();
Pen myPen = new Pen(Color.Red);
g.RotateTransform(angle);
raketa(g, myPen, x, y);
y = y -1;
angle--;
Thread.Sleep(60);
g.Clear(Color. White);
}
}
}
g.RotateTransform вращает всю картинку. центр вращения левый верхний угол формы
попробуйте так
int x = 100;
int y = 100;
double angle = 0;
Graphics g;
Pen myPen = new Pen(Color.Red);
public Form1()
{
InitializeComponent();
g = CreateGraphics();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 100;
timer1.Start();
}
private void raketa(Graphics g, Pen myPen, int x, int y)
{
int x1 = x;
int y1 = y;
Graphics g1 = CreateGraphics();
Pen myPen1 = new Pen(Color.Red);
g.DrawLine(myPen, x1 - 15, y1 + 60, x1 - 15, y1);
g.DrawLine(myPen, x1 + 15, y1 + 60, x1 + 15, y1);
g.DrawLine(myPen, x1 - 15, y1, x1, y1 - 30);
g.DrawLine(myPen, x1 + 15, y1, x1, y1 - 30);
g.DrawLine(myPen, x1 - 15, y1 + 60, x1 + 15, y1 + 60);
}
private void timer1_Tick(object sender, EventArgs e)
{
angle -= 0.1;
g.Clear(Color.FromKnownColor(KnownColor.Control));
raketa(g, myPen, 30 + x + Convert.ToInt32(x * Math.Cos(angle)), 30 + y + Convert.ToInt32(y * Math.Sin(angle)));
}
к тя ракета крутится вокруг собственной оси?!