Public Class Form1
Dim pos As New Point
Dim alte As Single = 0
Dim dist As Single = 0
Dim velx, vely, vel, altmax As Single
Dim angr, angg, i As Double
Dim start, massimo As Integer
Dim mom As Integer
Dim temp As Double
Dim att, attrad, xsotto As Double
Private Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Keys) As Short
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
vel = velo.Text
altmax = proiettile.Top
massimo = sfondo.Top
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
proiettile.Top = sfondo.Top - proiettile.Height
End Sub
Private Sub vai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles vai.Click
angg = ango.Text
vel = velo.Text
angr = angg * Math.PI / 180
velx = Math.Cos(angr) * vel
vely = vel * Math.Sin(angr)
Timer1.Start()
vai.Enabled = False
Button1.Enabled = False
Button2.Enabled = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
i += 0.15
If i = 0.15 Then
attrad = Math.Atan((vely / velx))
att = attrad / Math.PI * 180
dist += ((vel ^ 2 * Math.Sin(2 * angr)) / g.Text)
dimax.Text = dist
altmax = Math.Abs((((vel ^ 2) * Math.Sin(angr) * Math.Cos(angr)) / g.Text) / 2)
almax.Text = altmax
temp += (2 * vel * Math.Sin(angr)) / g.Text
tem.Text = temp
start = proiettile.Left
End If
proiettile.Top = proiettile.Top - vely * i + (1 / 2 * g.Text * i ^ 2)
If proiettile.Top < massimo Then
massimo = proiettile.Top
End If
If proiettile.Top + proiettile.Height >= sfondo.Top Then
i = 0
Timer1.Enabled = False
proiettile.Top = sfondo.Top - proiettile.Height
vai.Enabled = True
Button1.Enabled = True
Button2.Enabled = True
End If
proiettile.Left = proiettile.Left + velx * i
If proiettile.Left > sfondo.Width Then
Threading.Thread.Sleep(100)
proiettile.Left = 0
ind.Left = 0
Threading.Thread.Sleep(100)
ElseIf proiettile.Left < 0 Then
Threading.Thread.Sleep(100)
proiettile.Left = sfondo.Width - proiettile.Width
ind.Left = proiettile.Left
Threading.Thread.Sleep(100)
End If
ind.Left = proiettile.Left
If proiettile.Top < PictureBox1.Top Then
ind.Visible = True
proiettile.Visible = False
Else
ind.Visible = False
proiettile.Visible = True
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
proiettile.Top = sfondo.Top - proiettile.Height - pos.Y
proiettile.Left = sfondo.Left + pos.X
almax.Text = 0
dimax.Text = 0
tem.Text = 0
End Sub
Private Sub g_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles g.TextChanged
If g.Text = "" Then g.Text = 0
If Not IsNumeric(g.Text) Then Exit Sub
End Sub
Private Sub ango_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ango.TextChanged
If ango.Text = "" Then ango.Text = 0
End Sub
Private Sub velo_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles velo.TextChanged
If velo.Text = "" Then velo.Text = 0
End Sub
Private Sub Form1_HelpButtonClicked(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.HelpButtonClicked
Form2.Show()
End Sub
Private Sub Form1_HelpRequested(ByVal sender As System.Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs) Handles MyBase.HelpRequested
Form2.Show()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
proiettile.Top = sfondo.Top - proiettile.Height
proiettile.Left = sfondo.Left
velo.Text = 10
ango.Text = 45
g.Text = "9,81"
almax.Text = 0
dimax.Text = 0
tem.Text = 0
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If GetAsyncKeyState(Keys.Escape) < 0 Then
If Timer1.Enabled Then
Timer1.Stop()
proiettile.Top = sfondo.Top - proiettile.Height
proiettile.Left = start
i = 0
dist = 0
ind.Visible = False
proiettile.Visible = True
vai.Enabled = True
Button1.Enabled = True
Button2.Enabled = True
End If
End If
End Sub
End Class