compiler_options  _max_process=10000;

PROGRAM golf2;

GLOBAL
        ground_map;
 file1;
 map;
 ball_id;
      ground_wide = 512;
      ground_high = 512;
      modex=1200;
      modey=700;
      splashes;

BEGIN

      x=ground_wide/2;
      y=ground_high-32;


    mouse.x=100;  mouse.y=100;


    map=makemap();
    set_fps(60,0);
    write_int(0,10,10,0,&fps);
    set_mode(1200700);
    start_mode7(       0,    file1,   ground_map,            0,         0,              128    );

    m7.height = 3210;
    m7.distance = 1144;
    m7.color = 210;
    m7.camera =  map;
    m7.horizon =-1024;
    m7.focus = 500;
    m7.z = 0;

      dropper(x,y);



    END

 //----------------------------------------------




PROCESS makemap()
  PRIVATE
  i; j;
  BEGIN
    ctype = c_m7;
    x=ground_wide/2;
    y=ground_high/2;
    //graph=3;
    angle=90000;
    ground_map =new_map(ground_wide,ground_high,ground_wide/2,ground_high/2,5+16*rand(0,14));
    loop
    frame;
    end

  END



PROCESS dropper(x,y);
PRIVATE
spl;
BEGIN
    ctype=c_m7;
    priority=-1;
    z=1;
    height =200;
    graph=new_map(25,25,12,12,8);
    shadow(resolution) ;




    LOOP

        repeat
            spl=get_id(type splash);
            if(spl<>0)
                splashes+=1;
            end
        until(spl==0)

        x=-50+(mouse.x*(ground_wide+100)/modex);
        y=-50+(mouse.y*(ground_high+100)/modey);

        if(splashes<100)

            if(mouse.left)
                signal(ball_id, s_kill_tree);
                ball_id =ball(x,y,0,100,5000);
                ball_id.height = height;
            END

            if(mouse.right)
                splash(x,y);
            END
        end
        FRAME;
    END
end






PROCESS splash(x,y)
private
d=0;
droplets=5;

BEGIN
ctype = c_m7;

     graph=3;
     flags=4;
REPEAT
droplet(x,y,d);
d+=1;
UNTIL(d>=droplets)

END




PROCESS droplet(x,y,d)
PRIVATE
c=0;
life=100;
vx; vy; vxy; vz;
BEGIN
resolution=1000;
x=x*resolution;
y=y*resolution;
angle=rand(0,360000);
vxy=rand(500,1500);
vz=rand(15,20);
size=rand(50,70);
graph=new_map(20,20,2,2,rand(10,15));
shadow(resolution);
//height=d*100;
ctype=c_m7;

    LOOP
     vz-=1;
     height+=vz;
     advance(vxy) ;
     if(height<=0) ;
     unload_map(graph);
     son.height=-1000;
     break;
     END
     if(vz<0) flags=4; END
      FRAME;

      END

END








PROCESS ball(x,y,angle,size,vz)

PRIVATE
 vx; vy;   vxy;   x0; y0;
 grav= -250;
 state = 2 ;
 power=0;
  BEGIN
    angle  = 90000;
    z=-1000;
    ctype=c_m7;
    resolution = 1000;
    x=x*resolution; y= y*resolution;
  x0=x; y0=y;
    graph=new_map(10,10,5,5,15);

    shadow(resolution);

    LOOP
                height+=vz/resolution;

                IF(height>0):
                    vz+=grav;
                ELSE
                    splash(x/resolution,y/resolution);
                    break;
                END
        FRAME;
    END
          unload_map(graph);

END

PROCESS shadow(resolution);


BEGIN
    x=graphic_info(0,father.graph,G_wide);
    y=graphic_info(0,father.graph,G_height);
    ctype=c_m7;
    graph=new_map(x,y,x/2,y/2,1);
    flags=4;

    priority=-1;
    z=1;
    size = father.size;
    height =0;
    LOOP
        x=father.x;
        y=father.y;
        if(height<0)
          unload_map(graph);

        break;
        end
        FRAME;
    END

END
