Advertisement
Guest User

Untitled

a guest
Oct 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.01 KB | None | 0 0
  1. Program Grath3;
  2.  
  3. Uses
  4.     ptcGraph { FPC ONLY! }, Crt;
  5.  
  6. Var
  7.     gd, gm : integer;
  8.  
  9. function Random2(min : integer; max : integer) : integer;
  10. begin
  11.     Randomize;
  12.     Random2 := random (max-min+1)+min;
  13. end;
  14.  
  15. function ScreenX(x : real) : integer;
  16. begin
  17.     ScreenX := Trunc((GetMaxX+1) / 256 * x);
  18. end;
  19.  
  20. function ScreenY(y : real) : integer;
  21. begin
  22.     ScreenY := Trunc((GetMaxY+1) / 256 * y);
  23. end;
  24.  
  25. Const
  26.     gtime = 60;
  27.     time = 1;
  28. Var
  29.     ticks, ticks_cur, gticks, gticks_cur : longint;
  30.     i : integer;
  31.  
  32. Type bubble=record
  33.     x: real;
  34.     y: real;
  35.     sx: real;
  36.     sy: real;
  37.     ftick : real;
  38. end;
  39.  
  40. Var
  41.     bubbles: array of bubble;
  42.  
  43. procedure SpawnBubble(x : real; y : real; sx : real; sy : real);
  44. begin
  45.     SetLength(bubbles, Length(bubbles)+1);
  46.     bubbles[Length(bubbles)-1].x := x;
  47.     bubbles[Length(bubbles)-1].y := y;
  48.     bubbles[Length(bubbles)-1].sx := sx;
  49.     bubbles[Length(bubbles)-1].sy := sy;
  50.     bubbles[Length(bubbles)-1].ftick := 0;
  51. end;
  52.  
  53. procedure TickBubble(id : integer);
  54. begin
  55.     // add accel
  56.     bubbles[id].x := bubbles[id].x + bubbles[id].sx;
  57.     bubbles[id].y := bubbles[id].y + bubbles[id].sy;
  58.  
  59.     // respawn
  60.     if (bubbles[id].y <= 128) then
  61.     begin
  62.         bubbles[id].y := Random2(200, 220);
  63.         bubbles[id].x := Random2(100, 156);
  64.     end;
  65.  
  66.     // x floating
  67.     if (bubbles[id].ftick > 0) and (bubbles[id].ftick <= 128) then
  68.         bubbles[id].x := bubbles[id].x + 0.005
  69.     else if (bubbles[id].ftick > 128) and (bubbles[id].ftick <= 256) then
  70.         bubbles[id].x := bubbles[id].x - 0.005
  71.     else if (bubbles[id].ftick > 256) then
  72.         bubbles[id].ftick := 0;
  73.  
  74.     bubbles[id].ftick := bubbles[id].ftick + 1;
  75. end;
  76.  
  77. begin
  78.     SetLength(bubbles, 0);
  79.     // defaults
  80.     ticks := 0;
  81.     ticks_cur := 0;
  82.     gticks := 0;
  83.     gticks_cur := 0;
  84.  
  85.     // init grathical subsystem
  86.     gd := D8bit;
  87.     gm := m800x600;
  88.     InitGraph(gd,gm,'');
  89.  
  90.     // spawn bubbles
  91.     SpawnBubble(100, 156, 0, -0.02 / 5);
  92.     SpawnBubble(128, 144, 0, -0.02 / 5);
  93.  
  94.     // loop
  95.     while True do
  96.     begin
  97.         // exit on key press
  98.         if KeyPressed then break;
  99.  
  100.         if ticks_cur >= ticks then
  101.         begin
  102.             // process bubbles
  103.             if Length(bubbles) <> 0 then
  104.                 for i := 0 to Length(bubbles)-1 do
  105.                     TickBubble(i);
  106.             ticks := ticks + time;
  107.         end;
  108.         inc(ticks_cur);
  109.  
  110.         if gticks_cur >= gticks then
  111.         begin
  112.             ClearDevice;
  113.             SetColor(WHITE);  
  114.             // start point
  115.             MoveTo(ScreenX(80+16), ScreenY(225));
  116.             setlinestyle(SolidLn, 0, thickwidth);
  117.             LineRel(ScreenX(64), 0); // floor
  118.             LineRel(ScreenX(10), ScreenY(-128)); // right wall
  119.  
  120.             // go back
  121.             MoveTo(ScreenX(80+16), ScreenY(225));
  122.             LineRel(ScreenX(-10), ScreenY(-128)); // left wall
  123.  
  124.             MoveTo(ScreenX(80+16), ScreenY(225));
  125.  
  126.             // water
  127.             setlinestyle(SolidLn, 0, normwidth);
  128.             SetColor(BLUE);
  129.             MoveRel(ScreenX(-8), ScreenY(-100));
  130.             LineRel(ScreenX(80), 0);
  131.  
  132.             SetColor(WHITE);
  133.             // draw bubbles
  134.             if Length(bubbles) <> 0 then
  135.                 for i := 0 to Length(bubbles)-1 do
  136.                     Circle(ScreenX(bubbles[i].x), ScreenY(bubbles[i].y), 6);
  137.  
  138.             gticks := gticks + gtime;
  139.         end;
  140.  
  141.         inc(gticks_cur);
  142.         delay(1);
  143.     end;
  144.  
  145.     CloseGraph;
  146. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement