So far, we've learnt how to get information onto the screen using commands such as PRINT "" and DISPLAY plus some special ones like SHOWSCORE and SHOW BONUS.
As I've mentioned before, writing Speccy games is a challenge due to the lack of memory you have to work with, and unfortunately, text can take up quite a bit. But there are some tools at our disposal that we can carefully deploy to cut down on the amount of memory any game text we want to include, will take up.
MPAGD enables you to store a list of text messages that you can the call back when needed in your game. You can use this feature for pretty much all of the text in your game, in fact, I advise that you do. When I am writing a game I try to minimise the amount of times I use PRINT commands,
Why?
Text messages are RE-USABLE.
PRINT always expects a string of text like:
PRINT "Stinky Dog"
I could use that on our INTRO SCREEN above the control menu to display the title of our game
Maybe, when the player completes the screen we could also display the text "Well Done Stinky Dog!" above the Bonus calculator using
PRINT "Well Done Stinky Dog!"
But by doing so, in the source code for our game we would have the words "Stinky Dog" stored twice...taking up twice the amount of memory.
It might only be a few bytes, but trust me, those bytes could be put to better use.
It would be better, then, to have a list of messages,
"Stinky Dog"
"Well Done"
Then I could I could call the first message whenever I want to display the words Stinky Dog, and the second message whenever I want the words "Well Done"
Store once, use many.
Creating your messages is easy, from the EDITOR menu select "Text Messages"
You'll probably just get a blank document.
At the top, enter:
DEFINEMESSAGES
We need this label so that MPAGD know what follows are messages that we want to store
DEFINEMESSAGES
"STINKY DOG" ; 0
"WELL DONE" ; 1
I've also added a number comment for each line, you don't have to do this, but I strongly advise that you do as it will make it easier for you to identify the correct message later on as our code grows.
As with everything, we start at Zero not one, so the first message is message #0.
The way we tell MPAGD to display a message on the screen is with the command:
MESSAGE x
Where x is the number of the message in the list.
let's give it a test. Open up your INTRO MENU event and add the highlighted code below:
EVENT INTROMENU
BORDER 0
COLOUR 5
LET CONTROL = 99
WHILE CONTROL >= 99
CLS
AT 4 10 ; at line 4 column 10
MESSAGE 0 ; display the game title
AT 8 10
PRINT "1. KEYBOARD"
AT 10 10
PRINT "2. KEMPSTON"
AT 12 10
PRINT "3. SINCLAIR"
AT 14 10
PRINT "4. REDEFINE"
LET CONTROL = 99
WHILE CONTROL = 99
IF KEY OPTION1
LET CONTROL = 0
ENDIF
IF KEY OPTION2
LET CONTROL = 1
ENDIF
IF KEY OPTION3
LET CONTROL = 2
ENDIF
IF KEY OPTION4
CLS
AT 3 9
PRINT "PRESS KEY FOR:"
AT 6 12
WHILE KEY OPTION4
ENDWHILE
PRINT "PAUSE"
DEFINEKEY FIRE3
LET CONTROL = 100
ENDIF
ENDWHILE
ENDWHILE
CLS
OK, run the game and now you should get:
We could, however make our game title a bit more prominent by changing the PRINTMODE. At the moment our text is single character height, the default - which is PRINTMODE 0. But we could change it to double character height using PRINTMODE 1.
As we learnt with COLOUR, INK etc, whatever we change it to will affect all text/numbers on screen unless our code tells it to change to something different. So if we want Stinky Dog to be in double height but the rest single height we need to change it back to PRINTMODE 0 after we've printed STINKY DOG....like this:
EVENT INTROMENU
BORDER 0
COLOUR 5
LET CONTROL = 99
WHILE CONTROL >= 99
CLS
PRINTMODE 1 ; print the following text in double height
AT 4 10 ; at line 4 column 10
MESSAGE 0 ; display the game title
PRINTMODE 0 ; revert back to normal height text.
AT 8 10
PRINT "1. KEYBOARD"
AT 10 10
PRINT "2. KEMPSTON"
AT 12 10
PRINT "3. SINCLAIR"
AT 14 10
PRINT "4. REDEFINE"
LET CONTROL = 99
WHILE CONTROL = 99
IF KEY OPTION1
LET CONTROL = 0
ENDIF
IF KEY OPTION2
LET CONTROL = 1
ENDIF
IF KEY OPTION3
LET CONTROL = 2
ENDIF
IF KEY OPTION4
CLS
AT 3 9
PRINT "PRESS KEY FOR:"
AT 6 12
WHILE KEY OPTION4
ENDWHILE
PRINT "PAUSE"
DEFINEKEY FIRE3
LET CONTROL = 100
ENDIF
ENDWHILE
ENDWHILE
CLS
Now your intro menu will look like this:
Now, let's add an exclamation mark at the end of Stinky Dog. This time I'm not going to store "!" as a text message, I'm going to call it directly using its CHR (Character Number).
But what is it's number? Without going into the technicalities....here is a cheat sheet:
So '!' is character number 33, we can call and display it at the current cursor position on the screen by simply using CHR 33 in our intro menu event like this:.
EVENT INTROMENU
BORDER 0
COLOUR 5
LET CONTROL = 99
WHILE CONTROL >= 99
CLS
PRINTMODE 1 ; print the following text in double height
AT 4 10 ; at line 4 column 10
MESSAGE 0 ; display the game title
CHR 33 ; display a !
PRINTMODE 0 ; revert back to normal height text.
AT 8 10
{rest of code omitted)
Now our intro menu should look like this:
Now let's add some more text messages, open up your text messages file:
DEFINEMESSAGES
"STINKY DOG" ;0
"WELL DONE" ;1
"SCORE" ;2
"FART" ;3
"BONUS" ;4
"PRESS KEY TO START" ;5
"LIVES" ;6
Now let's update our COLLECT BLOCK event, specifically the part that controls what happens when the last bone is collected, AND ADD THE HIGHLIGHTED CODE:
EVENT COLLECTBLOCK
SCORE 100 ; score 100 points when we collect a Bone
AT 0 6
COLOUR 71
SHOWSCORE ; display the score
SUBTRACT 1 FROM B ; decrement the number of bones left on screen
IF B = 0 ; have all Bones been collected?
CLS ; clear the screen
AT 4 6
MESSAGE 1 ; "well done"
CHR 32 ; " "
MESSAGE 0 ; "stinky dog"
CHR 33 ; "!"
COLOUR 65 ; blue on black
AT 7 15
MESSAGE 3 ; "fart"
COLOUR 66 ; red on black
AT 8 15
MESSAGE 4 ; "bonus"
COLOUR 71
AT 10 6 ; at line 10, column 2...
SHOWSCORE ; display the score
DELAY 25 ; wait 1 second
CHR 32 ; " "
CHR 43 ; "+"
CHR 32 ; " "
DELAY 25 ; wait another second
SHOWBONUS ; display the bonus
DELAY 25 ; wait another second
CHR 32 ; " "
CHR 61 ; "="
CHR 32 ; " "
DELAY 25 ; wait another second
ADDBONUS ; add the bonus to the score
ZEROBONUS ; reset the bonus to 0 now we've added it
SHOWSCORE ; display the new score
AT 15 8 ; at line 15 column 8
COLOUR 215 ; flashing white on red
MESSAGE 5 ; "press key to start"
WAITKEY ; wait for a key press
NEXTLEVEL ; if so move to the next screen
ENDIF
Now let's have a play test:
Ok, that's starting to look better.
Now that we also have SCORE and BONUS saved as text messages we can go back to our RESTART SCREEN and replace there PRINT commands with MESSAGES so that we reuse the text and save a few bytes...
EVENT RESTARTSCREEN
RESTORE
READ B ; read the first value of the DATA and put it in B
IF SCREEN >= 1 ; if it is screen 1 or above
REPEAT SCREEN ; then repeat SCREEN-many times
READ B ; read the next value
ENDREPEAT ; so we've found the right B value for the Screen
ENDIF
AT 0 0
COLOUR 4 ; dull green text on black
MESSAGE 3 ; "score"
CHR 58 ; ":"
COLOUR 71 ; bright white text on black
AT 0 6
SHOWSCORE
AT 0 21
COLOUR 6 ; dull yellow on black
MESSAGE 6 ; "lives"
CHR 58 ; ":"
COLOUR 66 ; bright red on black
DISPLAY DOUBLEDIGITS LIVES
;-------------------number of Bones per screen-------------------------
DATA 5 7 3 4 6 9 5 8 5 6 4 8 6 9 3 8 9
DATA 4 7 8 10
It might seem a bit of a pain to do it this way, but trust me, it's worth it in the long run. Every extra byte we save is one we can use to make the game better, so trying to keep things as efficient as possible will reap rewards for us as our game develops.
Another benefit of keeping all your text in the text messages file is it makes it a hell of a lot easier to translate into other languages, rather than rooting through all your code to find lots of PRINT commands and editing them.
We'll look more at text messages as our game starts to take shape, but hopefully the last few tutorials have given you a good understanding of the basics.
Comments