Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.24 KB | None | 0 0
  1. Program life;
  2. uses GraphABC;
  3.  
  4. type TMatrix = array of array of integer;
  5. type TColors = array of array of Color;
  6. type TNames = array[0..140] of String;
  7. var sizeEnt:integer;
  8. type list = ^s;
  9. s = record
  10.  
  11. x, y,
  12. age : integer;
  13. name : string;
  14. dead : boolean;
  15. col : Color;
  16.  
  17. next : list;
  18.  
  19. procedure create(i, j: integer; n: string; c: Color);
  20. begin
  21. x:= i;
  22. y:= j;
  23. name:= n;
  24. age:= 0;
  25. col:= c;
  26. dead:= false;
  27. end;
  28.  
  29. procedure createFlower(i, j: integer; c: Color);
  30. begin
  31. x:= i;
  32. y:= j;
  33. age:= 0;
  34. col:= c;
  35. dead:= false;
  36. end;
  37.  
  38. function update(width, height: integer; var l, f: list; names: TNames):list;
  39. begin
  40. if NOT(dead) then begin
  41. inc(age);
  42. dead:= (0 = Random(round(4000 / age))) AND (age > 50);
  43. var count:= 0;
  44. repeat
  45. inc(count);
  46. x:= x + Random(3) - 1;
  47. y:= y + Random(3) - 1;
  48. if x < 0 then
  49. x:= 0;
  50. if x > width then
  51. x:= width;
  52. if y < 0 then
  53. y:= 0;
  54. if y > height then
  55. y:= height;
  56. until (l^.existing(x, y, l)) AND (count > 5);
  57. update:= l;
  58. if l^.existing(x, y, f) then begin
  59. removeOfCoord(x, y, f);
  60. var dx: list;
  61. new(dx);
  62. dx^.create(x, y, names[Random(141)], l^.col);
  63. dx^.next:= l;
  64. update:= dx;
  65. end;
  66. {
  67. TextOut(min(WindowWidth, WindowHeight) + 280, 50 + sizeEnt * 20);
  68. sizeEnt:= sizeEnt + 1;
  69. }
  70. end;
  71. end;
  72.  
  73. function existing(x, y: integer; l:list):boolean;
  74. var dx:list;
  75. var e:boolean;
  76. begin
  77. dx:= l;
  78. e:= false;
  79. while dx <> nil do begin
  80. e:= e OR ((dx^.x = x) AND (dx^.y = y));
  81. dx:= dx^.next;
  82. end;
  83. existing:= e;
  84. end;
  85.  
  86. function updateFlower(width, height: integer; l, e: list; mrx: TMatrix):list;
  87. begin
  88. if NOT(dead) then begin
  89. inc(age);
  90. dead:= (0 = Random(round(20 / age))) AND (age > 6);
  91. updateFlower:= l;
  92. var count: integer;
  93. if age mod 5 = 0 then begin
  94. var i, j:integer;
  95. count:= 0;
  96. repeat
  97. count:= count + 1;
  98. i:= x + Random(11) - 5;
  99. j:= y + Random(11) - 5;
  100. until ((i < 0) OR (i > width) OR (j < 0) OR (j > height) OR ((x = i) AND (j = y)) OR NOT existing(i, j, l) OR NOT existing(i, j, e) OR (mrx[i, j] < 600) OR (mrx[i, j] > 1000)) AND (count > 2);
  101. if (count < 4) AND (i > -1) AND (i < width) AND (j > -1) AND (j < height) AND NOT ((x = i) AND (j = y)) AND NOT existing(i, j, l) AND NOT existing(i, j, e) then begin
  102. if ((mrx[i, j] > 600) AND (mrx[i, j] < 1000)) then begin
  103. var x: list;
  104. new(x);
  105. x^.createFlower(i, j, l^.col);
  106. x^.next:= l;
  107. updateFlower:= x;
  108. end;
  109. end;
  110. end;
  111. end;
  112. end;
  113.  
  114. procedure draw(SCALE, up, right: integer);
  115. begin
  116. var i:= y * SCALE;
  117. var j:= x * SCALE;
  118. if (i + up > -1) AND
  119. (j + right > -1) AND
  120. (j + right + SCALE < min(WindowHeight, WindowWidth) + 1) AND
  121. (i + up + SCALE < min(WindowHeight, WindowWidth) + 1) then begin
  122. SetPenColor(col);
  123. if SCALE > 1 then begin
  124. SetBrushColor(col);
  125. SetBrushStyle(bsSolid);
  126. Rectangle(j + right, i + up, j + right + SCALE - 1, i + up + SCALE - 1);
  127. end else
  128. SetPixel(j + right, i + up, col);
  129. end;
  130. end;
  131.  
  132. function inform:string;
  133. begin
  134. inform:= name + ' - age: ' + age + ' x: ' + x + ' y: ' + y;
  135. end;
  136.  
  137. function informFlower:string;
  138. begin
  139. informFlower:= ('Flower - age: ' + age + ' x: ' + x + ' y: ' + y);
  140. end;
  141.  
  142. function add(l:list):list;
  143. var x: list;
  144. begin
  145. new(x);
  146. x^.next:= l;
  147. add:= x;
  148. end;
  149.  
  150. function remove(var l:list):list;
  151. var x, dx:list;
  152. begin
  153. x:= l;
  154. while (x <> nil) AND NOT (x^.dead) do begin
  155. dx:= x;
  156. x:= x^.next;
  157. end;
  158. if x <> nil then begin
  159. dx^.next:= x^.next;
  160. dispose(x);
  161. end;
  162. end;
  163.  
  164. function removeOfCoord(i, j: integer; var l:list):list;
  165. var x, dx:list;
  166. begin
  167. x:= l;
  168. if (l <> nil) AND ((l^.x = i) AND (l^.y = j)) then begin
  169. l:= l^.next;
  170. dispose(x);
  171. end;
  172. while (x <> nil) AND NOT ((x^.x = i) AND (x^.y = j)) do begin
  173. dx:= x;
  174. x:= x^.next;
  175. end;
  176. if x <> nil then begin
  177. if (x^.next <> nil) then
  178. dx^.next:= x^.next
  179. else
  180. dx^.next:= nil;
  181. dispose(x);
  182. x:= dx^.next;
  183. end;
  184. end;
  185.  
  186. function removeAll(var l:list):list;
  187. var x, dx:list;
  188. begin
  189. x:= l;
  190. if (l <> nil) AND (l^.dead) then begin
  191. l:= l^.next;
  192. dispose(x);
  193. end;
  194. while x <> nil do begin
  195. while (x <> nil) AND NOT (x^.dead) do begin
  196. dx:= x;
  197. x:= x^.next;
  198. end;
  199. if x <> nil then begin
  200. if x^.next <> nil then
  201. dx^.next:= x^.next
  202. else
  203. dx^.next:= nil;
  204. dispose(x);
  205. x:= dx^.next;
  206. end;
  207. end;
  208. end;
  209.  
  210. procedure removeEverything(l:list);
  211. var x:list;
  212. begin
  213. while l<>nil do begin
  214. x:= l;
  215. l:= l^.next;
  216. dispose(x);
  217. end;
  218. end;
  219. end;
  220.  
  221. var
  222. matrix : TMatrix;
  223. colors : TColors;
  224. entities : list;
  225. flowers : list;
  226. names: TNames;
  227. maxFPS:= 15;
  228. SCALE,
  229. WINDOW_W,
  230. WINDOW_H,
  231. WIDTH,
  232. HEIGHT,
  233. up,
  234. right,
  235. changeHeight,
  236. minHeight,
  237. maxHeight,
  238. reading,
  239. antiAlias,
  240. speed,
  241. mode: integer;
  242. fps,
  243. readed: real;
  244. pause,
  245. isWorking: boolean;
  246.  
  247. procedure initNames;
  248. begin
  249. names[0]:= 'Aaron';
  250. names[1]:= 'Abraham';
  251. names[2]:= 'Adam';
  252. names[3]:= 'Adrian';
  253. names[4]:= 'Aidan';
  254. names[5]:= 'Alan';
  255. names[6]:= 'Albert';
  256. names[7]:= 'Alejandro';
  257. names[8]:= 'Alex';
  258. names[9]:= 'Alexander';
  259. names[10]:= 'Alfred';
  260. names[11]:= 'Andrew';
  261. names[12]:= 'Ashley';
  262. names[13]:= 'Benjamin';
  263. names[14]:= 'Bernard';
  264. names[15]:= 'Blake';
  265. names[16]:= 'Brandon';
  266. names[17]:= 'Brian';
  267. names[18]:= 'Bruce';
  268. names[19]:= 'Bryan';
  269. names[20]:= 'Bailey';
  270. names[21]:= 'Barbara';
  271. names[22]:= 'Beatrice';
  272. names[23]:= 'Belinda';
  273. names[24]:= 'Brianna';
  274. names[25]:= 'Bridjet';
  275. names[26]:= 'Brooke';
  276. names[27]:= 'Cameron';
  277. names[28]:= 'Carl';
  278. names[29]:= 'Carlos';
  279. names[30]:= 'Charles';
  280. names[31]:= 'Christopher';
  281. names[32]:= 'Daniel';
  282. names[33]:= 'David';
  283. names[34]:= 'Dennis';
  284. names[35]:= 'Diana';
  285. names[36]:= 'Dorothy';
  286. names[37]:= 'Edward';
  287. names[38]:= 'Elijah';
  288. names[39]:= 'Eric';
  289. names[40]:= 'Ethan';
  290. names[41]:= 'Evan';
  291. names[42]:= 'Elizabeth';
  292. names[43]:= 'Ella';
  293. names[44]:= 'Emily';
  294. names[45]:= 'Emma';
  295. names[46]:= 'Erin';
  296. names[47]:= 'Evelyn';
  297. names[48]:= 'Francis';
  298. names[49]:= 'Fred';
  299. names[50]:= 'Fiona';
  300. names[51]:= 'Florence';
  301. names[52]:= 'Freda';
  302. names[53]:= 'Gabriel';
  303. names[54]:= 'Gavin';
  304. names[55]:= 'Geoffrey';
  305. names[56]:= 'George';
  306. names[57]:= 'Gerld';
  307. names[58]:= 'Gilbert';
  308. names[59]:= 'Gordon';
  309. names[60]:= 'Graham';
  310. names[61]:= 'Gregory';
  311. names[62]:= 'Gloria';
  312. names[63]:= 'Gabriella';
  313. names[64]:= 'Gabrielle';
  314. names[65]:= 'Gladys';
  315. names[66]:= 'Grace';
  316. names[67]:= 'Harold';
  317. names[68]:= 'Harry';
  318. names[69]:= 'Helen';
  319. names[70]:= 'Ian';
  320. names[71]:= 'Isaac';
  321. names[72]:= 'Isaiah';
  322. names[73]:= 'Jake';
  323. names[74]:= 'James';
  324. names[75]:= 'Jason';
  325. names[76]:= 'Jayden';
  326. names[77]:= 'Jeffery';
  327. names[78]:= 'Jeremiah';
  328. names[79]:= 'Jesse';
  329. names[80]:= 'Jesus';
  330. names[81]:= 'John';
  331. names[82]:= 'Julia';
  332. names[83]:= 'Keith';
  333. names[84]:= 'Kevin';
  334. names[85]:= 'Kyle';
  335. names[86]:= 'Katelyn';
  336. names[87]:= 'Katherine';
  337. names[88]:= 'Kathryn';
  338. names[89]:= 'Kayla';
  339. names[90]:= 'Kaylee';
  340. names[91]:= 'Kimberly';
  341. names[92]:= 'Kylie';
  342. names[93]:= 'Landon';
  343. names[94]:= 'Lawrence';
  344. names[95]:= 'Leonars';
  345. names[96]:= 'Lewis';
  346. names[97]:= 'Logan';
  347. names[98]:= 'Louis';
  348. names[99]:= 'Lucas';
  349. names[100]:= 'Luke ';
  350. names[101]:= 'Laura';
  351. names[102]:= 'Lillian';
  352. names[103]:= 'Lily';
  353. names[104]:= 'Linda';
  354. names[105]:= 'Lorna';
  355. names[106]:= 'Luccile';
  356. names[107]:= 'Lucy';
  357. names[108]:= 'Lynn';
  358. names[109]:= 'Malcolm';
  359. names[110]:= 'Martin';
  360. names[111]:= 'Mason';
  361. names[112]:= 'Matthew';
  362. names[113]:= 'Michael';
  363. names[114]:= 'Maria';
  364. names[115]:= 'Molly';
  365. names[116]:= 'Peter';
  366. names[117]:= 'Philip';
  367. names[118]:= 'Pamela';
  368. names[119]:= 'Ryan ';
  369. names[120]:= 'Rachel';
  370. names[121]:= 'Rebecca';
  371. names[122]:= 'Riley';
  372. names[123]:= 'Rita';
  373. names[124]:= 'Simon';
  374. names[125]:= 'Stanley';
  375. names[126]:= 'Steven';
  376. names[127]:= 'Tyler';
  377. names[128]:= 'Taylor';
  378. names[129]:= 'Trinity';
  379. names[130]:= 'Victoria';
  380. names[131]:= 'Violet';
  381. names[132]:= 'Virginia';
  382. names[133]:= 'Wallace';
  383. names[134]:= 'Walter';
  384. names[135]:= 'William';
  385. names[136]:= 'Wyatt';
  386. names[137]:= 'Xavier';
  387. names[138]:= 'Yvonne';
  388. names[139]:= 'Zachary';
  389. names[140]:= 'Romeo';
  390. end;
  391.  
  392. procedure fillMatrix(lu, ru, ld, rd, n: real; k, l: integer);
  393. var c, cu, cl, cr, cd: real;
  394. var len, ran: integer;
  395. begin
  396. len:= round(n / 2);
  397. ran:= round(n / WIDTH * 500);
  398.  
  399. c:= Random(ran) - ran / 2 + ((lu + ru + ld + rd) / 4);
  400. cu:= Random(ran) - ran / 2 + ((lu + ru + c) / 3);
  401. cl:= Random(ran) - ran / 2 + ((lu + ld + c) / 3);
  402. cr:= Random(ran) - ran / 2 + ((ru + rd + c) / 3);
  403. cd:= Random(ran) - ran / 2 + ((ld + rd + c) / 3);
  404.  
  405. matrix[k + len, l + len]:= round(c);
  406. matrix[k, l + len]:= round(cu);
  407. matrix[k + len, l]:= round(cl);
  408. matrix[k + len, l + round(n)]:= round(cr);
  409. matrix[k + round(n), l + len]:= round(cd);
  410.  
  411. if n > 2 then begin
  412. fillMatrix(lu, cu, cl, c, len, k, l);
  413. fillMatrix(cu, ru, c, rd, len, k, l + len);
  414. fillMatrix(cl, c, ld, cd, len, k + len, l);
  415. fillMatrix(c, cr, cd, rd, len, k + len, l + len);
  416. end;
  417. end;
  418.  
  419. procedure passFl(x: integer;l:list);
  420. var y:integer;
  421. begin
  422. y:= 50;
  423. while l <> nil do begin
  424. TextOut(x + 280, y, l^.informFlower);
  425. l:= l^.next;
  426. y:= y + 20;
  427. end;
  428. end;
  429.  
  430. procedure updateEnt(l:list);
  431. begin
  432. while l <> nil do begin
  433. entities:= l^.update(WIDTH, HEIGHT, entities, flowers, names);
  434. l:= l^.next;
  435. end;
  436. end;
  437.  
  438. procedure updateFl(l:list);
  439. begin
  440. while l <> nil do begin
  441. flowers:= l^.updateFlower(WIDTH, HEIGHT, flowers, entities, matrix);
  442. l:= l^.next;
  443. end;
  444. end;
  445.  
  446. procedure drawEnt(l:list);
  447. begin
  448. while l <> nil do begin
  449. l^.draw(SCALE, up, right);
  450. l:= l^.next;
  451. end;
  452. end;
  453.  
  454. procedure setPause(p: boolean);
  455. begin
  456. pause:= p;
  457. if pause then
  458. SetWindowTitle('PAUSE');
  459. end;
  460.  
  461. procedure maxFPSdown();
  462. begin
  463. if maxFPS > 1 then
  464. maxFPS:= maxFPS - 1
  465. else begin
  466. setPause(true);
  467. maxFPS:= 0;
  468. end;
  469. end;
  470.  
  471. procedure maxFPSup();
  472. begin
  473. maxFPS:= maxFPS + 1;
  474. if pause then setPause(false);
  475. end;
  476.  
  477. procedure movement(step: integer; var vec: integer);
  478. begin
  479. vec:= vec + step;
  480. end;
  481.  
  482. procedure toCenter();
  483. var offset: integer;
  484. begin
  485. up:= 0;
  486. right:= 0;
  487. offset:= round((min(WindowWidth, WindowHeight) - WINDOW_W) / 2);
  488. movement(offset, up);
  489. movement(offset, right);
  490. end;
  491.  
  492. procedure setScale(s: integer);
  493. var running: boolean;
  494. begin
  495. if s > 0 then begin
  496. running:= true;
  497. while running do
  498. if NOT(isWorking) then begin
  499. SCALE:= s;
  500. WINDOW_W:= SCALE * WIDTH;
  501. WINDOW_H:= SCALE * HEIGHT;
  502. running:= false;
  503. end;
  504. end;
  505. end;
  506.  
  507. procedure initEnvironment();
  508. var i: integer;
  509. begin
  510. antiAlias:= 0;
  511. SetLength(matrix, WIDTH + 1);
  512. SetLength(colors, WIDTH);
  513. for i:= 0 to WIDTH - 1 do begin
  514. SetLength(matrix[i], WIDTH + 1);
  515. SetLength(colors[i], WIDTH);
  516. end;
  517. SetLength(matrix[WIDTH], WIDTH + 1);
  518.  
  519. matrix[0, 0]:= Random(1500);
  520. matrix[0, WIDTH]:= Random(1500);
  521. matrix[HEIGHT, 0]:= Random(1500);
  522. matrix[HEIGHT, WIDTH]:= Random(1500);
  523.  
  524. fillMatrix(matrix[0, 0],
  525. matrix[0, WIDTH],
  526. matrix[HEIGHT, 0],
  527. matrix[HEIGHT, WIDTH],
  528. WIDTH, 0, 0);
  529.  
  530. setScale(1);
  531. toCenter();
  532. end;
  533.  
  534. procedure smooth(x, y: integer);
  535. var delta, count: integer;
  536. var am: real;
  537. begin
  538. count:= 0;
  539. am:= 0;
  540.  
  541. for var i:= -1 to 1 do begin
  542. for var j:= -1 to 1 do begin
  543. if (x + i > -1) AND (y + j > -1) AND (x + i < WIDTH + 1) AND (y + j < HEIGHT + 1) then begin
  544. inc(count);
  545. am:= am + matrix[x + i, y + j];
  546. end;
  547. end;
  548. end;
  549.  
  550. if antiAlias = 2 then
  551. matrix[x, y]:= round(am / count) + Random(7) - 3
  552. else begin
  553. delta:= matrix[x, y] - round(am / count);
  554. case delta of
  555. -1..1: delta:= Random(11) - 5;
  556. end;
  557. if (delta > 0) then
  558. matrix[x, y]:= round(matrix[x, y] - Random(delta))
  559. else
  560. matrix[x, y]:= round(matrix[x, y] + Random(Abs(delta)));
  561. end;
  562. end;
  563.  
  564. procedure update();
  565. begin
  566. maxHeight:= -1000;
  567. minHeight:= 1500;
  568. for var x:= 0 to WIDTH do begin
  569. for var y:= 0 to HEIGHT do begin
  570. if antiAlias <> 0 then smooth(x, y);
  571. if maxHeight < matrix[x, y] then maxHeight:= matrix[x, y];
  572. if minHeight > matrix[x, y] then minHeight:= matrix[x, y];
  573. end;
  574. end;
  575. end;
  576.  
  577. procedure calculateColors();
  578. var a: real;
  579. begin
  580. for var x:= 0 to WIDTH - 1 do begin
  581. for var y:= 0 to HEIGHT - 1 do begin
  582. var arithMean:= round((matrix[x, y] + matrix[x + 1, y] + matrix[x, y + 1] + matrix[x + 1, y + 1]) / 4);
  583. case arithMean of
  584. -1000..400: begin
  585. if arithMean < 0 then
  586. colors[x,y]:= RGB(28, 15, 181)
  587. else begin
  588. a:= arithMean / 400;
  589. colors[x,y]:= RGB(round(28 + 123 * a), round(15 + 207 * a), round(181 + 72 * a));
  590. end;
  591. end;
  592. 401..600: begin
  593. a:= (arithMean - 400) / 200;
  594. colors[x,y]:= RGB(round(250 - 10 * a), round(223 - 31 * a), round(133 + 7 * a));
  595. end;
  596. 601..1000: begin
  597. a:= (arithMean - 600) / 400;
  598. colors[x,y]:= RGB(round(81 - 26 * a), round(232 - 77 * a), round(77 - 16 * a));
  599. end;
  600. 1001..1200: begin
  601. a:= (arithMean - 1000) / 200;
  602. colors[x,y]:= RGB(round(129 - 26 * a), round(173 - 52 * a), round(180 - 42 * a));
  603. end;
  604. 1201..1500: begin
  605. a:= (arithMean - 1200) / 300;
  606. colors[x,y]:= RGB(round(248 - 13 * a), round(253 - 8 * a), round(253 - 8 * a));
  607. end;
  608. end;
  609. end;
  610. end;
  611. end;
  612.  
  613. procedure draw();
  614. var y:= 0;
  615. var x:= 0;
  616. begin
  617. isWorking:= true;
  618. while y < WINDOW_H do begin
  619. x:= 0;
  620. while x < WINDOW_W do begin
  621. if (x + up > -1) AND
  622. (y + right > -1) AND
  623. (y + right + SCALE < min(WindowHeight, WindowWidth) + 1) AND
  624. (x + up + SCALE < min(WindowHeight, WindowWidth) + 1) then begin
  625. SetPenColor(colors[round(y / SCALE), round(x / SCALE)]);
  626. if SCALE > 1 then begin
  627. SetBrushColor(colors[round(y / SCALE), round(x / SCALE)]);
  628. SetBrushStyle(bsSolid);
  629. Rectangle(y + right, x + up, y + right + SCALE, x + up + SCALE);
  630. end else
  631. SetPixel(y + right, x + up, colors[y, x]);
  632. end;
  633. x:= x + SCALE;
  634. end;
  635. y:= y + SCALE;
  636. end;
  637. isWorking:= false;
  638. end;
  639.  
  640. procedure createNewWorld();
  641. begin
  642. if reading = 1 then begin
  643. ClearWindow(clWhite);
  644. WIDTH:= round(readed);
  645. HEIGHT:= WIDTH;
  646. initEnvironment();
  647. reading:= 2;
  648. end;
  649. end;
  650.  
  651. procedure changeH(x, y, h: integer);
  652. begin
  653. if (x > -1) AND (y > -1) AND (x < WIDTH + 1) AND (y < HEIGHT + 1) then begin
  654. var v:= matrix[x, y] + h;
  655. if v > 1501 then
  656. matrix[x, y]:= 1500
  657. else
  658. if v < -1000 then
  659. v:= -1000
  660. else
  661. matrix[x, y]:= v;
  662. end;
  663. end;
  664.  
  665. procedure initEditingMode();
  666. begin
  667. mode:= 0;
  668. OnMouseMove:= (x, y, mb) -> if mb <> 0 then
  669. changeH(round((x - right) / SCALE),
  670. round((y - up) / SCALE),
  671. (mb * 2 - 3) * -changeHeight);
  672. OnMouseDown:= nil;
  673. end;
  674.  
  675. procedure initCreatursMode();
  676. begin
  677. mode:= 1;
  678. OnMouseMove:= nil;
  679. OnMouseDown:= (x, y, mb) -> begin
  680. var i:= round((x - right) / SCALE);
  681. var j:= round((y - up) / SCALE);
  682. if (i > -1) AND
  683. (j > -1) AND
  684. (i < WIDTH + 1) AND
  685. (j < HEIGHT + 1) then begin
  686. if mb = 1 then begin
  687. entities:= entities^.add(entities);
  688. entities^.create(i, j, names[Random(141)], RGB(180, 40, 180));
  689. end else begin
  690. flowers:= flowers^.add(flowers);
  691. flowers^.createFlower(i, j, RGB(200, 200, 100));
  692. end;
  693. end;
  694. end;
  695. end;
  696.  
  697. procedure disposeLists();
  698. begin
  699. entities^.removeEverything(entities);
  700. flowers^.removeEverything(flowers);
  701. entities:= nil;
  702. flowers:= nil;
  703. end;
  704.  
  705. procedure KeyDown(key: integer);
  706. begin
  707. case key of
  708. VK_ADD: maxFPSup();
  709. VK_SUBTRACT: maxFPSdown();
  710. VK_SPACE: setPause(NOT(pause));
  711. VK_G: begin
  712. disposeLists();
  713. initEditingMode();
  714. initEnvironment();
  715. end;
  716. VK_R: reading:= 0;
  717. VK_B: begin
  718. changeHeight:= round(readed);
  719. reading:= 2;
  720. end;
  721. VK_W: createNewWorld();
  722. VK_O: setScale(SCALE - 1);
  723. VK_P: setScale(SCALE + 1);
  724. VK_A: begin
  725. inc(antiAlias);
  726. if antiAlias = 3 then
  727. antiAlias:= 0;
  728. end;
  729. VK_M: begin
  730. inc(mode);
  731. if mode > 1 then
  732. mode:= 0;
  733. if mode = 0 then
  734. initEditingMode()
  735. else
  736. initCreatursMode();
  737. end;
  738. VK_D: disposeLists();
  739. VK_UP: movement(speed, up);
  740. VK_DOWN: movement(-speed, up);
  741. VK_RIGHT: movement(-speed, right);
  742. VK_LEFT: movement(speed, right);
  743. end;
  744. end;
  745.  
  746. procedure createOpenWindow();
  747. begin
  748. SetWindowSize(400, 200);
  749. SetWindowPos(round(ScreenWidth / 2) - 200, round(ScreenHeight / 2) - 100);
  750.  
  751. TextOut(round(WindowWidth / 2 - 60), round(WindowHeight / 2 - 20), 'Enter world size(power of two)');
  752. read(WIDTH);
  753. HEIGHT:= WIDTH;
  754. end;
  755.  
  756. procedure initMainFunc();
  757. begin
  758. antiAlias:= 0;
  759. changeHeight:= 50;
  760. readed:= 0;
  761. reading:= 2;
  762.  
  763. initNames();
  764. end;
  765.  
  766. procedure initMainWindow();
  767. begin
  768. SetWindowPos(0, 0);
  769. Sleep(500);
  770. initEnvironment();
  771. Sleep(500);
  772. SetWindowSize(ScreenWidth, ScreenHeight);
  773. setScale(1);
  774. toCenter();
  775.  
  776. OnKeyDown:= KeyDown;
  777. OnMouseDown:= nil;
  778. OnMouseMove:= (x, y, mb) -> if mb <> 0 then
  779. changeH(round((x - right) / SCALE),
  780. round((y - up) / SCALE),
  781. (mb * 2 - 3) * -changeHeight);
  782. end;
  783.  
  784. procedure info(start: real);
  785. var s: string;
  786. begin
  787. if NOT(pause) then begin
  788. fps:= 1000 / (Milliseconds - start);
  789. SetWindowTitle('fps: ' + (Trunc(fps * 100) / 100));
  790. end;
  791. s:= 'Anti aliasing mode: ';
  792. if antiAlias = 2 then
  793. s:= s + 'Full anti aliasing'
  794. else
  795. if antiAlias = 1 then
  796. s:= s + 'Local anti aliasing'
  797. else
  798. s:= s + 'No anti aliasing';
  799. SetBrushColor(clWhite);
  800. var m:= min(WindowWidth, WindowHeight);
  801. TextOut(m + 10, 50, s);
  802. TextOut(m + 10, 70, 'MaxFPS: ' + maxFPS);
  803. TextOut(m + 10, 90, 'Brush: ' + changeHeight);
  804. TextOut(m + 10, 110, 'Size: ' + WIDTH + 'x' + HEIGHT);
  805. TextOut(m + 10, 130, 'Scale: ' + SCALE);
  806. TextOut(m + 10, 150, 'Minimal height: ' + minHeight);
  807. TextOut(m + 10, 170, 'Maximal height: ' + maxHeight);
  808. TextOut(m + 10, 220, 'SPACE -Pause');
  809. TextOut(m + 10, 240, 'G -Generation of a new world');
  810. TextOut(m + 10, 260, 'A -Change the anti aliasing mode');
  811. TextOut(m + 10, 280, 'R -Read the data');
  812. TextOut(m + 10, 300, 'B -Assign brush');
  813. TextOut(m + 10, 320, 'W -Assign world size');
  814. TextOut(m + 10, 340, '+/- -Controller Max FPS');
  815. TextOut(m + 10, 360, 'P/O -Controller scaling');
  816. TextOut(m + 10, 380, 'UP/DOWN/RIGHT/LEFT -Offset the image');
  817. Line(m, 0, m, m);
  818. end;
  819.  
  820. begin
  821. var start, finish : real;
  822. start:= -1;
  823. speed:= 10;
  824. pause:= false;
  825.  
  826. initMainFunc();
  827. createOpenWindow();
  828. Sleep(500);
  829. initMainWindow();
  830. Sleep(500);
  831.  
  832. while (true) do begin
  833.  
  834. finish:= Milliseconds;
  835.  
  836. LockDrawing();
  837.  
  838. if ((start = -1) OR (1000 / maxFPS < (finish - start))) AND (NOT(pause)) then begin
  839. start:= Milliseconds;
  840.  
  841. Redraw;
  842.  
  843. if reading = 0 then begin
  844. read(readed);
  845. reading:= 1;
  846. end else begin
  847. if reading = 2 then begin
  848. Window.Clear();
  849. update();
  850. calculateColors();
  851. draw();
  852. if mode = 1 then begin
  853. sizeEnt:= 0;
  854. updateEnt(entities);
  855. entities^.removeAll(entities);
  856. updateFl(flowers);
  857. flowers^.removeAll(flowers);
  858. drawEnt(flowers);
  859. drawEnt(entities);
  860. end;
  861. info(start);
  862. end;
  863. end;
  864. end;
  865. end;
  866. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement