PROGRAM bioshoot;  //That's it's name.
  
GLOBAL
	spawny;                     //random location for enemy spawns.
	energy=100;                 
	bulletcount=0;              //how many bullets are on screen.  
	can=0;                      //variable for being able to shoot
	shoot_wav;                  //sound when shooting
	explosion_wav;
	fireball_wav;
	wave_wav;
	waveshoot=3;
	score;
	pausedtext;
	life=3;
  gp32=FALSE;

BEGIN                         //This Stuff happens once.                 
	SET_FPS(30,2);  //30 frames per second, maximum 2 frameskip.
	SET_TITLE("BioShoot");
	SET_MODE(320,240,16);  //GP32 resolution, 16bpp.
	LOAD_FPG("shoot.fpg");  //load the graphics so we can use them.
	put_screen("shoot.fpg",20);  //loads the background
	WRITE_INT(0,45,230,0,&energy);  //This shows the player's energy in the bottom left corner.
	//WRITE_INT(0,300,230,0,&bulletcount);  //This shows how many bullets exist (player and enemy).       
	WRITE_INT(0,170,230,0,&waveshoot);
	write(0,130,230,0,"Waves");
	write(0,0,230,0,"Health");  //Just writes "Health" in the bottom left corner of the screen       
	write(0,3,0,0,"Lives");
	WRITE_INT(0,45,0,0,&life);
	write(0,245,230,0,"Score");
	WRITE_INT(0,285,230,0,&score);
	ship(30,120);  //Creates a "ship" process, 160 and 220 are for x and y.
	//waveicon(130,232);  
  shoot_wav = LOAD_WAV("laser.wav");  //loads shooting sound
  explosion_wav = LOAD_WAV("explosion.wav");
  fireball_wav = LOAD_WAV("bomb2.wav");
   
LOOP  
  //if(file_exists("\GPMM\bioshoot.fxe"))
    //gp32=true;end
  //if (not(file_exists("\GPMM\bioshoot.fxe")))
    //shoot_wav = LOAD_WAV("laser.wav");
    //explosion_wav = LOAD_WAV("explosion.wav");end
    //fireball_wav = LOAD_WAV("bomb2.wav");end  //basic way to improve speed on gp32, 
    //it wont load the sound if it's on a gp32 to increase memory space, if you want to have sound just comment all this section and uncomment     
    //the shoot_wav, explosion_wav and fireball_wav above the LOOP command
FRAME;  
END
END  


//Now we define our processes, like bullets, enemies, etc.


PROCESS ship(x,y)  //Player ship
Private
  level;
BEGIN
	graph = 12;  //Graphic number 1 in the FPG we loaded.
LOOP                                     
	spawny=RAND(230,10);  //Sets spawnx to a random number between 10 and 310, used for x location.
	if(RAND(0,1000)<65)enemy1(310,spawny);end  // 65/1000 chance to spawn an enemy.
	if(RAND(0,1000)<2)big(310,spawny);end  // 1/1000 chance to spawn enemy 2 
	level+=1;
	if(key(_left))x-=7;end  //left,
	if(key(_right))x+=7;end  //right,
	if(key(_up))y-=7;end  //up and
	if(key(_down))y+=7;end  //down keys. "y+=7" is the same as writing "y=y+7"
	if(key(_control))
		(can+=1);end  //B button adds 1 to the var "can" 
	if(can>4)bullet(x,y);end  //if can is greater than 5 this creates a bullet, just stops a string of bullets coming out 
    
	if(key(_backspace)) //fires wave
	   while(key(_backspace))frame;end
	   if(waveshoot>0);
	   waveshoot--;
	   wave(x,160);end
	end
  if(key(_Space))  //exits game
     exit("Exiting",0);
  end
  if(key(_Enter))  //pause game
     pause(120,160);end
  if(energy<0)  //takes life if health reaches 0
     life--;
     energy=100;
     x=30;
     y=120;
     signal(type enemy1,s_kill);
     signal(type ebullet1,s_kill);
     signal(type big,s_kill);
     signal(type ebullet2,s_kill);
     signal(type bigebullet1,s_kill);
     signal(type bigebullet2,s_kill);
   end 
  if(life<1)  //if life goes below 1 ends game
    gameover(160,120);end
	//if(key(_Tab))  //start shield
   // while(key(_Tab))frame;end
	  //shield(x,y);
  //end
	if(COLLISION(TYPE ebullet1));
	  blastright(x,y);end	
  if(x>140)x=140;end //parameters for ship
	if(x<10)x=10;end
	if(y>220)y=220;end
	if(y<10)y=10;end
 FRAME;  //You need one of these in each process.
END  //Ends the loop
END  //Ends the PROCESS/BEGIN


PROCESS enemy1(x,y)  //Basic enemy
BEGIN
graph=2;  //Graphic number 2.
LOOP
	x-=4;  //Moves across the screen 4 pixels every frame.
	if(RAND(0,100)<10)ebullet1(x,y);end  // 10/100 chance to shoot, sets bullet's location to own.
	if(RAND(0,1000)<5)ebullet2(x,y);end  //5/1000 chance to shoot ebulltet2
	if(COLLISION(TYPE bullet));
	  score+=10;
		blast(x,y);
		return;end  //If the enemy touches a player bullet, kill it (return).
	if(COLLISION(TYPE ship)); //if ship hits the enemy energy goes down -2
		energy-=2;
	end
	if(COLLISION(TYPE wave));  //if wave hits enemy score goes up 10 and kills enemy
	  score+=10;
	  return;end	
  if(x<5)return;end  //If the enemy goes off screen at the bottom, kill it.
FRAME;
END
END 



PROCESS ebullet1(x,y)  //Enemy bullet
BEGIN
	bulletcount++;
	graph=4;
LOOP
	x-=5;  //Moves down the screen at 5 pixels per frame 
	if(COLLISION(TYPE ship))  //If it touches the player ship,
		energy--;  //reduce energy by 1,
		bulletcount--;  //bulletcount by 1,
		return;end  //then kill it.
  if(COLLISION(TYPE wave));  //if wave hits ebullet destroy it
	  return;end	    
  if(x<-10)bulletcount--;return;end  //If it goes off screen, reduce bulletcount by 1 and kill it
  if(COLLISION(TYPE shield))
          return;end
FRAME;
END
END


PROCESS ebullet2(x,y)
BEGIN
	graph=7;
  PLAY_WAV(fireball_wav,0);
LOOP
	x-=8;  //moves 8 pixels across per frame
	IF(COLLISION(TYPE ship))
		energy-=5;
		bulletcount--;
	  return;end  //if collision with ship energy-5 and bulletcount-1, then destroy it
	IF(x<-10)bulletcount--;
	  return;end  // if it goes off the left side of the screen destroy it
  if(COLLISION(TYPE wave));
	  return;end
  if(COLLISION(TYPE shield))
          return;end	
FRAME;
END
END


PROCESS big(x,y)//big enemy
Private
	change=0;  //local variable change
	bheightup;
	bheightdown;
BEGIN
	graph=8;
	bheightup=(y+16);
	bheightdown=(y-16);
LOOP
	x-=2;
	if(RAND(0,100)<10)
	  bigebullet1(x,bheightup);
	  bigebullet1(x,bheightdown);end  // 10/100 chance to shoot, sets bullet's location to own.
	if(RAND(0,1000)<5)bigebullet2(x,y);end  //5/1000 chance to shoot bigebulltet2
	
	if(collision(Type bullet))  //if big enemy gets hit more than 3 times destroy the big enemy, sketchy at best
		change+=1;
	  while(change<0)frame;end
		if(change>3)
		  change=0;
		  score+=20;
		return;end
	end
  
  if(COLLISION(TYPE wave));
	  return;end	
FRAME;
END
END


PROCESS bigebullet1(x,y)
BEGIN
bulletcount++;
graph=9;
LOOP
	x-=5;  //Moves down the screen at 5 pixels per frame 
	if(COLLISION(TYPE ship))  //If it touches the player ship,
		energy-=2;  //reduce energy by 2,
		bulletcount--;  //bulletcount by 1,
		return;end  //then kill it.
	if(x<-10)bulletcount--;return;end  //If it goes off screen, reduce bulletcount by 1 and kill it.
  if(COLLISION(TYPE wave));
	  return;end	
FRAME;
END
END


PROCESS bigebullet2(x,y)
BEGIN
graph=10;
LOOP
	x-=8;
	IF(COLLISION(TYPE ship))
		energy-=10;
		bulletcount--;
		return;end  //if collision with ship energy-10, bulletcount-1 and then destroy it
	IF(x<-10)bulletcount--;return;end
  if(COLLISION(TYPE wave));
	  return;end	
FRAME;
END
END 


PROCESS bullet(x,y)  //Player bullet, x and y get set by the location of the ship.
BEGIN
bulletcount++;  //Makes bulletcount go up by one, only once because it's not in the LOOP. 
graph=3;  //Graphic number 3.
can=0;
play_wav(shoot_wav,0);
LOOP
	x+=8;  //Moves 8 pixels up every frame.
	if(x>318)bulletcount--;
		can=0;
		return;end
		//If the bullet is off the side of the screen it kills the process and can=0
	if(COLLISION(TYPE BIG))return;end
FRAME;
END
END

PROCESS wave(x,y)
BEGIN
  graph=13;
  wave_wav = LOAD_WAV("wave.wav");
  PLAY_WAV(wave_wav,0);
LOOP
x+=10;
if(x>319)  //when wave goes off the screen unload the sound and kill the process
 UNLOAD_WAV("wave.wav");
 return;end
FRAME;
END
END


//Process waveicon(x,y) //unnecessary may be worked on in a later version
//Begin  
  //graph=15;
//Loop
  //WRITE_INT(0,140,230,0,&waveshoot);
//FRAME;
//END
//END  


PROCESS shield(x,y)  //shield process, will be infront of ship, reflect certain bullets, to be completed
BEGIN
  graph=18;
LOOP
  x=x+10;
  while (timer<120)  //after 4 seconds the shield is destroyed
  timer+=1;frame;end  	
  if (timer>120)return;end 
FRAME;
END
END

Process gameover(x,y)
Begin
  graph=14;
  LET_ME_ALONE();
  DELETE_TEXT(0);
  write(0,87,230,0,"Press SELECT to quit");
  write(0,120,190,0,"Score is ");
  write_Int(0,180,190,0,&score);
Loop
  if(key(_Space))  //exit game
    exit("Exiting",0);end
if(!file_exists("bioscores.dat"));
    save("bioscores.dat",score);end    
FRAME;
END
END     


Process pause(x,y);
private
  st_pressed=0; done=0; freezed=0;
  text1;  
Begin
  loop
    if(key(_enter))st_pressed=1;end;
    if(not key(_enter) and st_pressed==1)
      //this process remembers if the game is paused or not:
      //if freezed==0 every process is running and gets freezed here
      if(freezed==0 and done==0)
        signal((type ship),s_freeze); //process 1 = a process from your game
        signal((type enemy1),s_freeze); //another process from your game
        signal((type ebullet1),s_freeze);
        signal((type ebullet2),s_freeze);
        signal((type big),s_freeze);
        signal((type bigebullet1),s_freeze);
        signal((type bigebullet2),s_freeze);
        signal((type bullet),s_freeze);
        signal((type wave),s_freeze);
        text1 = write(0,135,120,0,"Paused");
        freezed=1; done=1;
        
        //If (IS_PLAYING_WAV(shoot_wav))    
          //PAUSE_WAV(shoot_wav);end
        //If (IS_PLAYING_WAV(explosion_wav))
          //PAUSE_WAV(explosion_wav);end
        //If (IS_PLAYING_WAV(fireball_wav))
          //PAUSE_WAV(fireball_wav);end
        //If (IS_PLAYING_WAV(wave_wav))
          //PAUSE_WAV(wave_wav);end      
       end;
       

      //if freezed==1 every process is freezed and gets woken up here
      if(freezed==1 and done==0)
        signal((type ship),s_wakeup); //same as above
        signal((type enemy1),s_wakeup);
        signal((type ebullet1),s_wakeup);
        signal((type ebullet2),s_wakeup);
        signal((type big),s_wakeup);
        signal((type bigebullet1),s_wakeup);
        signal((type bigebullet2),s_wakeup);
        signal((type bullet),s_wakeup);
        signal((type wave),s_wakeup);
        delete_Text(text1);
        freezed=0; done=1;
       end;
      done=0; st_pressed=0;
     end

frame;
end   
end


Process blast(x,y)
PRIVATE
time;	
Begin
  graph=19;
  PLAY_WAV(explosion_wav,0);
Loop  
  while (time<15)  //after half a second the blast is destroyed
  time+=1;
  frame;end  	
  if (time>14)return;end   
FRAME;
END
END


Process blastright(x,y)
Private
time;
Begin
  graph=17;
Loop
  while (time<10)
  time+=1;
  frame;end
  if(time>9)return;end
FRAME;
END
END

    
//Many thanks to Daniel Parker who made the ship graphics, the shield, the blast and also helped with some ideas along the way. 
       