无花果树下

临美两载,春夏秋冬,过红海禅神机; 学道廿年,酸甜苦辣,铸刚韧造灵秀.[
正文

打野鸡

(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)
评论
目前还没有任何评论
登录后才可评论.