Advertisement
Golden_Rus

fucking awesome game

Jan 14th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.77 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, ExtCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Image1: TImage;
  12.     Timer1: TTimer;
  13.     procedure FormCreate(Sender: TObject);
  14.     procedure FormKeyDown(Sender: TObject; var Key: Word;
  15.       Shift: TShiftState);
  16.     procedure Timer1Timer(Sender: TObject);
  17.   private
  18.     { Private declarations }
  19.   public
  20.     { Public declarations }
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.   texture: array [0..7] of TBitmap;
  26.   map: array [0..25, 0..25] of integer;
  27.   persPosX, persPosY, rotation: integer;
  28.   IsFire:boolean;
  29.   bollX, bollY, bollRot:integer;
  30. implementation
  31.  
  32. {$R *.dfm}
  33. procedure readMap();
  34. var
  35.   f: text;
  36.   i, j: integer;
  37. begin
  38.   AssignFile(f, 'res/map.txt');
  39.   Reset(f);
  40.   Read(f, persPosX);
  41.   Read(f, persPosY);
  42.   ReadLn(f);
  43.   i := 0;
  44.   while not Eof(f) do begin
  45.     j := 0;
  46.     while not Eoln(f) do begin
  47.       Read(f, map[j, i]);
  48.       Inc(j);
  49.     end;
  50.     ReadLn(f);
  51.     Inc(i);
  52.   end;
  53.   CloseFile(f);
  54. end;
  55.  
  56. procedure drawPers(x, y, rot: integer);//rot= 1-left, 2-right, 3-up, 4-down
  57. begin
  58. Form1.Image1.Canvas.Draw(x*20, y*20, texture[rot+1]);
  59. end;
  60.  
  61. procedure drawMap();
  62. var x, y:integer;
  63. begin
  64. for x:=0 to Form1.Image1.Height div 20 do
  65. for y:=0 to Form1.Image1.Width div 20 do
  66. begin
  67. Form1.Image1.Canvas.Draw(x*20, y*20, texture[map[x, y]]);
  68. end
  69. end;
  70.  
  71. procedure drawBoll(x, y: integer);
  72. begin
  73. Form1.Image1.Canvas.Draw(x*20, y*20, texture[6]);
  74. end;
  75.  
  76. procedure drawExp(x, y: integer);
  77. begin
  78. Form1.Image1.Canvas.Draw(x*20, y*20, texture[7]);
  79. end;
  80.  
  81. function Valid(dir:integer):boolean;  //dir= 1-left, 2-right, 3-up, 4-down
  82. begin
  83. if dir = 1 then
  84.   if persPosX>0 then
  85.     if map[persPosX-1, persPosY] = 0 then
  86.       Result:=true
  87.     else
  88.     Result:=false;
  89. if dir = 2 then
  90.   if persPosX<25 then
  91.     if map[persPosX+1, persPosY] = 0 then
  92.       Result:=true
  93.     else
  94.     Result:=false;
  95. if dir = 3 then
  96.   if persPosY>0 then
  97.     if map[persPosX, persPosY-1] = 0 then
  98.       Result:=true
  99.     else
  100.     Result:=false;
  101. if dir = 4 then
  102.   if persPosY<25 then
  103.     if map[persPosX, persPosY+1] = 0 then
  104.       Result:=true
  105.     else
  106.     Result:=false;
  107. end;
  108.  
  109. procedure explosive();
  110. begin
  111. IsFire:=false;
  112. if bollRot = 1 then
  113. begin
  114. drawExp(bollX-1, bollY);
  115. map[bollX-1, bollY]:=0;
  116. end;
  117. if bollRot = 2 then
  118. begin
  119. drawExp(bollX+1, bollY);
  120. map[bollX+1, bollY]:=0;
  121. end;
  122. if bollRot = 3 then
  123. begin
  124. drawExp(bollX, bollY-1);
  125. map[bollX, bollY-1]:=0;
  126. end;
  127. if bollRot = 4 then
  128. begin
  129. drawExp(bollX, bollY+1);
  130. map[bollX, bollY+1]:=0;
  131. end;
  132. end;
  133.  
  134. procedure fire();
  135. begin
  136. if not IsFire then
  137. begin
  138. IsFire:=true;
  139. bollRot:=rotation;
  140. bollX:=persPosX;
  141. bollY:=persPosY;
  142. drawBoll(bollX, bollY);
  143. end;
  144. end;
  145.  
  146.  
  147.  
  148.  
  149. procedure TForm1.FormCreate(Sender: TObject);
  150. var x, y:integer;
  151. begin
  152. IsFire:=false;
  153.  
  154. texture[1]:=TBitmap.Create;     //gnd texture
  155. texture[0]:=TBitmap.Create;    //white texture
  156. texture[2]:=TBitmap.Create;   //persL
  157. texture[3]:=TBitmap.Create;   //persR
  158. texture[4]:=TBitmap.Create;   //persU
  159. texture[5]:=TBitmap.Create;   //persD
  160. texture[6]:=TBitmap.Create;   //boll
  161. texture[7]:=TBitmap.Create;   //explosive
  162.  
  163. texture[1].LoadFromFile('res/ground.bmp');
  164. texture[0].LoadFromFile('res/null.bmp');
  165. texture[2].LoadFromFile('res/persL.bmp');
  166. texture[3].LoadFromFile('res/persR.bmp');
  167. texture[4].LoadFromFile('res/persU.bmp');
  168. texture[5].LoadFromFile('res/persD.bmp');
  169. texture[6].LoadFromFile('res/boll.bmp');
  170. texture[7].LoadFromFile('res/explosive.bmp');
  171.  
  172. readMap();
  173. drawMap();
  174. drawPers(persPosX, persPosY, 2);
  175. end;
  176.  
  177. procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  178.   Shift: TShiftState);
  179. begin
  180. if key = 37 then
  181. begin
  182. rotation:=1;
  183.   if Valid(1) then
  184.     persPosX:=persPosX-1;
  185. end;
  186. if key = 39 then
  187. begin
  188. rotation:=2;
  189.   if Valid(2) then
  190.     inc(persPosX);
  191. end;
  192. if key = 38 then
  193. begin
  194. rotation:=3;
  195.   if Valid(3) then
  196.     persPosY:=persPosY-1;
  197. end;
  198. if key = 40 then
  199. begin
  200. rotation:=4;
  201.   if Valid(4) then
  202.     inc(persPosY);
  203. end;
  204. if key = 32 then fire();
  205. drawMap();
  206. drawPers(persPosX, persPosY, rotation);
  207. end;
  208.  
  209. procedure TForm1.Timer1Timer(Sender: TObject);
  210. begin
  211. if IsFire then
  212. begin
  213. drawMap();
  214. drawBoll(bollX, bollY);
  215. drawPers(persPosX, persPosY, rotation);
  216.   if bollRot = 1 then
  217.   if bollX>0 then
  218.   begin
  219.     if map[bollX-1, bollY] = 0 then
  220.       bollX:=bollX-1
  221.       else
  222.         explosive();
  223.   end
  224.   else
  225.     explosive();
  226.  
  227.   if bollRot = 2 then
  228.   if bollX<25 then
  229.   begin
  230.     if map[bollX+1, bollY] = 0 then
  231.       bollX:=bollX+1
  232.       else
  233.         explosive();
  234.   end
  235.   else
  236.     explosive();
  237.  
  238.   if bollRot = 3 then
  239.   if bollY>0 then
  240.   begin
  241.     if map[bollX, bollY-1] = 0 then
  242.       bollY:=bollY-1
  243.       else
  244.         explosive();
  245.   end
  246.   else
  247.     explosive();
  248.  
  249.   if bollRot = 4 then
  250.   if bollY<25 then
  251.   begin
  252.     if map[bollX, bollY+1] = 0 then
  253.       bollY:=bollY+1
  254.       else
  255.         explosive();
  256.   end
  257.   else
  258.     explosive();
  259.  
  260. end else begin
  261. drawMap();
  262. drawPers(persPosX, persPosY, rotation);
  263. end;
  264. end;
  265.  
  266. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement