// The Main HAM Library
#include <mygba.h>
// Function: main()
int main()
{
// Variables
bool key_pressed = 0;
// Initialize HAMlib
ham_Init();
// Initialize the text display system in BGMODE 0
ham_InitText(0);
// Draw some text to the screen
ham_DrawText(0,0,"Hello, World!");
ham_DrawText(10,19,"Press D-Pad To Reset");
// Loop until a direction on the D-Pad is pressed
while(key_pressed == 0)
{
// Check for input
if (F_CTRLINPUT_UP_PRESSED
|| F_CTRLINPUT_DOWN_PRESSED
|| F_CTRLINPUT_LEFT_PRESSED
|| F_CTRLINPUT_RIGHT_PRESSED)
{
// Change key_pressed to true
key_pressed = 1;
}
}
return 0;
} // End of main()
|
Code Explanation
if (F_CTRLINPUT_UP_PRESSED ...)
During the while loop it will do a check to see if up, down,
left or right is pressed. After changing key_pressed to false,
it will end the while() loop and 'reset' the game.
GBA Button |
HAM Equivalent |
UP |
F_CTRLINPUT_UP_PRESSED |
DOWN |
F_CTRLINPUT_DOWN_PRESSED |
LEFT |
F_CTRLINPUT_LEFT_PRESSED |
RIGHT |
F_CTRLINPUT_RIGHT_PRESSED |
START |
F_CTRLINPUT_START_PRESSED |
SELECT |
F_CTRLINPUT_SELECT_PRESSED |
B |
F_CTRLINPUT_B_PRESSED |
A |
F_CTRLINPUT_A_PRESSED |
L |
F_CTRLINPUT_L_PRESSED |
R |
F_CTRLINPUT_R_PRESSED |
NOTE: In order to do diagonal movement, you can use something
like:
if (F_CTRLINPUT_UP_PRESSED && F_CTRLINPUT_LEFT_PRESSED)
There will be an example of this in a later project.
Well, another day, another tutorial. Again, nothing difficult here. |