PDA

View Full Version : [VB] Spostare palla


francesca911
19-12-2008, 16:10
Salve a tutti!!
vi scrivo per chiedervi un piccolo aiuto per un programmino di VB:
sono al terzo anno di liceo e per il primo anno mi trovo ad affrontare questo genere di programma
e vorrei sapere come posso fare a:
con un solo timer a spostare una pallina per la form con i tasti W E R S D Z X C rispettivamente in diagonale
verso l'alto a dx, su , in diagonale verso l'alto a sx, a dx, a sx, diagonale bassa a sx, gių e infine in diagonale bassa a dx.
l'unica indicazione che ci č stata data dall'insegnante e stata:
Private sub frm_keypress(keyascii as integer)
carattere=chr(keyascii)
end sub

io sono solo riuscita a farlo cosė con 8 timer:
Private Sub Form_KeyPress(KeyAscii As Integer)
carattere = Chr(KeyAscii)
If carattere = "d" Then
Tm1.Enabled = True
End If
If carattere = "s" Then
Tm2.Enabled = True
End If
If carattere = "x" Then
Tm3.Enabled = True
End If
If carattere = "" Then
Tm5.Enabled = True
End If
If carattere = "e" Then
Tm6.Enabled = True
End If
If carattere = "w" Then
Tm7.Enabled = True
End If
If carattere = "r" Then
Tm8.Enabled = True
End If
If carattere = "z" Then
Tm9.Enabled = True
End If
If carattere = "c" Then
Tm4.Enabled = True
End If

End Sub


Private Sub Tm1_Timer()
ShpPalla.Left = ShpPalla.Left + 25
If ShpPalla.Left <= frm1.ScaleWidth + ShpPalla.Width Then
Tm1.Enabled = False

End If


End Sub

Private Sub Tm2_Timer()

ShpPalla.Left = ShpPalla.Left - 25
If (ShpPalla.Left <= frm1.ScaleWidth + ShpPalla.Width) Then
Tm2.Enabled = False

End If

End Sub

Private Sub Tm3_Timer()
ShpPalla.Top = ShpPalla.Top + 25
If ShpPalla.Top <= frm1.ScaleHeight + ShpPalla.Height Then
Tm3.Enabled = False
End If
End Sub

Private Sub Tm4_Timer()
ShpPalla.Left = ShpPalla.Left + 25
ShpPalla.Top = ShpPalla.Top + 25
If (ShpPalla.Left <= frm1.ScaleWidth + ShpPalla.Width) And (ShpPalla.Top <= frm1.ScaleHeight + ShpPalla.Height) Then
Tm4.Enabled = False
End If

End Sub

Private Sub Tm6_Timer()
ShpPalla.Top = ShpPalla.Top - 25
If (ShpPalla.Top < frm1.ScaleHeight + ShpPalla.Height) Then
Tm6.Enabled = False
End If

End Sub

Private Sub Tm7_Timer()
ShpPalla.Left = ShpPalla.Left - 25
ShpPalla.Top = ShpPalla.Top - 25
If (ShpPalla.Left <= frm1.ScaleWidth + ShpPalla.Width) And (ShpPalla.Top <= frm1.ScaleHeight + ShpPalla.Height) Then
Tm7.Enabled = False
End If

End Sub

Private Sub Tm8_Timer()
ShpPalla.Left = ShpPalla.Left + 25
ShpPalla.Top = ShpPalla.Top - 25
If (ShpPalla.Left <= frm1.ScaleWidth + ShpPalla.Width) And (ShpPalla.Top <= frm1.ScaleHeight + ShpPalla.Height) Then
Tm8.Enabled = False
End If

End Sub

Private Sub Tm9_Timer()
ShpPalla.Left = ShpPalla.Left - 25
ShpPalla.Top = ShpPalla.Top + 25
If (ShpPalla.Left <= frm1.ScaleWidth + ShpPalla.Width) And (ShpPalla.Top <= frm1.ScaleHeight + ShpPalla.Height) Then
Tm9.Enabled = False
End If

End Sub

grazie mille per l'aiuto^^
( mi servirebbe entro le sei di stasera se nn č un problema)

DanieleC88
19-12-2008, 16:24
Ti basta un solo timer, ogni volta che viene premuto un tasto salvi il suo valore ASCII come ti ha fatto vedere la prof, e poi nella routine del timer gestisci i vari casi (a seconda del tasto premuto, vai a sinistra, vai a destra, vai gių, etc...).

ciao ;)

francesca911
19-12-2008, 18:35
grazie!!!!!