Hi folks.
I'm targeting cpctelera users with this question, but I'm open to all suggestions!
:)
I'm frantically trying to put a high score table into my game, but I'm not sure how to do it.
The table itself, and displaying it, are all fine.
It's just the bit where the player can enter their name that has me stumped.
I'm planning on allowing all 10 numbers, 26 letters (regardless of case, they will be treated as uppercase), and the DEL key to correct mistakes.
Is the easiest way simply to have a loop similar to WaitForKeypress, that reads the keyboard status, and then acts on each keypress individually?
For example (this is pseudocode):
- if keypressed_keyA then print A
- else if keypressed_keyB then print B
- else if ETC ETC ETC
- else if keypressed_keyDEL then delete rightmost character
Thanks for any help.
:)
Hi ervin,
Something similar was asked on amstrad.es some time ago. I suggested using this code for reading keys:
cpct_keyID getKey() {
// Traverse the keystatus vector from end to start, to help
// the compiler better optimize this code
u8 i = 10, *keys = cpct_keyboardStatusBuffer + 9;
u16 keypressed;
// Wait for a keypress
do { cpct_scanKeyboard(); } while ( ! cpct_isAnyKeyPressed() );
// Analyse which key has been pressed and return its keycode
do {
// We analyse groups of keys byte by byte (8 by 8, 1 bit per key)
// If no single key is pressed in this group, all bits will be on, and the byte will be 0xFF
// Then, XORing the byte with 0xFF will result in 0 unless some key from this group is pressed
keypressed = *keys ^ 0xFF;
if (keypressed)
return (keypressed << 8) + (i - 1); // Convert to cpct_keyID format: 8 first bits = key mask, 8 next bits, keyboard row (0-9)
--keys;
} while(--i);
// No key was pressed
return 0;
}
This function waits for a keypress and returns the keycode when one is pressed. It's quite the same as the if/else approach, but done lowlevel and optimised :) .
Hope this solves your problem ;)
That's brilliant!
Thanks so much @ronaldo (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1227).
Also, thanks for taking the time to reply (and so quickly!).
That's very kind of you.
You're welcome, man :)
You should pay me with a great game to enjoy on my CPC ;D
Quote from: ronaldo on 00:30, 08 October 15
You should pay me with a great game to enjoy on my CPC ;D
That is most certainly what I plan to do. ;D
Hopefully it's something that hasn't really been seen on the cpc before!
Quote from: ervin on 23:42, 07 October 15
I'm targeting cpctelera users with this question, but I'm open to all suggestions!
:)
A PM to @ronaldo (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1227) usually gets a quick reply should you need it! :)
Quote from: AMSDOS on 09:09, 08 October 15
A PM to @ronaldo (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1227) usually gets a quick reply should you need it! :)
Yes indeed, but I don't want to bother him too often, as he is very busy.
:)
Also, he has helped me so, so much, and I absolutely don't want to take advantage of his generosity.
Heck, just
releasing cpctelera has been a great help to the community.
Yes, very busy answering PMs. Haha. :laugh: