// Includes #include <PA9.h> // Include for PA_Lib
#include "ctype.h" #include <String>
// Graphics Includes // *** Backgrounds *** // gfx2gba -fsrc -m -pBackground.pal -t8 Background.bmp #include "gfx/Background.map.c" #include "gfx/Background.pal.c" #include "gfx/Background.raw.c"
// Function: main() int main(int argc, char ** argv) { // Variables char curr_key; // Gets letter from keyboard std::string name = ""; // Stores Player Name
PA_Init(); // Initializes PA_Lib PA_InitVBL(); // Initializes a standard VBL
PA_InitText(1, 0); // Text system for top screen PA_InitKeyboard(3); // Keyboard system
//PA_LoadSplash(); // PA_Lib splash screen
// Setup top screen PA_LoadPal(PAL_BG1, Background_Palette); PA_LoadSimpleBg(1, 3, Background_Tiles, Background_Map, BG_256X256, 0, 1);
PA_SetTextCol(1, 0, 31, 0); // Set text color to white
// Setup bottom screen BG_PALETTE[0] = PA_RGB(0,0,31); // Set bottom screen to blue PA_ScrollKeyboardXY(25, 103); // Initial keyboard location
// Infinite loop to keep the program running while (1) { PA_UpdatePad();
curr_key = PA_CheckKeyboard(); // Input from keyboard
// If there is an open slot in the name & the character is printable... if ((name.length() != 20) && (isprint(curr_key))) { name.append(&curr_key); // put the character in the open slot... }
// Handle the Backspace key if ((!name.empty()) && (curr_key == PA_BACKSPACE)) { name.erase(name.length()-1, 1); }
PA_OutputSimpleText(1, 6, 14, " "); // Clear the text PA_OutputSimpleText(1, 6, 14, name.c_str()); // Output current name
PA_WaitForVBL(); }
return 0; } // End of main()
|
|
Code
Explanation
#include "ctype.h"
This is needed for isprint().
PA_InitKeyboard(...);
Create the keyboard on the background you pass it.
BG_PALETTE[0] = PA_RGB(...);
This is one way to set the background color of the bottom screen.
You can use BG_PALETTE[512] to set the top screen's color.
PA_ScrollKeyboardXY(...);
Move the keyboard to the specified location.
PA_CheckKeyboard();
Make sure to call this every VBL. It returns the last character pressed.
PA_BACKSPACE
Non-printable characters include PA_BACKSPACE, PA_CAPS, PA_ENTER, and PA_SHIFT.
NOTE: Some characters don't display properly on the screen. For instance, the & and * are kind of weird and { and } don't show at all.
|