I am trying to create a simple game using C # to learn the language better.
The game should be simple: the player controls the vessel around and can shoot at some material that also moves.
So far I have this:
public partial class Form1 : Form
{
Rectangle r1 = new Rectangle(new Point(100, 100), new Size(100, 150));
Matrix rotateMatrix = new Matrix();
GraphicsPath gp = new GraphicsPath();
public Form1()
{
InitializeComponent();
gp.AddRectangle(r1);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.HighQuality;
g.DrawRectangle(new Pen(Color.Beige), r1);
this.lblPoint.Text = "X-pos: " + r1.X + " Y-pos: " + r1.Y;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.D:
r1.X += 10;
break;
case Keys.A:
r1.X -= 10;
break;
case Keys.W:
r1.Y -= 10;
break;
case Keys.S:
r1.Y += 10;
break;
case Keys.T:
rotateMatrix.RotateAt(45, new Point(50, 50));
gp.Transform(rotateMatrix);
break;
default:
break;
}
Invalidate();
Update();
}
}
So far I can move the rectangle (vessel) around the fine, but when it comes to turning the rectangle with a key, it’s not so much, and I can’t understand what happened. I want to be able to rotate the vessel both clockwise and counterclockwise.
What am I doing wrong or not doing at all?
Miked source
share