Advertisement
Zung_the_great

[Pascal] Flappy bird ?

Jul 6th, 2015
716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.31 KB | None | 0 0
  1. //WARNING: need additional files, can not run this program alone
  2. // you can find it in my site :)
  3. // flap flap
  4. // full file here :http://upfile.vn/uVjCu~XtxdFQ/flappy-bird-rar.html
  5. program project_flapy;
  6. uses crt;
  7. label loop;
  8. type int = integer;
  9.  
  10. var obj : string;
  11. f : text;
  12. x,y,n,score: int;
  13. kt,coin : boolean;
  14. col : array[1..9] of record
  15.  
  16. diadiem,dodai: int;
  17. end;
  18. bl : array[1..80,1..25]of shortint;
  19. ghost : shortint;
  20. increase,material : int;
  21.  
  22. k : char;
  23.  
  24. procedure readf;
  25. var c : int;
  26. begin
  27. assign(f,'data.dat'); reset(f);
  28. obj:='';
  29. while not eof(f) do
  30. begin
  31. read(f,c);
  32. obj:=obj+chr(c);
  33. end;
  34. close(f);
  35. fillchar(bl,sizeof(bl),0);
  36. end;
  37.  
  38. procedure drawrectangle(x,y:int; x1,y1:int; co1,co2:int);
  39. var i,j : int; //x1 la ngang dai y1 la doc
  40. c : char;
  41. begin
  42. c:=chr(material); textcolor(co1);
  43. gotoxy(x,y); bl[x,y]:=ghost;
  44. for i:=1 to x1-1 do begin bl[x+i,y]:=ghost; write(c);end;
  45. for j:=1 to y1-1 do begin gotoxy(x,y+j); bl[x,y+j]:=ghost; write(c); end;
  46. for j:=1 to y1 do begin gotoxy(x+x1-1,y+j-1); bl[x+x1-1,y+j-1]:=ghost; write(c); end;
  47. gotoxy(x,y+y1-1);
  48. bl[x,y+y1-1]:=ghost;
  49. for i:=1 to x1 do begin if i<>x1 then bl[x+i,y+y1-1]:=ghost; write(c); end;
  50. textcolor(co2);
  51. end;
  52.  
  53. procedure del(re:int);
  54. var i:int;
  55. begin
  56.  
  57. textcolor(7); textbackground(7);
  58. for i:=1 to 3 do write(chr(176));
  59. textcolor(re);
  60. end;
  61.  
  62. procedure delcol(i:int);
  63. begin
  64. textcolor(7); textbackground(7);
  65. drawrectangle(col[i].diadiem,1,15,col[i].dodai,7,19);
  66. drawrectangle(col[i].diadiem,col[i].dodai+7,15,26-col[i].dodai-7,7,19);
  67. end;
  68.  
  69. procedure print(re:int);
  70. var i : int;
  71. begin
  72. textcolor(green); write(obj[1]);
  73. textbackground(green); write(obj[2]);
  74. textcolor(black);
  75. gotoxy(wherex-1,wherey); write(obj[4]);
  76. textbackground(7);
  77. textcolor(yellow); write(obj[3]);
  78. textcolor(re);
  79. end;
  80.  
  81. procedure fill(co1,co2:int);
  82. var i,j : int;
  83. c : char;
  84. begin
  85.  
  86. textcolor(co1); textbackground(co1);
  87. for i:=1 to 25 do
  88. for j:=1 to 80 do write(c);
  89. textcolor(co2);
  90. end;
  91.  
  92. procedure tree(x:int; co1,co2:int);
  93. var c:char; h,i:int;
  94. begin
  95. randomize;
  96. textcolor(co1); c:=chr(219);
  97. repeat
  98. h:=random(6)+1;
  99. until (h>3);
  100. for i:=0 to h-1 do begin gotoxy(x,23-i); write(c); end;
  101. c:=chr(178);
  102. textcolor(co2);
  103. gotoxy(x-2,24-h); for i:=1 to 5 do write(c);
  104. gotoxy(x-1,23-h); for i:=1 to 3 do write(c);
  105. gotoxy(x-1,25-h); write(c);
  106. gotoxy(x+1,25-h); write(c);
  107. end;
  108.  
  109. procedure cloud(x,y:int);
  110. var i,j:int; c:char;
  111. l1,l2,l3:int;
  112. begin
  113.  
  114. randomize;
  115. repeat
  116. l1:=random(4)+1;
  117. l2:=random(6)+1;
  118. l3:=random(5)+1;
  119. until (l1>3)and(l2>l3)and(l3>3);
  120. textcolor(19);
  121. c:=chr(176);
  122. gotoxy(x+3,y); for i:=1 to l1 do write(c);
  123. c:=chr(177);
  124. gotoxy(x,y+1); for i:=1 to l2 do write(c);
  125. c:=chr(178);
  126. gotoxy(x+2,y+2); for i:=1 to l3 do write(c);
  127. end;
  128.  
  129.  
  130. procedure pipe(x:int);
  131. var h1, w1, s, h2:int;
  132. begin
  133. randomize;
  134. repeat
  135. h1:=random(15)+1;
  136. until h1>6;
  137. col[n].dodai:=h1;
  138. w1:=15; col[n].diadiem:=x;
  139. material:=219;
  140. drawrectangle(x,1,w1,h1,18,1);
  141.  
  142. h2:=h1+7;
  143.  
  144. drawrectangle(x,h2,w1,25-h2+1,18,1);
  145. material:=178;
  146. end;
  147.  
  148. procedure flap1(var x,y:int);
  149. var i,j:int; k:char;
  150. begin
  151. readkey;
  152. while (y<23)and(x<76)and(y>1)and(bl[x,y]<>1)and(bl[x+1,y]<>1)and(bl[x+2,y]<>1)and(kt)do
  153. begin
  154. gotoxy(x,y); print(3); delay(150); gotoxy(x,y); del(3);
  155. inc(y); inc(x);
  156. if (keypressed) then
  157. begin
  158. for j:=1 to 3 do
  159. begin
  160. gotoxy(x,y); print(3); delay(50); gotoxy(x,y); del(3);
  161.  
  162. if( (x in[16..31])or(x in[39..54])or(x in[61..76]) )and(coin=false)then
  163. begin
  164. inc(increase); textcolor(0);
  165. gotoxy(2,2); write(increase);
  166. coin:=true;
  167. end;
  168. if (x in[1..15])or(x in[32..38])or(x in[55..60])or(x in[77..80]) then coin:=false;
  169.  
  170. if (bl[x,y]=1)or(bl[x+1,y]=1)or(bl[x+2,y]=1)
  171. then begin kt:=false; exit; end;
  172. dec(y); inc(x);
  173. end;
  174. if kt then flap1(x,y);
  175. end;
  176.  
  177. end;
  178.  
  179. end;
  180.  
  181. procedure menu;
  182. var i,j : int;
  183. c : char;
  184. begin
  185. fill(7,1); material:=178;
  186.  
  187. drawrectangle(33,1,14,3,19,96);
  188. gotoxy(38,2); write('MENU');
  189. assign(f,'menu.dat'); reset(f);
  190. c:=chr(177);
  191. textcolor(6);
  192. repeat
  193. readln(f,i,j); gotoxy(i,j); write(c);
  194. until eof(f);
  195. close(f);
  196. assign(f,'sc.dat'); reset(f);
  197. readln(f,score);
  198. close(f);
  199. drawrectangle(65,13,13,4,4,96);
  200. gotoxy(66,14); write('Press space');
  201. drawrectangle(65,18,13,4,4,96);
  202. gotoxy(66,19); write('High score:');
  203. gotoxy(66,20); write(score);
  204. drawrectangle(66,23,11,3,19,0);
  205. gotoxy(67,24);write('LQRD team'); gotoxy(1,1);
  206. // // //
  207. repeat k:=readkey; until (k=' ')or(k=#27);
  208. end;
  209.  
  210. procedure loser;
  211. var k:char;
  212. begin
  213. //fill(19,0);
  214. drawrectangle(35,12,13,5,12,0);
  215. gotoxy(37,14); write('YOU LOSE !');
  216.  
  217. repeat k:=readkey; until k=' ';
  218. end;
  219. procedure play;
  220. var i, j : int; c:char;
  221. begin
  222.  
  223. fill(7,1);
  224. textcolor(4); textbackground(4); gotoxy(1,25);
  225. for i:=1 to 80 do write('c');
  226. gotoxy(1,23);
  227. c:=chr(178);
  228. textcolor(6); textbackground(7);
  229. for i:=1 to 80 do write(c);
  230. material:=177;
  231. drawrectangle(1,1,7,3,19,0);
  232. for i:=10 to 70 do if i mod 10=0 then cloud(i,1);
  233.  
  234. n:=1; ghost:=1; increase:=0; coin:=false;
  235. kt:=true; //U are alife;
  236. while kt do
  237. begin
  238.  
  239. x:=1; y:=15; gotoxy(x,y); print(19);
  240.  
  241. for i:=10 to 70 do if i mod 10=0 then tree(i,127,18);
  242.  
  243. pipe(16);inc(n); pipe(39);inc(n); pipe(61);
  244.  
  245. flap1(x,y);
  246.  
  247. if (y=25) or(y<=2)or(x<76) then begin kt:=false; ghost:=0; loser; end;
  248.  
  249. for i:=10 to 70 do if i mod 10=0 then tree(i,7,7);
  250.  
  251. ghost:=0; delcol(1); delcol(2); delcol(3); n:=1; ghost:=1; n:=1;
  252.  
  253. end;
  254.  
  255. if increase>=score then
  256. begin
  257. assign(f,'sc.dat'); rewrite(f);
  258. write(f,increase);
  259. close(f);
  260. end;
  261. end;
  262.  
  263. procedure loading;
  264. var i: int;
  265. begin
  266. fill(4,0);
  267. material:=219;
  268. drawrectangle(13,12,56,3,6,0);
  269. gotoxy(14,13);
  270. textcolor(3);
  271. for i:=1 to 54 do begin
  272. write(chr(178));
  273. if i mod 3=0 then delay(100);
  274. end;
  275. end;
  276.  
  277. begin
  278. clrscr;
  279. readf;
  280. repeat
  281. gotoxy(1,1); ghost:=0;
  282. menu;
  283. if k<>#27 then begin
  284. gotoxy(1,1);
  285. loading;
  286. gotoxy(1,1);
  287. play;
  288. end;
  289. until k=#27;
  290.  
  291. // encrypt
  292. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement