Info

此问题已关闭。 请重新打开它进行编辑或回答。

Help with projectile game

1 次查看(过去 30 天)
Aaron Stronguin
Aaron Stronguin 2020-4-22
关闭: Ameer Hamza 2020-4-22
I am currently having trouble with my script outputing the scores when the user has scored a point by hitting the board on the plot with a ball. Any help will be greatly appreciated.
(script)
h=figure;
score = 0;
clf(h);
AxesH = axes('NextPlot','add');
while (1)
play = menu('Would you like to play?: ', 'Yes', 'No');
switch play
case (1)
b = input('Please input angle value: ');
if (b >= 0) && (b <=90)
[x,y] = HDTask1function_f(b);
z = rand()*3.5;
j = z+0.5;
hndl2=plot([z j],[0 0],'LineWidth',5);
hold on
set(gca,'Xlim',[0 4])
set(gca,'Ylim',[0 4])
hndl=plot(x(1),y(1),'r.','MarkerSize',50);
for ii=2:length(x)
drawnow;
set(hndl,'XData', x(ii), 'YData', y(ii));
pause(0.0025);
if y(ii:end) < 0
y(ii:end) = 0;
pause(0.5);
if x(1,ii) > z && x(1,ii) < j
score = score +1;
fprintf('Your current score is: %4.2', num2str(score));
end
break
end
end
else
disp('Invalid input. Please input an angle in the range of [0 - 90]');
end
case(2)
disp('Thankyou for visiting')
break;
end
end
(function)
function [x,y]=HDTask1function_f(a)
x0=0;
y0=1.8;
v0=4;
g=9.8;
t=0:0.01:5;
x=x0+v0*cos(a*(pi./180)).*t;
y=y0+v0*sin(a*(pi./180)).*t-(g.*t.^2)/2;
end
  1 个评论
Rik
Rik 2020-4-22
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.

回答(0 个)

此问题已关闭。

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by