program falling_rocks;  

Global
GAMEOVER;
FPGGAME;
FLGSHOT;
FLGROCK;
PLYSCORE=0;
PLYLIVES=3; 
GY; 
SNDLOOP;
CHNLOOP;    
Mede;
Shoot=0;
Diff=97;
Diff0;
PRIVATE
BEGIN
FPGGAME=LOAD_FPG("pigeonk.fpg");
SNDLOOP=load_song("music.wav");
play_song(SNDLOOP,-1); // -1 for infinite loop          
PUT_SCREEN(FPGGAME,8);
Menu();
Frame;
END     
Process Menu();                  
PRIVATE
Begin
Loop
IF(KEY(_Control))
SIGNAL(TYPE Menu,S_KILL);
Keep();
Mede=1;
END 
IF(KEY(_Alt))
SIGNAL(TYPE Menu,S_KILL);
RUN();
Mede=2;
END 
IF(KEY(_Space))
SIGNAL(TYPE Menu,S_KILL);
Avoid();
Mede=3;
END
Frame;
END
END

PROCESS Keep();
PRIVATE
BEGIN 
Diff0=100-Diff;
PUT_SCREEN(FPGGAME,1); SHIP();
WRITE_INT(0,30,0,0,OFFSET PLYSCORE);         
WRITE_INT(0,270,0,0,OFFSET PLYLIVES); 
WRITE_INT(0,150,0,0,Offset Diff0);
FRAME;
While(NOT GAMEOVER)
If(FLGROCK<10 AND RAND(0,99)>Diff)
ROCK();
END
FRAME;
END  
WRITE(0,125,100,0,"GAME OVER");
SIGNAL(TYPE SHOT,S_KILL); 
SIGNAL(TYPE ROCK,S_KILL);
SIGNAL(TYPE SHIP,S_KILL); 
WHILE(NOT KEY(_ALT))
FRAME;
END
END

PROCESS RUN();
PRIVATE
BEGIN
Diff=87;
Diff0=100-Diff;
PUT_SCREEN(FPGGAME,1); SHIP();
WRITE_INT(0,30,0,0,OFFSET PLYSCORE);         
WRITE_INT(0,270,0,0,OFFSET PLYLIVES); 
WRITE_INT(0,150,0,0,Offset Diff0);
FRAME;
While(NOT GAMEOVER)
If(FLGROCK<10 AND RAND(0,99)>Diff)
ROCK();
END
FRAME;
END  
WRITE(0,125,100,0,"GAME OVER");
SIGNAL(TYPE SHOT,S_KILL); 
SIGNAL(TYPE ROCK,S_KILL);
SIGNAL(TYPE SHIP,S_KILL);
WHILE(NOT KEY(_ALT))
FRAME;
END
END

PROCESS Avoid();
PRIVATE
BEGIN 
Diff=90;
Diff0=100-Diff;
PUT_SCREEN(FPGGAME,1); SHIP();
WRITE_INT(0,30,0,0,OFFSET PLYSCORE);         
WRITE_INT(0,270,0,0,OFFSET PLYLIVES); 
WRITE_INT(0,150,0,0,Offset Diff0);
FRAME;
While(NOT GAMEOVER)
If(FLGROCK<10 AND RAND(0,99)>Diff)
ROCK();
END
FRAME;
END  
WRITE(0,125,100,0,"GAME OVER");
SIGNAL(TYPE SHOT,S_KILL); 
SIGNAL(TYPE ROCK,S_KILL);
SIGNAL(TYPE SHIP,S_KILL);
WHILE(NOT KEY(_ALT))
FRAME;
END
END









PROCESS SHIP();

PRIVATE
FLGCOLLISION;
BEGIN
y=100;
x=30;
Graph=2;
Loop 
If(KEY(_control) AND (Mede<3) AND NOT FLGSHOT)
Shot();
END 
IF(KEY(_UP))
y=y-15;
END     
IF(KEY(_DOWN))
y=y+15;
END
GY=y; 
If(Diff>0)
If(Key(_tab))
Diff=Diff-1;
Diff0=100-Diff;
END
END
If(Diff<100)
If(Key(_backspace))
Diff=Diff+1;
Diff0=100-Diff;
END
END
Frame;
END
END      

PROCESS SHOT();

PRIVATE
FLGCOLLISION; 
BEGIN
y=GY;
x=50;
Graph=4;


FLGSHOT=1;
For(x=60;x<320;x=x+50)
FLGCOLLISION = COLLISION(TYPE ROCK);
For(Graph=4;Graph<7;Graph=GRAPH+1)
Frame;
End

IF (FLGCOLLISION)
SWITCH(FLGCOLLISION.SIZE)
CASE 75:
PLYSCORE=PLYSCORE+100;
END
CASE 100:
PLYSCORE=PLYSCORE+50;
END
CASE 200:
PLYSCORE=PLYSCORE+25;
END
END
SIGNAL(FLGCOLLISION,S_KILL);
FLGROCK=FLGROCK-1;
FLGSHOT=0;
SIGNAL(TYPE SHOT,S_KILL);
END


Frame;
end 
FLGSHOT=0;
END
           
PROCESS ROCK();

PRIVATE
FLGSIZE;
Collise;
BEGIN 
y=rand(0,199);
graph=3;
FLGSIZE=RAND(1,3);
SWITCH (FLGSIZE)
Case 1:
Size = 75;
END
CASE 2:
Size = 100;
END
CASE 3:
Size = 200;
END
END

for(x=340;x>0;x=x-5)
Collise = COLLISION(TYPE SHIP);
If((X<60)And(Mede<2))
PLYLIVES=PLYLIVES-1;
IF(PLYLIVES==0)
GAMEOVER=1;
END
SIGNAL(TYPE ROCK,S_kill);
FLGROCK=FLGROCK-1;               
END
    
If((Collise)And(Mede<4))
PLYLIVES=PLYLIVES-1;
IF(PLYLIVES==0)
GAMEOVER=1;
END
SIGNAL(TYPE ROCK,S_kill);
FLGROCK=FLGROCK-1;               
END
If((X<60)And(Mede>2))
plyscore=plyscore+5;
IF(PLYLIVES==0)
GAMEOVER=1;
END
FLGROCK=FLGROCK-1;               
END
FRAME;
END
FLGROCK=FLGROCK-1; 
END         