Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program Grath3;
- Uses
- ptcGraph { FPC ONLY! }, Crt;
- Var
- gd, gm : integer;
- function Random2(min : integer; max : integer) : integer;
- begin
- Randomize;
- Random2 := random (max-min+1)+min;
- end;
- function ScreenX(x : real) : integer;
- begin
- ScreenX := Trunc((GetMaxX+1) / 256 * x);
- end;
- function ScreenY(y : real) : integer;
- begin
- ScreenY := Trunc((GetMaxY+1) / 256 * y);
- end;
- Const
- gtime = 60;
- time = 1;
- Var
- ticks, ticks_cur, gticks, gticks_cur : longint;
- i : integer;
- Type bubble=record
- x: real;
- y: real;
- sx: real;
- sy: real;
- ftick : real;
- end;
- Var
- bubbles: array of bubble;
- procedure SpawnBubble(x : real; y : real; sx : real; sy : real);
- begin
- SetLength(bubbles, Length(bubbles)+1);
- bubbles[Length(bubbles)-1].x := x;
- bubbles[Length(bubbles)-1].y := y;
- bubbles[Length(bubbles)-1].sx := sx;
- bubbles[Length(bubbles)-1].sy := sy;
- bubbles[Length(bubbles)-1].ftick := 0;
- end;
- procedure TickBubble(id : integer);
- begin
- // add accel
- bubbles[id].x := bubbles[id].x + bubbles[id].sx;
- bubbles[id].y := bubbles[id].y + bubbles[id].sy;
- // respawn
- if (bubbles[id].y <= 128) then
- begin
- bubbles[id].y := Random2(200, 220);
- bubbles[id].x := Random2(100, 156);
- end;
- // x floating
- if (bubbles[id].ftick > 0) and (bubbles[id].ftick <= 128) then
- bubbles[id].x := bubbles[id].x + 0.005
- else if (bubbles[id].ftick > 128) and (bubbles[id].ftick <= 256) then
- bubbles[id].x := bubbles[id].x - 0.005
- else if (bubbles[id].ftick > 256) then
- bubbles[id].ftick := 0;
- bubbles[id].ftick := bubbles[id].ftick + 1;
- end;
- begin
- SetLength(bubbles, 0);
- // defaults
- ticks := 0;
- ticks_cur := 0;
- gticks := 0;
- gticks_cur := 0;
- // init grathical subsystem
- gd := D8bit;
- gm := m800x600;
- InitGraph(gd,gm,'');
- // spawn bubbles
- SpawnBubble(100, 156, 0, -0.02 / 5);
- SpawnBubble(128, 144, 0, -0.02 / 5);
- // loop
- while True do
- begin
- // exit on key press
- if KeyPressed then break;
- if ticks_cur >= ticks then
- begin
- // process bubbles
- if Length(bubbles) <> 0 then
- for i := 0 to Length(bubbles)-1 do
- TickBubble(i);
- ticks := ticks + time;
- end;
- inc(ticks_cur);
- if gticks_cur >= gticks then
- begin
- ClearDevice;
- SetColor(WHITE);
- // start point
- MoveTo(ScreenX(80+16), ScreenY(225));
- setlinestyle(SolidLn, 0, thickwidth);
- LineRel(ScreenX(64), 0); // floor
- LineRel(ScreenX(10), ScreenY(-128)); // right wall
- // go back
- MoveTo(ScreenX(80+16), ScreenY(225));
- LineRel(ScreenX(-10), ScreenY(-128)); // left wall
- MoveTo(ScreenX(80+16), ScreenY(225));
- // water
- setlinestyle(SolidLn, 0, normwidth);
- SetColor(BLUE);
- MoveRel(ScreenX(-8), ScreenY(-100));
- LineRel(ScreenX(80), 0);
- SetColor(WHITE);
- // draw bubbles
- if Length(bubbles) <> 0 then
- for i := 0 to Length(bubbles)-1 do
- Circle(ScreenX(bubbles[i].x), ScreenY(bubbles[i].y), 6);
- gticks := gticks + gtime;
- end;
- inc(gticks_cur);
- delay(1);
- end;
- CloseGraph;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement