Game bắn thiên thạch bằng pascal.

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,619
744
21
Phú Yên
Trường THPT Lương Văn Chánh
[TẶNG BẠN] TRỌN BỘ Bí kíp học tốt 08 môn
Chắc suất Đại học top - Giữ chỗ ngay!!

ĐĂNG BÀI NGAY để cùng trao đổi với các thành viên siêu nhiệt tình & dễ thương trên diễn đàn.

Mã:
uses crt,graph,dos;
var gd,gm,x,y,u,v,sao,x1,y1,u1,v1,tr:integer;
    x2,y2,u2,v2,x3,y3,u3,v3,diem,mnen:integer;
    p,p1,p2,p3,p4,p5:pointer;
    n:word;
    key,lastkey:char;
    dim:string[4];
    sx,sy,xx,yy,color,rd:array[1..500] of integer;
    trung,bum,cl:boolean;

const
 No: array[1..14] of PointType=
((x:0;y:440),
 (x:140;y:430),
 (x:250;y:420),
 (x:400;y:435),
 (x:450;y:424),
 (x:500;y:443),
 (x:525;y:437),
 (x:570;y:444),
 (x:600;y:430),
 (x:620;y:425),
 (x:640;y:440),
 (x:640;y:480),
 (x:0;y:480),
 (x:0;y:440));

procedure In_diem;
begin
SetTextStyle(0,HorizDir,2);
str(diem,dim);
SetColor(Yellow);
OutTextxy(1,2,'Diem: '+dim);
end;


procedure Tao_nen;
begin
For Sao:=1 to 500 do
begin
sx[sao]:=random(641);
sy[sao]:=random(461);
Color[sao]:=Random(16);
end;
For Sao:=1 to 100 do begin
Repeat
xx[sao]:=random(620);
yy[sao]:=Random(460);
Rd[sao]:=random(15);
until (yy[sao]>=440) and (rd[sao]>=-15);
                    end;
repeat mnen:=random(10);until (mnen<>2) and (mnen<>6) and (mnen<>1);
end;

procedure In_nen;
begin
for sao:=1 to 500 do
Putpixel(sx[sao],sy[sao],Color[sao]);
SetFillStyle(1,7);
SetColor(7);
FillPoly(14,no);
SetColor(Red);
for Sao:=1 to 50 do begin
Line(xx[sao],yy[sao],xx[sao]+rd[sao],yy[sao]+rd[sao]+2);
                    end;
In_diem;
end;

Procedure Bi_thuong;
begin
SetColor(Brown);
Line(0,0,20,0);
Line(20,0,32,15);
Line(32,15,25,25);
Line(25,25,13,20);
Line(13,20,0,0);
SetFillStyle(1,Brown);
FloodFill(15,7,Brown);
SetColor(Black);
Line(12,20,20,5);
Line(20,5,10,7);
Line(15,5,15,7);
Line(15,3,25,5);
Getmem(p3,Imagesize(0,0,32,25));
GetImage(0,0,32,25,p3^);
Line(15,15,20,23);
Line(20,17,30,14);
Line(18,10,22,12);
Line(15,18,18,20);
Getmem(p4,Imagesize(0,0,32,25));
GetImage(0,0,32,25,p4^);
ClearDevice;
end;

Procedure Thien_thach;
begin
SetColor(Brown);
Line(0,0,20,0);
Line(20,0,32,15);
Line(32,15,25,25);
Line(25,25,13,20);
Line(13,20,0,0);
SetFillStyle(1,Brown);
FloodFill(15,7,Brown);
Getmem(p2,Imagesize(0,0,32,25));
GetImage(0,0,32,25,p2^);
Cleardevice;
end;


Procedure Vien_dan;
begin
SetFillStyle(1,Red);
SetColor(Red);
FillEllipse(3,5,3,5);
Getmem(p1,Imagesize(0,0,6,10));
GetImage(0,0,6,10,p1^);
ClearDevice;
end;

procedure May_bay;
begin
setcolor(Blue);
line(x,y,x-10,y+25);
line(x-10,y+25,x-30,y+35);
line(x-30,y+35,x-30,y+30);
line(x-30,y+30,x-33,y+25);
line(x-33,y+25,x-36,y+30);
line(x-36,y+30,x-36,y+41);
line (x-36,y+41,x-30,y+41);
line(x-30,y+41,x-30,y+40);
line (x-30,y+40,x-20,y+40);
line (x-20,y+40,x-20,y+43);
line(x-20,y+43,x-5,y+43);
line(x-5,y+43,x-5,y+40);
line (x-5,y+40,x+5,y+40);
line(x+5,y+40,x+5,y+43);
line(x+5,y+43,x+20,y+43);
line(x+20,y+43,x+20,y+40);
line (x+20,y+40,x+30,y+40);
line(x+30,y+40,x+30,y+41);
line(x+30,y+41,x+36,y+41);
line(x+36,y+41,x+36,y+30);
line(x+35,y+30,x+33,y+25);
line (x+33,y+25,x+30,y+30);
line(x+30,y+30,x+30,y+35);
line (x+30,y+35,x+10,y+25);
line(x+10,y+25,x,y);
setfillstyle(1,Blue);
floodfill(x,y+15,Blue);
setfillstyle(1,Red);
Bar(x-10,y+28,x+10,y+38);
SetTextStyle(0,0,1);
SetColor(Cyan);
OutTextxy(x-10,y+29,'B52');
end;

procedure Noo;
var r:integer;
begin
r:=0;
repeat
Sound(400);
r:=r+10;
SetFillStyle(1,Brown);
PieSlice(x,y+40,180,0,r);
Delay(100);
if r=100 then
begin
Nosound;
SetTextstyle(0,HorizDir,5);
Setcolor(red);
Outtextxy(100,200,'GAME OVER');
SetTextStyle(1,HorizDir,1);
SetColor(Blue);
Sound(600);delay(500);
Sound(200);delay(500);
Sound(350);delay(500);
Sound(200);delay(500);
sound(600);delay(500);
sound(400);delay(700);
Nosound;
OutTextxy(200,300,'Bam Enter De Choi Lai');
repeat
if keypressed then key:=Readkey;
until (key=#27) or (key=#13);
if key=#13 then cl:=True else cl:=False;
end;
until r>=100;
end;

procedure Giao_dien;
begin
Vien_dan;
Thien_thach;
Tao_Nen;
{==========================================}
for sao:=1 to 500 do
Putpixel(sx[sao],sy[sao],Color[sao]);
SetFillStyle(1,7);
SetColor(7);
FillPoly(14,no);
SetColor(Red);
for Sao:=1 to 50 do begin
Line(xx[sao],yy[sao],xx[sao]+rd[sao],yy[sao]+rd[sao]+2);
                    end;
{==========================================} (* In nen*)
Settextstyle(0,horizdir,5);
SetColor(Cyan);
Outtextxy(100,200,'GAME');
SetColor(Green);
Outtextxy(300,200,'PLANE');
x:=290;y:=250;
May_bay;
PutImage(285,230,p1^,1);
PutImage(285,210,p1^,1);
PutImage(285,190,p1^,1);
PutImage(100,50,p2^,2);
PutImage(400,90,p2^,2);
PutImage(320,120,p2^,2);
Settextstyle(1,horizdir,10);
SetColor(Yellow);
Outtextxy(200,400,'Bam Enter De Bat Dau Choi');
Sound(200);delay(500);
Sound(300);delay(500);
Sound(400);delay(500);Nosound;
Readln;ClearDevice;
end;

Procedure Vo_thien_thach;
begin
SetFillStyle(1,Brown);
SetColor(Brown);
Line(x2-6,y2-6,x2,y2);
Line(x2,y2,x2-12,y2+8);
Line(x2-12,y2+8,x2-6,y2-6);
FloodFill(x2-6,y2,Brown);
Line(x2+15,y2-5,x2+23,y2-1);
Line(x2+23,y2-1,x2+23,y2+3);
Line(x2+23,y2+3,x2+11,y2+3);
Line(x2+11,y2+3,x2+15,y2-5);
FloodFill(x2+15,y2-1,Brown);
Line(x2,y2+13,x2+4,y2+25);
Line(x2+4,y2+25,x2,y2+25);
Line(x2,y2+25,x2-8,y2+21);
Line(x2-8,y2+21,x2,y2+13);
FloodFill(x2,y2+21,Brown);
Delay(20);
end;

BEGIN
gd:=VGA;gm:=VgaHi;
Initgraph(gd,gm,'');
repeat
Giao_dien;
Bum:=False;
Trung:=False;
diem:=0;
tr:=0;
Vien_dan;
Thien_thach;
Bi_thuong;
Tao_nen;In_nen;
x:=240;y:=405;
x2:=500;y2:=0;
n:=Imagesize(x-36,y,x+36,y+43);
getmem(p,n);
repeat
GetImage(x-36,y,x+36,y+43,p^);
setcolor(Blue);
line(x,y,x-10,y+25);
line(x-10,y+25,x-30,y+35);
line(x-30,y+35,x-30,y+30);
line(x-30,y+30,x-33,y+25);
line(x-33,y+25,x-36,y+30);
line(x-36,y+30,x-36,y+41);
line (x-36,y+41,x-30,y+41);
line(x-30,y+41,x-30,y+40);
line (x-30,y+40,x-20,y+40);
line (x-20,y+40,x-20,y+43);
line(x-20,y+43,x-5,y+43);
line(x-5,y+43,x-5,y+40);
line (x-5,y+40,x+5,y+40);
line(x+5,y+40,x+5,y+43);
line(x+5,y+43,x+20,y+43);
line(x+20,y+43,x+20,y+40);
line (x+20,y+40,x+30,y+40);
line(x+30,y+40,x+30,y+41);
line(x+30,y+41,x+36,y+41);
line(x+36,y+41,x+36,y+30);
line(x+35,y+30,x+33,y+25);
line (x+33,y+25,x+30,y+30);
line(x+30,y+30,x+30,y+35);
line (x+30,y+35,x+10,y+25);
line(x+10,y+25,x,y);
setfillstyle(1,Blue);
floodfill(x,y+15,Blue);
setfillstyle(1,Red);
Bar(x-10,y+28,x+10,y+38);
SetTextStyle(0,0,1);
SetColor(Cyan);
OutTextxy(x-10,y+29,'B52');
u:=x;v:=y;
Case tr of
0:putImage(x2,y2,p2^,1);
1:putImage(x2,y2,p3^,1);
2:putImage(x2,y2,p4^,1);
end;

u2:=x2;v2:=y2;
if keypressed then key:=readkey;
case key of
#27: cl:=False;
#77: if x<=570 then x:=x+15;
#75: if x>=60 then x:=x-15;
#72: begin
ClearDevice;In_nen;
PutImage(x-36,y,p^,3);
x1:=x-3;y1:=y-5;
repeat
putImage(x1,y1,p1^,1);
case tr of
0: PutImage(x2,y2,p2^,1);
1: PutImage(x2,y2,p3^,1);
2: PutImage(x2,y2,p4^,1);
end;
u2:=x2;v2:=y2;
u1:=x1;v1:=y1;
y1:=y1-10;
y2:=y2+7;
if tr=3 then begin
Vo_thien_thach;
trung:=true;diem:=diem+1;end;

if (y2+25>=y) or (tr=3) then repeat tr:=0;
x2:=random(600);y2:=0;until x2>=50;
delay(50);
PutImage(u1,v1,p1^,1);
Case tr of
0:putImage(u2,v2,p2^,1);
1:putImage(u2,v2,p3^,1);
2:putImage(u2,v2,p4^,1);
end;
if trung then begin ClearDevice;In_nen;May_bay;trung:=False;end;
May_bay;
if (y1<=y2+25) and (x1+6>=x2) and (x1<=x2+25) then begin
tr:=tr+1;
if tr<3 then Sound(300) else sound(500);delay(100);nosound;
ClearDevice;y1:=y-5;
In_nen;May_bay;
end;
if y1<=y2+25 then begin
ClearDevice;y1:=y-5;
In_nen;May_bay;
end;
until keypressed;
lastkey:=#72;
     end;
end;
y2:=y2+10;
if (y2+27>=y) and (x2+32>=x-36) and (x2<=x+36) and (tr<3) then bum:=true;
if (y2+25>=y) or (tr=3) then repeat x2:=random(600);
y2:=0;tr:=0;until x2>=50;
delay(50);
PutImage(u-36,v,p^,0);
case tr of
0:putImage(u2,v2,p2^,1);
1:putImage(u2,v2,p3^,1);
2:putImage(u2,v2,p4^,1);
end;
If lastkey=#72 then begin ClearDevice;In_nen;lastkey:=#0;end;
Until (key=#27) or bum;
if bum then begin ClearDevice;In_nen;Noo;end;
until not cl;
Closegraph;
END.
 
Last edited:

Vuio Dev

Banned
Banned
19 Tháng năm 2017
57
15
61
22
Chuyển lên dùng Lazarus (Object pascal đi bạn), học nhanh (tương tự pascal) nhưng làm game rất ok
 

kingsman(lht 2k2)

Mùa hè Hóa học|Ngày hè tuyệt diệu
Thành viên
TV BQT tích cực 2017

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,619
744
21
Phú Yên
Trường THPT Lương Văn Chánh
  • Like
Reactions: kingsman(lht 2k2)

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,619
744
21
Phú Yên
Trường THPT Lương Văn Chánh

kingsman(lht 2k2)

Mùa hè Hóa học|Ngày hè tuyệt diệu
Thành viên
TV BQT tích cực 2017
Bạn ơi lập trình game bằng j:r2:r2
nếu chưa bít dùng những ngôn ngữ lập trình khó như vậy hãy dùng những phần mềm như
unity (bom bá dc làm từ phần mềm này )
game maker ( có thể làm dc mario hay nhiều game đơn gian mà ko cần dùng đầu nhiều
 
  • Like
Reactions: Dragon_Ball_Z

kingsman(lht 2k2)

Mùa hè Hóa học|Ngày hè tuyệt diệu
Thành viên
TV BQT tích cực 2017
muốn lập rtrinhf máy tính có cần cài gì ko bạn
tham khảo các code game để dễ dàng tiếp cận ngôn ngữ lập trình
vd bạn muốn chỉnh map của game offline thì bạn phải có một chút kĩ năng tạo lập trình nhé ,,,,,,,,,,,,
 
Top Bottom