g = 9.8;
v = 100;
distance = 500+500*rand;
kill = false;
while ~kill
    angle = input('Enter angle in degrees: ');
    theta = angle * pi / 180;
    range = v^2 * sin(2 * theta) / g;
    vy = v * sin(theta);
    vx = v * cos(theta);
    time = 2 * vy/g;
    t = linspace(0, time, 100);
    x = vx .* t;
    y = vy .* t - 0.5 * g * t.^2;
    plot (x, y);
    xlabel('distance (meters)');
    ylabel('height (meters)');
    title('Trajectory Game');
    fprintf('distance is %f, target is %f\n',range, distance)
    if abs(distance - range) < 10
        kill = true;
        disp('You got it!');
    else
        disp('Try again');
    end
end
