OK. So I'm making a simple game that is a car that moves around the screen according to the arrow keys. i have made code to rotate the car inside the picturebox, but i don't know how to make the car move in the direction that it is facing after the turn. please help. my code so far.....
Imports System.Math
Public Class Form2
Private Sub tmrRotate_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrRotate.Tick
Dim bm_in As New Bitmap(picCar.Image)
Dim wid As Single = bm_in.Width
Dim hgt As Single = bm_in.Height
Dim corners As Point() = { _
New Point(0, 0), _
New Point(wid, 0), _
New Point(0, hgt), _
New Point(wid, hgt)}
Dim cx As Single = wid / 2
Dim cy As Single = hgt / 2
Dim i As Long
For i = 0 To 3
corners(i).X -= cx
corners(i).Y -= cy
Next i
Dim theta As Single = Single.Parse(lblAngle.Text) * PI / 180.0
Dim sin_theta As Single = Sin(theta)
Dim cos_theta As Single = Cos(theta)
Dim X As Single
Dim Y As Single
For i = 0 To 3
X = corners(i).X
Y = corners(i).Y
corners(i).X = X * cos_theta + Y * sin_theta
corners(i).Y = -X * sin_theta + Y * cos_theta
Next i
Dim xmin As Single = corners(0).X
Dim ymin As Single = corners(0).Y
For i = 1 To 3
If xmin > corners(i).X Then xmin = corners(i).X
If ymin > corners(i).Y Then xmin = corners(i).Y
Next i
For i = 0 To 3
corners(i).X -= xmin
corners(i).Y -= ymin
Next i
Dim bm_out As New Bitmap(CInt(-2 * xmin), CInt(-2 * ymin))
Dim gr_out As Graphics = Graphics.FromImage(bm_out)
ReDim Preserve corners(2)
gr_out.DrawImage(bm_in, corners)
picCar.Image = bm_out
End Sub
Private Sub Form2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.Left
lblAngle.Text -= 1
If lblAngle.Text < 0 Then
lblAngle.Text = 359
End If
End Select
Select Case e.KeyCode
Case Keys.Right
lblAngle.Text += 1
If lblAngle.Text > 359 Then
lblAngle.Text = 0
End If
End Select
Select Case e.KeyCode
Case Keys.Escape
End
End Select
Select Case e.KeyCode
Case Keys.Up
End Select
End Sub
End Class
Thanks in advance.