Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program pjp;
- uses wincrt, wingraph, winmouse, sysutils, dos;
- type Tball = record
- x, y, radius, vy:integer;
- check, onscreen:boolean;
- end;
- Tblock = record
- x1, x2, y1, y2, vy, vx:integer;
- end;
- var driver, mode:smallint;
- key:char;
- balls:array[1..2] of Tball;
- block:Tblock;
- lim,acelcount,vxb,auxcount:integer;
- procedure randomball(n:integer);
- begin
- with balls[n] do
- begin
- onscreen:=true;
- check:=false;
- randomize;
- x:=getmaxx;
- y:=random(getmaxy+2200);
- radius:=40;
- end;
- end;
- procedure initialize(n:integer);
- begin
- UpdateGraph(UpdateOff);
- with block do
- begin
- x2:=getmaxx div 2;
- x1:=x2 - 100;
- y2:=getmaxy;
- y1:=y2-200;
- vy:=0;
- vx:=0;
- end;
- with balls[n] do
- begin
- randomball(n);
- end;
- end;
- procedure acelerateball(acel:integer);
- begin
- if (acelcount mod 13 = 0) and (acelcount<>0) and (auxcount<>acelcount) then begin
- vxb:=vxb+acel;
- auxcount:=acelcount;
- end;
- end;
- procedure moveball;
- var n:integer;
- begin
- acelerateball(-1);
- for n := 1 to lim do
- with balls[n] do
- begin
- if onscreen = true then
- x:= x + vxb;
- end;
- end;
- procedure killball;
- var cont:integer;
- begin
- for cont:= 1 to lim do
- with balls[cont] do
- begin
- if x+radius<0 then begin
- onscreen:=false;
- end;
- end;
- end;
- procedure alternateball;
- var n,rdm:integer;
- begin
- for n := 1 to lim do
- begin
- with balls[n] do
- if onscreen = true then
- if check=false then
- begin
- randomize;
- rdm:=random(20);
- if (x<getmaxx div 2) and (x>getmaxx div 3) and (rdm<5) then
- begin
- check:=true;
- if n = lim then
- randomball(1)
- else randomball(n+1);
- acelcount:=acelcount+1;
- end;
- if x<getmaxx div 3 then
- begin
- check:=true;
- if n = lim then
- randomball(1)
- else randomball(n+1);
- acelcount:=acelcount+1;
- end;
- end;
- end;
- end;
- procedure moveblock;
- begin
- with block do
- begin
- x1:=x1+vx;
- x2:=x2+vx;
- y1:=y1+vy;
- y2:=y2+vy;
- if vx>0 then
- vx:=vx-1;
- if vx<0 then
- vx:=vx+1;
- if y2<getmaxy then
- vy:=vy+1
- else if y2>getmaxy then
- begin
- vy:=0;
- y2:=getmaxy;
- y1:=y2-200;
- end;
- if y1<0 then
- begin
- y1:=0;
- y2:=200;
- end;
- if x1<0 then
- begin
- x1:=0;
- x2:=100;
- end;
- if x2>getmaxx then
- begin
- x2:=getmaxx;
- x1:=getmaxx-100;
- end;
- end;
- end;
- procedure draw;
- var cont:integer;
- begin
- clearviewport;
- setcolor(white);
- SetFillStyle(solidfill, white);
- setlinestyle(solidln, doublewidth, 4);
- with block do
- begin
- FillRect(x1,y1,x2,y2);
- end;
- for cont := 1 to lim do
- with balls[cont] do
- if onscreen=true then
- begin
- circle(x,y,radius);
- end;
- end;
- procedure collisioncheck;
- var cont:integer;
- begin
- for cont:= 1 to lim do
- with balls[cont] do
- begin
- if ((y-radius<block.y2) and (y-radius>block.y1)) or ((y+radius<block.y2) and (y+radius>block.y1)) then
- if ((x-radius<block.x2) and (x-radius>block.x1)) or ((x+radius<block.x2) and (x+radius>block.x1)) then
- delay(100); //the delay is just for knowing that the collision happened. gonna change it later.
- end;
- end;
- procedure joystick;
- begin
- key:=readkey;
- case key of
- #0:begin
- key:=readkey;
- case key of
- #72:with block do
- begin
- vy:=-25;
- end;
- #80:with block do
- begin
- y1:=y2-100; //make it get half of its height
- repeat
- moveblock; //these are the drawing routines.
- moveball; //they are in another procedure, which is the 'main loop'
- collisioncheck;
- draw; //i expected the code to run inside here with the block's
- alternateball; //height changed, and as soon as the arrow key gets released
- updateGraph(updateNow); //it should go back to the 'main loop'
- killball;
- delay(10);
- until keypressed = false; //<--thats what i think is not working
- y1:=y2-200; //this would make the block get normal again
- end;
- #75:with block do
- begin
- vx:=-20;
- end;
- #77:with block do
- begin
- vx:=20;
- end;
- end;
- end;
- end;
- end;
- procedure game;
- begin
- initialize(1);
- draw;
- repeat
- repeat
- moveblock;
- moveball;
- draw;
- collisioncheck;
- alternateball;
- updateGraph(updateNow);
- killball;
- delay(10);
- until keypressed;
- joystick;
- moveblock;
- draw;
- until key = #27;
- end;
- //main
- begin
- lim:=2;
- acelcount:=0;
- vxb:=-5;
- driver:=nopalette;
- mode:=mMaximized;
- initgraph(driver, mode, 'Test');
- game;
- closegraph;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement