' Juan Antonio Villalpando
' juana1991@yahoo.com
Sub Globals
Dim pnlLayer, pnlLayer2 As Panel
Dim cvsLayer As Canvas
Dim Boton As Button
Dim scrollvelocidad, scrollangulo As SeekBar
Dim labelvelocidad, labelangulo As Label
Dim labelalturamaxima, labelalcance As Label
Dim bmpBackground, bmpBackground1 As Bitmap
Dim bmdBackground, bmdBackground1 As BitmapDrawable
Dim xc, yc As Int
Dim xVal, yVal, xDelta, yDelta, xOrigin, yOrigin As Int
Dim DestRect As Rect
Dim temporizador As Timer
Dim radianes, grados, velocidad As Float
Dim alturamaxima, alcance As Int
grados = 0
radianes = 0
velocidad = 0
xc = 0
yc = 0
End Sub
Sub Activity_Create(FirstTime As Boolean)
' Fondo de pantalla del Activity
bmpBackground.Initialize(File.DirAssets,"paisaje.gif")
bmpBackground1.Initialize(File.DirAssets,"arbol.gif")
bmdBackground.Initialize(bmpBackground)
bmdBackground1.Initialize(bmpBackground1)
Activity.Background = bmdBackground
' Crea los Paneles
pnlLayer.Initialize("pnlLayer")
Activity.AddView(pnlLayer, 0, 0, 100%x, 100%y)
pnlLayer2.Initialize("pnlLayer2")
pnlLayer2.SetBackgroundImage(LoadBitmap(File.DirAssets, "arbol.gif"))
pnlLayer.AddView(pnlLayer2, 100%x-40, 100%y-40, 5%x, 10%y)
' Crea un Canvas en el Panel, para dibujar el círculo rojo.
cvsLayer.Initialize(pnlLayer)
' Crea Botón
boton.Initialize("boton")
Activity.AddView(boton, 5, 200, 160, 55) ' Posicion, ancho y alto
boton.Text = "Disparo"
' Crea Scroll de la velocidad
scrollvelocidad.Initialize("scrollvelocidad")
scrollvelocidad.Max = 100 ' 100 m/s son 360 km/h
Activity.AddView(scrollvelocidad, 5, 5, 200, 30) ' Posicion, ancho y alto
' Crea Scroll del ángulo
scrollangulo.Initialize("scrollangulo")
scrollangulo.Max = 90 ' Ángulo máximo de tiro
Activity.AddView(scrollangulo, 5, 50, 200, 30) ' Posicion, ancho y alto
' Crea etiqueta de velocidad
labelvelocidad.Initialize("labelvelocidad")
labelvelocidad.TextColor = Colors.Black
labelvelocidad.Text = "Velocidad = "
Activity.AddView(labelvelocidad, 210, 5, 200, 30) ' Posicion, ancho y alto
' Crea etiqueta de ángulo
labelangulo.Initialize("labelangulo")
labelangulo.TextColor = Colors.Black
labelangulo.Text = "Ángulo = "
Activity.AddView(labelangulo, 210, 50, 200, 30) ' Posicion, ancho y alto
' Crea etiqueta de altura máxima
labelalturamaxima.Initialize("labelalturamaxima")
labelalturamaxima.TextColor = Colors.Black
labelalturamaxima.Text = "Altura máxima = "
Activity.AddView(labelalturamaxima, 5, 100, 220, 30) ' Posicion, ancho y alto
' Crea etiqueta de alcance
labelalcance.Initialize("labelalcance")
labelalcance.TextColor = Colors.Black
labelalcance.Text = "Alcance = "
Activity.AddView(labelalcance, 5, 150, 200, 30) ' Posicion, ancho y alto
' Temporizador
temporizador.Initialize("temporizador", 20) ' 1000 = 1 segundo
temporizador.Enabled = True
DestRect.Initialize(0dip, 0dip, 100%x,100%y)
End Sub
Sub Activity_Resume
End Sub
Sub pnlLayer_Touch (Action As Int, X As Float, Y As Float)
' Arrastre del dibujo del árbol
X = X-(pnlLayer2.Width/2)
Y = Y-(pnlLayer2.Height/2)
If x >= 0 AND x <= pnlLayer.Width-pnlLayer2.Width Then
pnlLayer2.Left = X
End If
If y >= 0 AND y <= pnlLayer.Height-pnlLayer2.Height Then
pnlLayer2.Top = Y
End If
End Sub
Sub boton_Click
' Temporizador.Enabled = Not(Temporizador.Enabled)
xc= 0
yc = 0
End Sub
Sub Temporizador_Tick
' Debemos pasar el ángulo a radianes para realizar las funciones trigonométricas
radianes = (grados * 2 * 3.1416) / 360
' Cálculo de la trayectoria, altura.
yc = 100%y - (xc * Tan(radianes) - (9.8 * xc * xc)/ (2 * velocidad * velocidad * Cos(radianes) * Cos(radianes)))
xc = xc + 5
' Dibujo del círculo rojo según xc - yc
cvsLayer.DrawBitmap(bmpBackground, Null, DestRect) ' Si quieres dibujar el recorrido, anula esta línea.
cvsLayer.DrawCircle(xc, yc, 5, Colors.Red, True, 3dip)
pnlLayer.Invalidate
End Sub
Sub scrollvelocidad_ValueChanged (Value As Int, UserChanged As Boolean)
' Establece la velocidad y calcula altura y alcance
labelvelocidad.Text = "Velocidad = " & Value & " m/s"
velocidad = Value
alturamaxima = (velocidad * velocidad * Sin(radianes) * Sin(radianes)) / (2 * 9.8)
labelalturamaxima.Text = "Altura máxima = " & alturamaxima & " m"
alcance = (velocidad * velocidad * Sin(2 * radianes)) / (2 * 9.8)
labelalcance.Text = "Alcance = " & alcance & " m"
End Sub
Sub scrollangulo_ValueChanged (Value As Int, UserChanged As Boolean)
' Establece el ángulo y calcula altura y alcance
labelangulo.Text = "Ángulo = " & Value & "º"
grados = Value
alturamaxima = (velocidad * velocidad * Sin(radianes) * Sin(radianes)) / (2 * 9.8)
labelalturamaxima.Text = "Altura máxima = " & alturamaxima & " m"
alcance = (velocidad * velocidad * Sin(2 * radianes)) / (2 * 9.8)
labelalcance.Text = "Alcance = " & alcance & " m"
End Sub
|