無花果樹下

臨美兩載,春夏秋冬,過紅海禪神機; 學道廿年,酸甜苦辣,鑄剛韌造靈秀.[
正文

打野雞

(2009-12-24 12:44:29) 下一個

你的電腦要預裝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 a<=.5
y=(80+160*rand(1,1));
else
y=( -80-160*rand(1,1));
end
b=rand(1,1);
if b<=.5
x=(100+220*rand(1,1));
else
x=( -100-220*rand(1,1));
end  
%x=ceil((320-640*rand(1,1))+.1);
%if abs(x)<100
%end
%y=ceil((240-480*rand(1,1))+.1);
%if abs(y)<100
%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<0
        cgellipse(x-i,y-i*y/x,30,30,'f')
    elseif x<0 & y>0
        cgellipse(x+i,y+i*y/x,30,30,'f')
    elseif x<0 & y<0
        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<0
        cgellipse(x+i*x/y,y+i,30,30,'f')
    elseif x<0 & y>0
        cgellipse(x-i*x/y,y-i,30,30,'f')
    else x<0 & y<0
        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

[ 打印 ]
閱讀 ()評論 (0)
評論
目前還沒有任何評論
登錄後才可評論.