PROGRAM m7stuff;
CONST
GLOBAL
ground_map;
file1;
map;
ground_wide = 512;
ground_high = 512;
modex=1200;
modey=700;
splashes;
mouse_x[1];
mouse_y[1];
mouse_Dx;
mouse_dy;
mouse_x0;
mouse_y0;
mouseleft;
mouseright;
treemap;
//-------------------------------------------------------------------------------------
BEGIN
x=ground_wide/2;
y=ground_high-32;
maketreemaps();
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;
mouse_handler();
dropper(x,y);
loop
if(key(_esc))
exit(0,0);
end
frame;
end
END
//---------------------------------------------------------------------------
function maketreemaps();
begin
treemap=new_map(200,200,5,199,0);
frame;
end
//---------------------------------------------------------------------------
function mapdrawline(x0,y0,x1,y1,graph,pen);
private
length;
i;
px; py;
begin
length=fget_dist(x0,y0,x1,y1);
for(i=0;i<=length;i+=1)
px=x0+(i*1000/length)*(x1-x0)/1000;
py=y0+(i*1000/length)*(y1-y0)/1000;
map_xput(0,graph,pen,px,py,0,200,0);
end
end
function plant_tree(x,y)
private
w; cx; cy; graph0;
h;
i;j; k;
col=32; dcol;
leaves[15];
points=360;
variety;
asp=1; fir=2; OAK=3; shrub=4;
struct point[1]
x;
y;
end
edge;
angle1;
rad;
dr;
dy;
begin
variety=rand(asp,oak);
switch (variety)
case oak:
h=rand(200,300);
w=h-rand(0,h/4);
cx=w/2;
cy=9*h/20;
graph0=new_map(w,h,w/2,h-1,4);
tree(x,y,w,h,graph0);
frame;
for(i=0; i<16; i+=1)
leaves[i]=new_map(5,5,2,2,col+i);
end
for(i=-w/10;i<=w/10; i+=1)
for(j=h-1;j>=2*h/3; j-=1)
map_put_pixel(0,graph0,w/2+i,j,118);
end
end
tree(x,y,w,h,graph0);
angle=90000;
points=rand(20,30);
for(i=0; i<points; i+=1)
angle1=angle+360000/points;
if(i==0)
point.y=cy+get_disty(angle,cy-10);
point.x=cx+get_distx(angle,cx-20);
else
point.x=point[1].x;
point.y=point[1].y;
end
point[1].y=cy+get_disty(angle1,cy-10);
point[1].x=cx+get_distx(angle1,cx-20);
if(i<points-1)
rad=fget_dist(point[1].x,point[1].y,cx,cy);
dr=rand(-10,10);
if(rand(0,5)==1)
dr=-rad/4;
end
point[1].x=cx+get_distx(angle1,rad+dr);
point[1].y=cy+get_disty(angle1,rad+dr);
end
mapdrawline(point[1].x,point[1].y,point.x,point.y,graph0,leaves[0]);
frame;
dcol=angle/60000;
// map_put(0,graph0,leaves[0],point.x,point.y);
angle=angle1;
end
end
case asp:
h=rand(200,300);
w=h/3+rand(h/20,h/10);
cx=w/2;
cy=4*h/10;
graph0=new_map(w,h,w/2,h-1,4);
tree(x,y,w,h,graph0);
for(i=0; i<16; i+=1)
leaves[i]=new_map(5,5,2,2,col+i);
end
for(i=-w/10;i<=w/10; i+=1)
for(j=h-1;j>=2*h/3; j-=1)
map_put_pixel(0,graph0,w/2+i,j,118);
end
end
frame;
angle=90000;
for(i=0; i<=points; i+=1)
point.y=cy+get_disty(angle,cy-1);
point.x=cx+get_distx(angle,cx-20)*point.y/cy;
dcol=angle/60000;
map_put(0,graph0,leaves[0],point.x,point.y);
angle+=360000/points;
end
frame;
end
case fir:
h=rand(200,300);
w=h/3+rand(h/10,h/5);
cx=w/2;
cy=4*h/10;
graph0=new_map(w,h,w/2,h-1,4);
for(i=0; i<16; i+=1)
leaves[i]=new_map(5,5,2,2,col+i);
end
for(i=-w/10;i<=w/10; i+=1)
for(j=h-1;j>=2*h/3; j-=1)
map_put_pixel(0,graph0,w/2+i,j,118);
end
end
tree(x,y,w,h,graph0);
point.x=w-1;
point.y=85*h/100;
points=rand(3,6);
point[1].x=0;
point[1].y=0;
dy=point.y/points;
for(k=1; k<=points; k+=1)
j=k*dy;
i=(j*1000/point.y)*(cx-10)/1000;
map_put(0,graph0,leaves[0],cx+i,j);
map_put(0,graph0,leaves[0],cx-i,j);
mapdrawline(cx+point[1].x,point[1].y,cx+i+5,j,graph0,leaves[0]) ;
frame;
mapdrawline(cx-point[1].x,point[1].y,cx-i-5,j,graph0,leaves[0]) ;
frame;
point[1].x=i;
point[1].y=j;
end
mapdrawline(cx-i,j,cx+i,j,graph0,leaves[0]) ;
for(i=0; i<w; i+=1)
j=85*h/100;
map_put(0,graph0,leaves[0],i,j);
end
end
default:
end
end
for(i=0; i<w; i+=1)
for(j=0; j<h; j+=1)
edge=map_get_pixel(0,graph0,i,j);
if(edge==4)
map_put_pixel(0,graph0,i,j,0);
else
if(edge==118)
map_put_pixel(0,graph0,i,j,114);
else
break;
END
end
end
for(j=h-1; j>=0; j-=1)
edge=map_get_pixel(0,graph0,i,j);
if(edge==4)
map_put_pixel(0,graph0,i,j,0);
else
if(edge==118)
map_put_pixel(0,graph0,i,j,114);
else
break;
end
end
end
end
for(j=0; j<h; j+=1)
for(i=0; i<w; i+=1)
edge=map_get_pixel(0,graph0,i,j);
if(edge<>COL and edge <>114)
map_put_pixel(0,graph0,i,j,0);
else
break;
end
end
for(i=w-1; i>=0; i-=1)
edge=map_get_pixel(0,graph0,i,j);
if(edge<>COL and edge <>114)
map_put_pixel(0,graph0,i,j,0);
else
break;
end
end
end
frame;
for(i=0; i<w; i+=1)
for(j=0; j<h; j+=1)
edge=map_get_pixel(0,graph0,i,j);
if(edge==4 or edge==118);
// map_put(0,graph,leaves[2],i,j);
map_put_pixel(0,graph0,i,j,col+2);
end
end
end
frame;
for(i=0; i<16; i+=1)
unload_map(leaves[i]);
end
end
process tree(x,y,w,h,graph)
begin
ctype=c_m7;
loop
frame;
end
end
//---------------------------------------------------------------------------
PROCESS makemap()
PRIVATE
i; j;
BEGIN
ctype = c_m7;
x=ground_wide/2;
y=ground_high/2;
angle=30000;
ground_map =new_map(ground_wide,ground_high,ground_wide/2,ground_high/2,6);
loop
if(key(_left))
angle-=1000;
end
if(key(_right))
angle+=1000;
end
frame;
end
END
PROCESS dropper(x,y);
PRIVATE
spl;
txt[4];
j;
BEGIN
ctype=c_m7;
priority=-1;
z=1;
height =100;
graph=new_map(10,40,5,0,26);
// mouse.graph=graph;
x=255;
y=255;
LOOP
mouse_dx=mouse.x-mouse_x0;
mouse_dy=mouse.y-mouse_y0;
x+=-get_distx(m7.camera.angle,mouse_dy)-get_disty(m7.camera.angle,mouse_dx);
if(x<0) x=0; end
if(x>ground_wide) x=ground_wide; end
y+=get_distx(m7.camera.angle,mouse_dx)-get_disty(m7.camera.angle,mouse_dy);
if(y<0) y=0; end
if(y>ground_high) y=ground_high; end
if(mouse.left)
if(mouseleft==0)
plant_tree(x,y);
end
mouseleft=1;
else
mouseleft=0;
end
FRAME;
delete_text(txt);
END
end
process mouse_handler()
private
f;
j;
begin
priority=-100;
mouse.x=100;
mouse.y=100;
for(j=0; j<1; j+=1)
mouse_x[j]=mouse.x;
mouse_y[j]=mouse.y;
end
mouse_x0=mouse.x;
mouse_y0=mouse.y;
mouse_dx=0;
mouse_dy=0;
loop
f+=1;
f=f mod 1;
mouse_x[f]=mouse.x;
mouse_y[f]=mouse.y;
mouse_x0=mouse_x[f];
mouse_y0=mouse_y[f];
write(0,100,10,0,"MODE7 MOUSE DEMO");
write(0,100,20,0,"rotate view with _left, _right");
write(0,100,30,0,"left click for a tree");
write(0,100,40,0,"press _esc to exit");
frame;
mouse_dx=mouse.x-100;
mouse_dy=mouse.y-100;
mouse.x-=mouse_dx;
mouse.y-=mouse_dy;
for(j=0; j<=1;j+=1)
mouse_x[f]-=mouse_dx;
mouse_y[f]-=mouse_dy;
end
end
end
|