bounce.pas

Denna kod är public domain. Om ni hittar fel eller vill ändra något i koden blir jag jätteglad om ni skickar dessa ändringar till jesper [at] fantasi [punkt] se.


PROGRAM BOUNCE;

USES Crt, graph;

CONST Fi : fillpatterntype = ($ff, $ff, $ff, $ff, $ff, $ff, $ff, $ff);

VAR
   ps, p, sv, ti,   : integer;
   x, y, dx, dy     : integer;
   i, li, lx, ly    : integer;
   o, n, r, m, b    : integer;
   grDriver, grMode : integer;
   tid, so, tr      : integer;
   knapp            : char;
   pc, l1, l2       : string;

LABEL e, ex, t, u, 1, st, 2, 3, sl;

BEGIN
   randomize;
   grDriver := Detect;
   InitGraph(grDriver, grMode, '\kompil\tp6\bgi');
   settextstyle(gothicfont, horizdir, 10);
   sv := 15;
   p := 260;
   n := 2;
   so := 1;
U: 
   clrscr;
   initgraph(grDriver, grMode, '\kompil\tp6\bgi');
   setcolor(10);
   settextstyle(gothicfont, 0, 5);
   outtextxy(200, 40, 'BOUNCE');
   settextstyle(defaultfont, 0, 1);
   outtextxy(155, 100, 'A PROGRAM BY JESPER WILHELMSSON, 1992');
   outtextxy(200, 150, 'LEVEL:    EASIER');
   outtextxy(278, 200, 'HARDER');
   outtextxy(200, 125, 'NUMBER OF PLAYERS:');
   outtextxy(210, 250, 'START GAME');
   outtextxy(210, 300, 'QUIT GAME');
   outtextxy(400, 120, '  ONE PLAYER');
   outtextxy(398, 130, '* TWO PLAYERS');
   outtextxy(210, 225, 'FX');
   outtextxy(245, 225, 'on');
   setcolor(4);
   outtextxy(398, 120, '*');
   outtextxy(278, 200, 'H');
   outtextxy(210, 250, 'S');
   outtextxy(210, 300, 'Q');
   outtextxy(200, 125, 'N');
   outtextxy(280, 150, 'E');
   outtextxy(210, 225, 'F');
   setcolor(10);
   outtextxy(280, 175, '------>');
   outtextxy(450, 170, '* 1');
   outtextxy(450, 180, '* 2');
   outtextxy(450, 190, '* 3');
   outtextxy(450, 200, '* 4');
   outtextxy(450, 210, '* 5');
   outtextxy(450, 220, '* 6');
   outtextxy(450, 230, '* 7');
   outtextxy(450, 240, '* 8');
   outtextxy(450, 250, '* 9');
   outtextxy(450, 260, '*10');
   outtextxy(450, 270, '*11');
   outtextxy(450, 280, '*12');
   outtextxy(450, 290, '*13');
   outtextxy(450, 300, '*14');
   outtextxy(450, 310, '*15');
   outtextxy(450, 320, '*16');
   outtextxy(450, 330, '*17');
   outtextxy(450, 340, '*18');
   outtextxy(450, 350, '*19');
   outtextxy(450, 360, '*20');
   rectangle(100, 350, 300, 400);
   outtextxy(110, 360, 'Player 1 styr med A o Z');
   outtextxy(110, 380, 'Player 2 styr med  o -');
   setcolor(4);
   rectangle(240, 220, 270, 235);
   setcolor(10);
   setfillpattern(fi, black);
   repeat;
      knapp := ' ';
      if keypressed then knapp := readkey;
      outtextxy(450, P, '*');
      if knapp = 'h'then begin
         Sv := Sv - 1;
         if Sv < 5 then
            Sv := 25;
         P := P + 10;
         if P > 360 then
            P:=170;
      end;
      if knapp = 'e'then begin
         Sv := Sv + 1;
         if S > 25 then
            Sv := 5;
         P := P - 10;
         if P < 170 then
            P := 360;
      end;
      tr := 1;
      if (knapp = 'f') and (so = 1) then begin
         so := 0;
         tr := 0;
         floodfill(241, 221, red);
         outtextxy(245, 225, 'off');
      end;
      if (knapp = 'f') and (so = 0) and (tr = 1) then begin
         so := 1;
         floodfill(241, 221, red);
         outtextxy(245, 225, 'on');
      end;
      setcolor(4);
      outtextxy(450, P, '*');
      if knapp = 'q' then
         goto T;
      if knapp = 'n'then begin
         n := n + 1;
         if n = 3 then
            n := 1;
         if n=1 then
            outtextxy(370,125,'*');
         setcolor(10);
         if n=2 then
            outtextxy(370,125,'*');
      end;
   until knapp = 's';
   if n = 1 then
      goto 1;
   lx := 3;
   ly := 3;
2: 
   clrscr;
   initgraph(grdriver, grmode, '');
   x := random(100) + 200;
   y := random(392) + 4;
   dx := random(2);
   dy := random(2);
   i := 175;
   knapp := ' ';
   o := 175;
   b := 0;
   m := 0;
   if dx = 0 then
      dx := -1;
   if dy = 0 then
      dy := -1;
   tid := 0;
   setcolor(4);
   rectangle(0, 0, 639, 400);
   settextstyle(sansseriffont, 0, 2);
   outtextxy(20, 430, 'Lives:');
   str(lx, l1);
   str(ly, l2);
   outtextxy(100, 430, l2);
   outtextxy(400, 430, l1);
   setcolor(10);
   line(15, i, 15, i + 49);
   line(629, o, 629, o + 49);
   repeat;
      for ti := 1 to Sv * 100 - tid * 60 do begin;
      end;
      x := x + dx;
      y := y + dy;
      putpixel(x - dx, y - dy, 0);
      putpixel(x, y, 10);
      if (y > o - 1) and (y < o + 51) and (x = 623) or
         (y > i - 1) and (y < i + 51) and (x = 16) then begin
            dx := -dx;
            if so = 1 then begin
               sound(1500);
               delay(5);
               nosound;
            end;
            inc(tid);
         end;
      if (y = 398) or (y = 2) then begin
         dy:=-dy;
         if so = 1 then begin
            sound(1000);
            delay(5);
            nosound;
         end;
      end;
      if (x = 637) or (x = 2) then
         goto E;
      if b = 1 then putpixel(15, i - 2, 0);
      if m = 1 then putpixel(629, o - 2, 0);
      if b = 1 then putpixel(15, i + 49, 10);
      if m = 1 then putpixel(629, o + 49, 10);
      if b = -1 then putpixel(15, i + 50, 0);
      if b = -1 then putpixel(15, i - 1, 10);
      if m = -1 then putpixel(629, o + 50, 0);
      if m = -1 then putpixel(629, o - 1, 10);
      if keypressed then
         knapp := readkey;
      if knapp = 'z' then b := 1;
      if knapp = 'a' then b := -1;
      if knapp = '-' then m := 1;
      if knapp = '' then m := -1;
      i := i + b;
      o := o + m;
      if i = 1 then i := i + 1;
      if i = 350 then i := i - 1;
      if o = 1 then o := o + 1;
      if o = 350 then o := o - 1;
   until knapp = 'g';
E: 
   knapp := ' ';
   if so = 1 then begin
      for r := 500 downto 50 do begin
         sound(r);
         delay(2);
         nosound;
      end;
   end;
   if x = 637 then begin
      dec(lx);
      if lx = 0 then
         goto 3;
   end;
   if x=2 then begin
      dec(ly);
      if ly = 0 then
         goto 3;
   end;
   goto 2;
Ex:
   knapp := ' ';
   if so = 1 then begin
      for r:= 500 downto 50 do begin
         sound(r);
         delay(2);
         nosound;
      end;
   end;
   dec(li);
   if li = 0 then
      goto sl;
   goto st;
3: 
   setcolor(12);
   settextstyle(gothicfont, 0, 5);
   outtextxy(155,160,'GAME OVER');
   if lx > ly then begin
      settextstyle(defaultfont, 0, 2);
      outtextxy(110, 210, 'THE WINNER IS PLAYER 2');
   end
   else begin
      settextstyle(defaultfont, 0, 2);
      outtextxy(110, 210, 'THE WINNER IS PLAYER 1');
   end;
   x := 0;
   repeat;
   until keypressed;
   Goto U;
sl:
   setcolor(12);
   settextstyle(gothicfont, 0, 5);
   outtextxy(100, 160, 'GAME OVER');
   x := 0;
   repeat;
   until keypressed;
   Goto U;
1: 
   ps := 0;
   li := 3;
st:
   clrscr;
   initgraph(grdriver, grmode, '');
   x := 22;
   y := 22;
   dx := 1;
   dy := 1;
   i := 175;
   knapp := ' ';
   b := 0;
   setcolor(4);
   rectangle(0, 0, 639 - p, 400);
   rectangle(95, 408, 200, 447);
   setcolor(10);
   settextstyle(gothicfont, 0, 5);
   outtextxy(5, 400, 'score');
   str(ps, pc);
   outtextxy(100, 400, pc);
   line(15, i, 15, i + 49);
   repeat;
      for ti := 1 to Sv * 100 do begin ;
      end;
      x := x + dx;
      y := y + dy;
      putpixel(x - dx, y - dy, 0);
      putpixel(x, y, 10);
      if (y > i - 1) and (y < i + 51) and (x = 16) then begin
         dx := -dx;
         ps := ps + random(8) + 1;
         str(ps,pc);
         setfillpattern(fi, black);
         floodfill(100, 420, red);
         outtextxy(100, 400, pc);
      end;
      if (y = 398) or (y = 2) then begin
         if so = 1 then begin
            sound(1000);
            delay(5);
            nosound;
         end;
         dy := -dy;
      end;
      if x = 637 - p then begin
         if so = 1 then begin
            sound(1000);
            delay(5);
            nosound;
         end;
         dx := -dx;
      end;
      if x = 2 then goto Ex;
      if b = 1 then putpixel(15, i - 2, 0);
      if b = 1 then putpixel(15, i + 49, 10);
      if b = -1 then putpixel(15, i + 50, 0);
      if b = -1 then putpixel(15, i - 1, 10);
      if keypressed then knapp := readkey;
      if knapp = 'z' then b := 1;
      if knapp = 'a' then b := -1;
      i := i + b;
      if i = 1 then i := i + 1;
      if i = 349 then i := i - 1;
   until knapp = 's';
   goto ex;
T:
   closegraph;
END.