}

打野鸡

临美两载,春夏秋冬,过红海禅神机; 学道廿年,酸甜苦辣,铸刚韧造灵秀.[
打印 被阅读次数

你的电脑要预装MATLAB 和COGENT
% This code test your ability of timing.When a bird flies to you,you need
% to time and then trigger to shoot it.

function shooting_birdmouse_Timing( trials, velocity )
trials=6;
velocity=4;
cgloadlib
cgopen(1,0,0,1)
%cgscale(30)
%cgfont('Arial',4)
%fprintf('Shooting Bird is Funny.\n\n')
for i=1:trials
 a=rand(1,1);
if ay=(80+160*rand(1,1));
else
y=( -80-160*rand(1,1));
end
b=rand(1,1);
if bx=(100+220*rand(1,1));
else
x=( -100-220*rand(1,1));
end  
%x=ceil((320-640*rand(1,1))+.1);
%if abs(x)%end
%y=ceil((240-480*rand(1,1))+.1);
%if abs(y)%end
cgpencol(0,0,1)
cgellipse(x,y,30,30,'f')
mouse_pressed=0;
cgpencol(1,0,0)
cgellipse(0,-225,30,30,'f')
cgflip(0,0,0)
wait(2500);
if abs(x)>=abs(y)
% move the bird 1
for i=0:abs(x)
     % gun (red circle) movements...
     cgpencol(1,0,0)
     if mouse_pressed==1
      
      % move red circle (shoot)
    
       cgellipse(0,-255+velocity*(i-click),30,30,'f')
 
     else
        % fixed red circle (no shot)
         cgellipse(0,-225,30,30,'f')
     end

     cgpencol(1,1,0)
    % quadrant bird display
    if x>0 & y>0
    cgellipse(x-i,y-i*y/x,30,30,'f')
    elseif x>0 & y        cgellipse(x-i,y-i*y/x,30,30,'f')
    elseif x0
        cgellipse(x+i,y+i*y/x,30,30,'f')
    elseif x        cgellipse(x+i,y+i*y/x,30,30,'f')
    end
    %         time=cgflip(0,0,0);
    %          waituntil(time+10);

    [mx,my,bs,bp]=cgmouse;
    if bs>=1
        mouse_pressed=1;
        click=i;
        bs=0;
    end   

    cgflip(0,0,0)
    end
mouse_pressed=0;
end

if abs(x)% move the bird 2
for i=0:abs(y)
     % gun (red circle) movements...
     cgpencol(1,0,0)
     if mouse_pressed==1
        % move red circle (shoot)
         cgellipse(0,-255+velocity*(i-click),30,30,'f')
     else
        % fixed red circle (no shot)
         cgellipse(0,-225,30,30,'f')
     end  
     cgpencol(1,1,0)
    % quadrant bird display
    if x>0 & y>0
    cgellipse(x-i*x/y,y-i,30,30,'f')
    elseif x>0 & y        cgellipse(x+i*x/y,y+i,30,30,'f')
    elseif x0
        cgellipse(x-i*x/y,y-i,30,30,'f')
    else x        cgellipse(x+i*x/y,y+i,30,30,'f')
  
    end
    %time=cgflip(0,0,0);
    %waituntil(time+10);

    % cgmouse(0,-225)
    % mouse shooting check
    [mx,my,bs,bp]=cgmouse;
    if bs>=1
        mouse_pressed=1;
         click=i;
         bs=0;
    end   
    cgflip(0,0,0)
    end
mouse_pressed=0;
end
wait(1000);
cgflip(0,0,0)
wait(3000);
end
%cgflip(0,0,0)
wait(500);
cgshut

登录后才可评论.