Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c7a7e604f1 | |||
| cdfb966fc3 |
171
ASTEROID.PAS
171
ASTEROID.PAS
@@ -1,4 +1,4 @@
|
|||||||
uses mouse,crt,keyboard;
|
uses crt,keyboard,sencos;
|
||||||
|
|
||||||
const
|
const
|
||||||
marge_dalt=20;
|
marge_dalt=20;
|
||||||
@@ -7,6 +7,9 @@ const
|
|||||||
marge_dret=620;
|
marge_dret=620;
|
||||||
max_ipunts=30;
|
max_ipunts=30;
|
||||||
max_ornis=15;
|
max_ornis=15;
|
||||||
|
velocitat=2;
|
||||||
|
velocitat_max=6;
|
||||||
|
max_bales=3;
|
||||||
type
|
type
|
||||||
ipunt=RECORD r,angle:real; END;
|
ipunt=RECORD r,angle:real; END;
|
||||||
punt=RECORD x,y:integer; END;
|
punt=RECORD x,y:integer; END;
|
||||||
@@ -23,12 +26,22 @@ type
|
|||||||
velocitat:real;
|
velocitat:real;
|
||||||
n:byte;
|
n:byte;
|
||||||
drotacio,rotacio:real;
|
drotacio,rotacio:real;
|
||||||
|
esta:boolean;
|
||||||
END;
|
END;
|
||||||
|
|
||||||
|
|
||||||
pvirt=array [1..38400] of byte;
|
pvirt=array [1..38400] of byte;
|
||||||
|
|
||||||
var virt:^pvirt;
|
var nau:triangle;pol:poligon;
|
||||||
|
ang:real;
|
||||||
|
ch:char;
|
||||||
|
Dx,Dy:word;
|
||||||
|
i,aux:byte;
|
||||||
|
dist:integer;
|
||||||
|
puntaux:punt;
|
||||||
|
orni:array [1..max_ornis] of poligon;
|
||||||
|
virt:^pvirt;
|
||||||
|
bales:array [1..max_bales] of poligon;
|
||||||
|
|
||||||
procedure volca;
|
procedure volca;
|
||||||
var i:word;
|
var i:word;
|
||||||
@@ -49,9 +62,9 @@ begin
|
|||||||
act:=act + interval;
|
act:=act + interval;
|
||||||
end;
|
end;
|
||||||
pol.centre.x:=320;
|
pol.centre.x:=320;
|
||||||
pol.centre.y:=240;
|
pol.centre.y:=200;
|
||||||
pol.angle:=0;
|
pol.angle:=0;
|
||||||
pol.velocitat:=2;
|
pol.velocitat:=velocitat;
|
||||||
pol.n:=n;
|
pol.n:=n;
|
||||||
pol.drotacio:=0.078539816;
|
pol.drotacio:=0.078539816;
|
||||||
pol.rotacio:=0;
|
pol.rotacio:=0;
|
||||||
@@ -118,6 +131,21 @@ begin
|
|||||||
7:mem[seg(virt^):y*80+(x div 8)]:=(mem[seg(virt^):y*80+(x div 8)]AND $FE);
|
7:mem[seg(virt^):y*80+(x div 8)]:=(mem[seg(virt^):y*80+(x div 8)]AND $FE);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function llig(x,y:word):byte;
|
||||||
|
begin
|
||||||
|
case (x mod 8) of
|
||||||
|
0:llig:=(mem[seg(virt^):y*80+(x div 8)]AND $80)shr 7;
|
||||||
|
1:llig:=(mem[seg(virt^):y*80+(x div 8)]AND $40)shr 6;
|
||||||
|
2:llig:=(mem[seg(virt^):y*80+(x div 8)]AND $20)shr 5;
|
||||||
|
3:llig:=(mem[seg(virt^):y*80+(x div 8)]AND $10)shr 4;
|
||||||
|
4:llig:=(mem[seg(virt^):y*80+(x div 8)]AND $08)shr 3;
|
||||||
|
5:llig:=(mem[seg(virt^):y*80+(x div 8)]AND $04)shr 2;
|
||||||
|
6:llig:=(mem[seg(virt^):y*80+(x div 8)]AND $02)shr 1;
|
||||||
|
7:llig:=(mem[seg(virt^):y*80+(x div 8)]AND $01);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure posavga(x,y:word;color:byte);
|
procedure posavga(x,y:word;color:byte);
|
||||||
begin
|
begin
|
||||||
if color=1 then
|
if color=1 then
|
||||||
@@ -166,21 +194,29 @@ begin
|
|||||||
if p.y<>0 then angle:=arctan(p.x/p.y);
|
if p.y<>0 then angle:=arctan(p.x/p.y);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure linea(x1,y1,x2,y2,color:word);
|
procedure clsvirt;
|
||||||
|
var i:word;
|
||||||
|
begin
|
||||||
|
for i:=1 to 38400 do mem[seg(virt^):i]:=0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function linea(x1,y1,x2,y2,color:word):boolean;
|
||||||
|
|
||||||
function sign(x:integer):integer; {like sgn(x) in basic}
|
function sign(x:integer):integer; {like sgn(x) in basic}
|
||||||
begin if x<0 then sign:=-1 else if x>0 then sign:=1 else sign:=0 end;
|
begin if x<0 then sign:=-1 else if x>0 then sign:=1 else sign:=0 end;
|
||||||
|
|
||||||
var
|
var
|
||||||
x,y,count,xs,ys,xm,ym:integer;
|
x,y,count,xs,ys,xm,ym,col:integer;
|
||||||
begin
|
begin
|
||||||
|
linea:=false;
|
||||||
|
col:=0;
|
||||||
x:=x1;y:=y1;
|
x:=x1;y:=y1;
|
||||||
|
|
||||||
xs:=x2-x1; ys:=y2-y1;
|
xs:=x2-x1; ys:=y2-y1;
|
||||||
|
|
||||||
xm:=sign(xs); ym:=sign(ys);
|
xm:=sign(xs); ym:=sign(ys);
|
||||||
xs:=abs(xs); ys:=abs(ys);
|
xs:=abs(xs); ys:=abs(ys);
|
||||||
|
if llig(x,y)=1 then inc(col);
|
||||||
posa(x,y,color);
|
posa(x,y,color);
|
||||||
|
|
||||||
if xs > ys
|
if xs > ys
|
||||||
@@ -193,6 +229,7 @@ procedure linea(x1,y1,x2,y2,color:word);
|
|||||||
y:=y+ym;
|
y:=y+ym;
|
||||||
count:=count-xs;
|
count:=count-xs;
|
||||||
end;
|
end;
|
||||||
|
if llig(x,y)=1 then inc(col);
|
||||||
posa(x,y,color);
|
posa(x,y,color);
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
@@ -205,23 +242,26 @@ procedure linea(x1,y1,x2,y2,color:word);
|
|||||||
x:=x+xm;
|
x:=x+xm;
|
||||||
count:=count-ys;
|
count:=count-ys;
|
||||||
end;
|
end;
|
||||||
|
if llig(x,y)=1 then inc(col);
|
||||||
posa(x,y,color);
|
posa(x,y,color);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
if col>2 then linea:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure rota_tri(tri:triangle;angul,velocitat:real;color:byte);
|
function rota_tri(tri:triangle;angul,velocitat:real;color:byte):byte;
|
||||||
var x1,x2,x3,y1,y2,y3:word;
|
var x1,x2,x3,y1,y2,y3:word;
|
||||||
begin
|
begin
|
||||||
x1:=round((tri.p1.r+velocitat/2)*cos(tri.p1.angle+angul))+tri.centre.x;
|
x1:=round((tri.p1.r+velocitat)*cos(tri.p1.angle+angul))+tri.centre.x;
|
||||||
x2:=round((tri.p2.r+velocitat/2)*cos(tri.p2.angle+angul+velocitat/10))+tri.centre.x;
|
x2:=round((tri.p2.r+velocitat)*cos(tri.p2.angle+angul{+velocitat/20}))+tri.centre.x;
|
||||||
x3:=round((tri.p3.r+velocitat/2)*cos(tri.p3.angle+angul-velocitat/10))+tri.centre.x;
|
x3:=round((tri.p3.r+velocitat)*cos(tri.p3.angle+angul{-velocitat/20}))+tri.centre.x;
|
||||||
y1:=round((tri.p1.r+velocitat/2)*sin(tri.p1.angle+angul))+tri.centre.y;
|
y1:=round((tri.p1.r+velocitat)*sin(tri.p1.angle+angul))+tri.centre.y;
|
||||||
y2:=round((tri.p2.r+velocitat/2)*sin(tri.p2.angle+angul+velocitat/10))+tri.centre.y;
|
y2:=round((tri.p2.r+velocitat)*sin(tri.p2.angle+angul{+velocitat/20}))+tri.centre.y;
|
||||||
y3:=round((tri.p3.r+velocitat/2)*sin(tri.p3.angle+angul-velocitat/10))+tri.centre.y;
|
y3:=round((tri.p3.r+velocitat)*sin(tri.p3.angle+angul{-velocitat/20}))+tri.centre.y;
|
||||||
linea(x1,y1,x2,y2,color);
|
rota_tri:=0;
|
||||||
linea(x1,y1,x3,y3,color);
|
if linea(x1,y1,x2,y2,color) then rota_tri:=1 ;
|
||||||
linea(x3,y3,x2,y2,color);
|
if linea(x1,y1,x3,y3,color) then rota_tri:=1;
|
||||||
|
if linea(x3,y3,x2,y2,color) then rota_tri:=1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure rota_pol(pol:poligon;angul:real;color:byte);
|
procedure rota_pol(pol:poligon;angul:real;color:byte);
|
||||||
@@ -252,24 +292,71 @@ begin
|
|||||||
orni.rotacio:=orni.rotacio+orni.drotacio;
|
orni.rotacio:=orni.rotacio+orni.drotacio;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure clsvirt;
|
procedure mou_bales(var orni:poligon);
|
||||||
var i:word;
|
var dx,dy:real;
|
||||||
begin
|
begin
|
||||||
for i:=1 to 38400 do mem[seg(virt^):i]:=0;
|
orni.angle:=orni.angle{+(random(256)/512)*(random(3)-1)};
|
||||||
|
Dy:=round(orni.velocitat*sin(orni.angle-pi/2))+orni.centre.y;
|
||||||
|
Dx:=round(orni.velocitat*cos(orni.angle-pi/2))+orni.centre.x;
|
||||||
|
if (dy>marge_dalt) and (dy<marge_baix) then
|
||||||
|
orni.centre.y:=round(Dy)
|
||||||
|
else {orni.angle:=orni.angle+(random(256)/512)*(random(3)-1)}orni.esta:=false;
|
||||||
|
|
||||||
|
if (dx>marge_esq) and (dx<marge_dret) then
|
||||||
|
orni.centre.x:=round(Dx)
|
||||||
|
else {orni.angle:=orni.angle+(random(256)/512)*(random(3)-1)}orni.esta:=false;;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var nau:triangle;pol:poligon;
|
var itocado:word;
|
||||||
ang:real;
|
chatarra_cosmica:poligon;
|
||||||
ch:char;
|
|
||||||
Dx,Dy:word;
|
procedure tocado;
|
||||||
i:byte;
|
var i,j,k:word;dx,dy:word;
|
||||||
dist:integer;
|
begin
|
||||||
puntaux:punt;
|
if itocado=1 then begin
|
||||||
orni:array [1..max_ornis] of poligon;
|
chatarra_cosmica.centre.x:=nau.centre.x;
|
||||||
|
chatarra_cosmica.centre.y:=nau.centre.y;
|
||||||
|
chatarra_cosmica.n:=max_ipunts;
|
||||||
|
for i:=0 to max_ipunts-1 do begin
|
||||||
|
chatarra_cosmica.ipuntx[i].r:=1;
|
||||||
|
chatarra_cosmica.ipuntx[i].angle:=random(360)*57.295779513;
|
||||||
|
end;
|
||||||
|
nau.velocitat:=0;
|
||||||
|
end;
|
||||||
|
if ((nau.p1.r>1) and (nau.p2.r>1)and (nau.p3.r>1)and (itocado<170)) then begin
|
||||||
|
nau.p1.r:=nau.p1.r-0.7;
|
||||||
|
nau.p2.r:=nau.p2.r-0.7;
|
||||||
|
nau.p3.r:=nau.p3.r-0.7;
|
||||||
|
nau.angle:=nau.angle-0.3;
|
||||||
|
rota_tri(nau,nau.angle,0,1);
|
||||||
|
end
|
||||||
|
else begin
|
||||||
|
for i:=0 to max_ipunts-1 do begin
|
||||||
|
chatarra_cosmica.ipuntx[i].r:=chatarra_cosmica.ipuntx[i].r+3;
|
||||||
|
dx:=round((chatarra_cosmica.ipuntx[i].r)*cos(chatarra_cosmica.ipuntx[i].angle))
|
||||||
|
+chatarra_cosmica.centre.x;
|
||||||
|
dy:=round((chatarra_cosmica.ipuntx[i].r)*sin(chatarra_cosmica.ipuntx[i].angle))
|
||||||
|
+chatarra_cosmica.centre.y;
|
||||||
|
if ((dx>=0)AND(dx<640)AND(dy>0)AND(dy<480))then posa(dx,dy,1);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
inc(itocado);
|
||||||
|
if itocado=170 then begin
|
||||||
|
nau.p1.r:=12;nau.p1.angle:=3*pi/2;
|
||||||
|
nau.p2.r:=12;nau.p2.angle:=pi/4;
|
||||||
|
nau.p3.r:=12;nau.p3.angle:=(3*pi)/4;
|
||||||
|
nau.angle:=0;
|
||||||
|
nau.centre.x:=320;nau.centre.y:=240;
|
||||||
|
end;
|
||||||
|
if ((itocado>170)and(itocado mod 3=0)) then rota_tri(nau,nau.angle,nau.velocitat,1);
|
||||||
|
if itocado>250 then itocado:=0;
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
randomize;
|
randomize;
|
||||||
getmem(virt,38400);
|
getmem(virt,38400);
|
||||||
|
itocado:=0;
|
||||||
clsvirt;
|
clsvirt;
|
||||||
nau.p1.r:=12;nau.p1.angle:=3*pi/2;
|
nau.p1.r:=12;nau.p1.angle:=3*pi/2;
|
||||||
nau.p2.r:=12;nau.p2.angle:=pi/4;
|
nau.p2.r:=12;nau.p2.angle:=pi/4;
|
||||||
@@ -279,19 +366,28 @@ begin
|
|||||||
crear_poligon_regular(pol,10,200);
|
crear_poligon_regular(pol,10,200);
|
||||||
for i:=1 to max_ornis do crear_poligon_regular(orni[i],5,20);
|
for i:=1 to max_ornis do crear_poligon_regular(orni[i],5,20);
|
||||||
mcga;
|
mcga;
|
||||||
initMouse;
|
|
||||||
rota_pol(pol,0,1);
|
rota_pol(pol,0,1);
|
||||||
instalarkb;
|
instalarkb;
|
||||||
repeat
|
repeat
|
||||||
hideMouseCursor;
|
|
||||||
showMouseCursor;
|
|
||||||
{ rota_tri(nau,nau.angle,nau.velocitat,0);}
|
{ rota_tri(nau,nau.angle,nau.velocitat,0);}
|
||||||
clsvirt;
|
clsvirt;
|
||||||
|
|
||||||
if teclapuls(KEYarrowright) then nau.angle:=nau.angle+0.157079632;
|
if teclapuls(KEYarrowright) then nau.angle:=nau.angle+0.157079632;
|
||||||
if teclapuls(KEYarrowleft) then nau.angle:=nau.angle-0.157079632;
|
if teclapuls(KEYarrowleft) then nau.angle:=nau.angle-0.157079632;
|
||||||
if teclapuls(KEYarrowup) then begin
|
if teclapuls(KEYarrowup) then begin
|
||||||
if nau.velocitat<6 then nau.velocitat:=nau.velocitat+0.2;
|
if nau.velocitat<velocitat_max then nau.velocitat:=nau.velocitat+0.2;
|
||||||
|
end;
|
||||||
|
if teclapuls(KEYspace)and(bales[1].esta=false) then begin
|
||||||
|
bales[1].esta:=true;
|
||||||
|
bales[1].centre.x:=nau.centre.x;
|
||||||
|
bales[1].centre.y:=nau.centre.y;
|
||||||
|
bales[1].n:=2;
|
||||||
|
bales[1].velocitat:=7;
|
||||||
|
bales[1].ipuntx[1].r:=10;
|
||||||
|
bales[1].ipuntx[1].angle:=pi/2+nau.angle;
|
||||||
|
bales[1].ipuntx[2].r:=20;
|
||||||
|
bales[1].ipuntx[2].angle:=pi/2+nau.angle;
|
||||||
|
bales[1].angle:=nau.angle;
|
||||||
end;
|
end;
|
||||||
Dy:=round(nau.velocitat*sin(nau.angle-pi/2))+nau.centre.y;
|
Dy:=round(nau.velocitat*sin(nau.angle-pi/2))+nau.centre.y;
|
||||||
Dx:=round(nau.velocitat*cos(nau.angle-pi/2))+nau.centre.x;
|
Dx:=round(nau.velocitat*cos(nau.angle-pi/2))+nau.centre.x;
|
||||||
@@ -308,7 +404,6 @@ begin
|
|||||||
nau.centre.y:=nau.centre.y
|
nau.centre.y:=nau.centre.y
|
||||||
+round(dist*sin(angle(puntaux)+0.031415));
|
+round(dist*sin(angle(puntaux)+0.031415));
|
||||||
end;}
|
end;}
|
||||||
rota_tri(nau,nau.angle,nau.velocitat,1);
|
|
||||||
{ for i:=1 to 5 do begin
|
{ for i:=1 to 5 do begin
|
||||||
rota_pol(orni[i],ang,0);
|
rota_pol(orni[i],ang,0);
|
||||||
end;}
|
end;}
|
||||||
@@ -316,12 +411,20 @@ begin
|
|||||||
mou_orni(orni[i]);
|
mou_orni(orni[i]);
|
||||||
rota_pol(orni[i],orni[i].rotacio,1);
|
rota_pol(orni[i],orni[i].rotacio,1);
|
||||||
end;
|
end;
|
||||||
|
if itocado=0 then aux:=rota_tri(nau,nau.angle,nau.velocitat,1)
|
||||||
|
else tocado;
|
||||||
|
if (aux=1) then begin inc(itocado);aux:=0;end;
|
||||||
|
if bales[1].esta then begin
|
||||||
|
mou_bales(bales[1]);
|
||||||
|
rota_pol(bales[1],0,1);
|
||||||
|
end;
|
||||||
waitretrace;
|
waitretrace;
|
||||||
volca;
|
volca;
|
||||||
|
{ if aux=1 then begin {gotoxy(0,0);write('tocado')tocado;delay(200);end;}
|
||||||
gotoxy(50,24);
|
gotoxy(50,24);
|
||||||
write('<27> Visente i Sergi');
|
write('<27> Visente i Sergi');
|
||||||
gotoxy(50,25);
|
gotoxy(50,25);
|
||||||
write('<27>ETA 1.0 1/6/99');
|
write('<27>ETA 2.2 2/6/99');
|
||||||
until teclapuls(keyesc);
|
until teclapuls(keyesc);
|
||||||
desinstalarkb;
|
desinstalarkb;
|
||||||
ang:=0;
|
ang:=0;
|
||||||
|
|||||||
Reference in New Issue
Block a user