#include<allegro.h>
#include"keyconf.h"

extern unsigned char k_up[4];
extern unsigned char k_left[4];
extern unsigned char k_right[4];
extern unsigned char k_shoot[4];

int pkey=0;

int check_key()
{
 for(int n=0;n<128;n++)
 {
  if(key[n]) return(n);
 }
 return(FALSE);
}

int set_keys()
{
 int ktemp;
// while(check_key());
 clear_keybuf();
 for(int n=0;n<4;n++)
 {
  clear(screen);
  textprintf(screen,font,80,10,255,"PLAYER %i press key (ESC quits) for",n+1);
  textprintf(screen,font,100,20,255,"thrust");
  while(!check_key());
  pkey=check_key();
  while(check_key());
  if(pkey==KEY_ESC) return(-1);
  k_up[n]=pkey;
  textprintf(screen,font,100,40,255,"turn left");
  while(!check_key());
  pkey=check_key();
  while(check_key());
  if(pkey==KEY_ESC) return(-1);
  k_left[n]=pkey;
  textprintf(screen,font,100,50,255,"turn right");
  while(!check_key());
  pkey=check_key();
  while(check_key());
  if(pkey==KEY_ESC) return(-1);
  k_right[n]=pkey;
  textprintf(screen,font,100,60,255,"fire");
  while(!check_key());
  pkey=check_key();
  while(check_key());
  if(pkey==KEY_ESC) return(-1);
  k_shoot[n]=pkey;
 }
 clear_keybuf();
 return(0);
}
