Esempio n. 1
0
//////////////////////////////////////////////////////////////////////////////
// Waits until a new key is pressed, ignoring previous maintained keys
//
void wait4KeyPress () {
   // Wait while previous keys are still being pressed
   do { cpct_scanKeyboard(); } while (  cpct_isAnyKeyPressed() );

   // Wait for a new keypress 
   do { cpct_scanKeyboard(); } while ( !cpct_isAnyKeyPressed() );
}
Esempio n. 2
0
/*MENU*/
int menu(){
   u8* memptr;
   int init = 50;
   int pushed =0;
   int cont =0;
   cpct_clearScreen(0);

   memptr = cpct_getScreenPtr(VMEM,10,10);
   cpct_drawSprite(portada1,memptr,60,60);

   //Opciones
   memptr = cpct_getScreenPtr(VMEM,20,90);
   cpct_drawStringM0("Nueva Partida",memptr,1,0);

   memptr = cpct_getScreenPtr(VMEM,20,110);
   cpct_drawStringM0("Creditos",memptr,1,0);

   memptr = cpct_getScreenPtr(VMEM,20,130);
   cpct_drawStringM0("Constroles",memptr,1,0);

   memptr = cpct_getScreenPtr(VMEM,20,150);
   cpct_drawStringM0("Salir",memptr,1,0);

    /*memptr = cpct_getScreenPtr(VMEM,18,180);
   cpct_drawStringM0("Pulsa Intro",memptr,4,5);*/

   //Indicador
   while(1){

      cpct_scanKeyboard();
      if(cpct_isKeyPressed(Key_CursorDown) && cont > 150){
        cpct_drawSolidBox(memptr, 0, 2, 8);
        if(pushed<3) pushed ++;
        cont =0;
      }
      if(cpct_isKeyPressed(Key_CursorUp) && cont > 150){
        cpct_drawSolidBox(memptr, 0, 2, 8);
        if(pushed>0) pushed --;
        cont = 0;
      }

      switch (pushed){
        case 0: init = 90;break;
        case 1: init = 110;break;
        case 2: init = 130;break;
        case 3: init = 150;break;
      }
      memptr = cpct_getScreenPtr(VMEM,15,init);
      cpct_drawSprite(marcador,memptr, 2, 8);
      if(cpct_isKeyPressed(Key_Space)){
        switch (pushed){
        case 0: return 1;break;
        case 1: return 2;break;
        case 2: return 3;break;
        case 3: return 0;break;
      }
      }
      cont++;
   }
}
Esempio n. 3
0
/////////////////////////////////////////////////////////////////
// checkUserInputAndPerformActions
//    scans the keyboard and checks whether the user has pressed
// any action key or not. When the user presses an action key, 
// the corresponding action is performed.
//
void checkUserInputAndPerformActions() {
   // Scan the keyboard for user keypresses
   cpct_scanKeyboard();

   // Perform checks only when the user has
   // pressed at least one key
   if(cpct_isAnyKeyPressed()) {
      // Get current (x,y) coordinates of the cursor 
      u8 x = cursor_getX();
      u8 y = cursor_getY();

      // Check if the key pressed is one of the valid keys and
      // if sanity conditions are met

      // CURSOR_UP or CURSOR_DOWN (Only one at a time)
      //   Perform required action, if the cursor is not at the
      // edge of the map already.
      if (cpct_isKeyPressed(Key_CursorUp) && y > 0)
         cursor_move(DIR_UP);
      else if (cpct_isKeyPressed(Key_CursorDown) && y < MAP_HEIGHT-1)
         cursor_move(DIR_DOWN);

      // CURSOR_LEFT or CURSOR_RIGHT (Only one at a time)
      //   Perform required action, if the cursor is not at the
      // edge of the map already.
      if (cpct_isKeyPressed(Key_CursorLeft) && x > 0)
         cursor_move(DIR_LEFT);
      else if (cpct_isKeyPressed(Key_CursorRight) && x < MAP_WIDTH-1)
         cursor_move(DIR_RIGHT);

      // SPACE (change tile) or ESCAPE (clear map)
      //    Perform one of these actions if corresponding key is pressed
      if (cpct_isKeyPressed(Key_Space)) 
         map_changeTile(x, y);
      else if (cpct_isKeyPressed(Key_Esc))
         map_clear();

      // Always redraw the cursor after any of the above actions
      cursor_draw();
   }
}