using System;
using System.Timers;
using System.Drawing;
namespace Parabola
{
class Salto
{
public delegate void Siguiente(int x, int y);
public event Siguiente onSiguiente;
public delegate void Tope(int x, int y);
public event Tope onTope;
int f_xInicial = 0;
int f_yInicial = 0;
int f_VelocidadInicial;
double f_Gravedad = 9.8;
double f_Grados;
double radianes;
Timer timer;
Rectangle f_Ventana;
public int XInicial
{
get { return f_xInicial; }
set { f_xInicial = value; }
}
public int YInicial
{
get { return f_yInicial; }
set { f_yInicial = value; }
}
public int VelocidadInicial
{
get { return f_VelocidadInicial; }
set { f_VelocidadInicial = value; }
}
public double Gravedad
{
get { return f_Gravedad; }
set { f_Gravedad = value; }
}
public double Grados
{
get { return f_Grados; }
set
{
f_Grados = value;
radianes = (double)(f_Grados * Math.PI / 180);
}
}
public Rectangle Ventana
{
get { return f_Ventana; }
set { f_Ventana = value; }
}
public void Empieza()
{
timer = new Timer();
timer.Interval = 10;
timer.Elapsed+= Timer_Tick;
timer.Start();
}
public void Para()
{
timer.Stop();
}
double tiempo = 0;
int x;
int y;
double vy;
private void Timer_Tick(object sender, EventArgs e)
{
double ymax, tm;
x = (int)(f_VelocidadInicial * Math.Cos(radianes) * tiempo);
y = (int)(f_VelocidadInicial * Math.Sin(radianes) * tiempo - (.5 * f_Gravedad * (tiempo * tiempo)));
vy = (int)(f_VelocidadInicial * Math.Sin(radianes) - (f_Gravedad * tiempo));
tiempo += 0.1;
int xx = f_Ventana.Width - (x + f_xInicial);
int yy = f_Ventana.Height - (y+ f_yInicial);
if (xx >= 0 && xx <= f_Ventana.Width && yy >= 1 && yy <= f_Ventana.Height) if (onSiguiente != null) onSiguiente(xx, yy); else;
else if (onTope != null) onTope(xx, yy);
}
}
}