コード例 #1
0
ファイル: main.c プロジェクト: lronaldo/cpctelera
//////////////////////////////////////////////////////////////////////////////
// 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() );
}
コード例 #2
0
ファイル: main.c プロジェクト: AugustoRuiz/cpctelera
/////////////////////////////////////////////////////////////////
// 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();
   }
}