From cdfb966fc3381f180e09c2c955a7d59c306cb435 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Sat, 13 Aug 2022 10:41:21 +0200 Subject: [PATCH] BETA 2.01 --- ASTEROID.PAS | 141 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 105 insertions(+), 36 deletions(-) diff --git a/ASTEROID.PAS b/ASTEROID.PAS index 33632f9..97e1d3e 100755 --- a/ASTEROID.PAS +++ b/ASTEROID.PAS @@ -1,4 +1,4 @@ -uses mouse,crt,keyboard; +uses crt,keyboard,sencos; const marge_dalt=20; @@ -7,6 +7,8 @@ const marge_dret=620; max_ipunts=30; max_ornis=15; + velocitat=2; + velocitat_max=6; type ipunt=RECORD r,angle:real; END; punt=RECORD x,y:integer; END; @@ -28,7 +30,15 @@ type 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; procedure volca; var i:word; @@ -49,9 +59,9 @@ begin act:=act + interval; end; pol.centre.x:=320; - pol.centre.y:=240; + pol.centre.y:=200; pol.angle:=0; - pol.velocitat:=2; + pol.velocitat:=velocitat; pol.n:=n; pol.drotacio:=0.078539816; pol.rotacio:=0; @@ -118,6 +128,21 @@ begin 7:mem[seg(virt^):y*80+(x div 8)]:=(mem[seg(virt^):y*80+(x div 8)]AND $FE); 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); begin if color=1 then @@ -166,21 +191,29 @@ begin if p.y<>0 then angle:=arctan(p.x/p.y); 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} begin if x<0 then sign:=-1 else if x>0 then sign:=1 else sign:=0 end; var - x,y,count,xs,ys,xm,ym:integer; + x,y,count,xs,ys,xm,ym,col:integer; begin + linea:=false; + col:=0; x:=x1;y:=y1; xs:=x2-x1; ys:=y2-y1; xm:=sign(xs); ym:=sign(ys); xs:=abs(xs); ys:=abs(ys); - + if llig(x,y)=1 then inc(col); posa(x,y,color); if xs > ys @@ -193,6 +226,7 @@ procedure linea(x1,y1,x2,y2,color:word); y:=y+ym; count:=count-xs; end; + if llig(x,y)=1 then inc(col); posa(x,y,color); end; end @@ -205,23 +239,26 @@ procedure linea(x1,y1,x2,y2,color:word); x:=x+xm; count:=count-ys; end; + if llig(x,y)=1 then inc(col); posa(x,y,color); end; end; + if col>2 then linea:=true; 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; begin - x1:=round((tri.p1.r+velocitat/2)*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; - x3:=round((tri.p3.r+velocitat/2)*cos(tri.p3.angle+angul-velocitat/10))+tri.centre.x; - y1:=round((tri.p1.r+velocitat/2)*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; - y3:=round((tri.p3.r+velocitat/2)*sin(tri.p3.angle+angul-velocitat/10))+tri.centre.y; - linea(x1,y1,x2,y2,color); - linea(x1,y1,x3,y3,color); - linea(x3,y3,x2,y2,color); + x1:=round((tri.p1.r+velocitat)*cos(tri.p1.angle+angul))+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)*cos(tri.p3.angle+angul{-velocitat/20}))+tri.centre.x; + y1:=round((tri.p1.r+velocitat)*sin(tri.p1.angle+angul))+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)*sin(tri.p3.angle+angul{-velocitat/20}))+tri.centre.y; + rota_tri:=0; + if linea(x1,y1,x2,y2,color) then rota_tri:=1 ; + if linea(x1,y1,x3,y3,color) then rota_tri:=1; + if linea(x3,y3,x2,y2,color) then rota_tri:=1; end; procedure rota_pol(pol:poligon;angul:real;color:byte); @@ -252,24 +289,56 @@ begin orni.rotacio:=orni.rotacio+orni.drotacio; end; -procedure clsvirt; -var i:word; -begin - for i:=1 to 38400 do mem[seg(virt^):i]:=0; -end; +var itocado:word; + chatarra_cosmica:poligon; -var nau:triangle;pol:poligon; - ang:real; - ch:char; - Dx,Dy:word; - i:byte; - dist:integer; - puntaux:punt; - orni:array [1..max_ornis] of poligon; +procedure tocado; +var i,j,k:word;dx,dy:word; +begin + if itocado=1 then begin + 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 randomize; getmem(virt,38400); + itocado:=0; clsvirt; nau.p1.r:=12;nau.p1.angle:=3*pi/2; nau.p2.r:=12;nau.p2.angle:=pi/4; @@ -279,19 +348,16 @@ begin crear_poligon_regular(pol,10,200); for i:=1 to max_ornis do crear_poligon_regular(orni[i],5,20); mcga; - initMouse; rota_pol(pol,0,1); instalarkb; repeat - hideMouseCursor; - showMouseCursor; { rota_tri(nau,nau.angle,nau.velocitat,0);} clsvirt; if teclapuls(KEYarrowright) then nau.angle:=nau.angle+0.157079632; if teclapuls(KEYarrowleft) then nau.angle:=nau.angle-0.157079632; if teclapuls(KEYarrowup) then begin - if nau.velocitat<6 then nau.velocitat:=nau.velocitat+0.2; + if nau.velocitat