Mulla ois tämmönen koodi mikä on pielessä tai mitä tarvis lisätä
formilla pitäisi olla pictureboxi(mato) ja Timer(Timer1)
Kun painaa formia mato alkaa liikkua mutta käännös ei tapahdu
Dim suunta
Private Sub Form_Click()
suunta = 2
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 38
suunta = 1
Case 39
suunta = 2
Case 40
suunta = 3
Case 37
suunta = 4
End Select
End Sub
Private Sub Form_Load()
Form1.ScaleMode = 7
mato.ScaleMode = 7
mato.Height = 1
mato.Width = 1
End Sub
Private Sub Timer1_Timer()
If suunta = 1 Then
mato.Top = mato.Top - 1
ElseIf suunta = 2 Then
mato.Left = mato.Left + 1
ElseIf suunta = 3 Then
mato.Top = mato.Top + 1
ElseIf suunta = 4 Then
mato.Left = mato.Left - 1
End If
End SubForm1.Keypreview = true
Muutappa tuo :)
kiitos!
nyt toimii!
Sorry! unohdin koodi-merkit...
Dim Suunta As Go
Private Sub Form_Click()
Suunta.X = 0
Suunta.Y = 0
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 38
Suunta.Y = -1: Suunta.X = 0 'Ylös
Case 39
Suunta.X = 1: Suunta.Y = 0 ' Oikealle
Case 40
Suunta.Y = 1: Suunta.X = 0 ' Alas
Case 37
Suunta.X = -1: Suunta.Y = 0 ' Vasemmalle
Case 32
Suunta.Y = 0: Suunta.X = 0
End Select
End Sub
Private Sub Form_Load()
Form1.ScaleMode = 7
Mato.ScaleMode = 7
Mato.Height = 1
Mato.Width = 1
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
Mato.Top = Mato.Top + Suunta.Y
Mato.Left = Mato.Left + Suunta.X
End Sub
'Ja moduuli
Type Go
X As Integer
Y As Integer
End TypeEhsottaisin, että muokkaisit viestejäsi tästä eteenpäin. Voithan vielä nytkin muokata :).
Tarkennus, nyt voit poistaa muut Suunta.X = 0 rivit, jos haluat...
Private Sub Timer1_Timer() Mato.Top = Mato.Top + Suunta.Y Mato.Left = Mato.Left + Suunta.X Suunta.x =0 : Suunta.Y = 0 End Sub
Aihe on jo aika vanha, joten et voi enää vastata siihen.