Coding with FUZE BASIC – Part 2
Moving on from the previous FUZE BASIC tutorial, let’s expand everything you’ve done so far and see if we can apply it to something other than counting numbers or asking for someone’s name. In the grand tradition of BASIC programming, let’s create a text adventure.
A text adventure game is an ideal genre to explore your BASIC skills in. There are variables, events, user input, counting and if you want, even a few graphics here and there to inject and use.
You May Also Like:
The printat command will specify a location on the screen to display the text using x,y.
This prints the message whilst waiting for the specific key to be pressed on the keyboard: the Spacebar.
The Goto command goes to a line number and continues with the code. Here you can use it to start an end of game routine.
This closes the If statements, then goes to line 29 (if you pressed the Green button) to continue the game, skipping the end of game routine.
PALE BULBOUS EYES STARE AT YOU…
A text adventure game is an ideal genre to explore your BASIC skills in. There are variables, events, user input, counting and if you want, even a few graphics here and there to inject and use.
You May Also Like:
Step 1
Enter the Program Editor and begin with a simple clear screen, as it’s always a good way to start. What we need to do is set some basic parameters first, so start with the number of lives a player has, for example 3.ClsLet lives=3
Coding with FUZE BASIC – Part 2 |
Step 2
Now you can introduce the game and let the player know how many lives they currently have. You can do this by adding the following to the code:
Printat (41,0); “You have “; lives; “ lives left.” Printat (0,0); “Welcome to Cosmic Adventure!”
The printat command will specify a location on the screen to display the text using x,y.
Step 3
Let’s add a way whereby the user is required to press a key to continue, this way you can leave instructions on the screen for an indefinite period:
Printat (15,15); “Press the Spacebar to continue…” While inkey <> 32 cycle Repeat
This prints the message whilst waiting for the specific key to be pressed on the keyboard: the Spacebar.
Step 4
Now we can start the ‘story’ part of the adventure:
Cls Print “You awake to find yourself in an airlock onboard a space station.” Input “There are two buttons in front of you: Green and Red. Which do you press?”, button$ If button$=”Red” then Let lives=lives-1 Print “You just opened the airlock into space. You are dead!” Print “You now have “;lives; “ lives left.”
Step 5
Now add:
If lives=0 then goto 25 Print “Press the Spacebar to try again.” While inkey <> 32 cycle Repeat Goto 8 Else Print “The door to the interior of the space station opens, lucky for you.”
The Goto command goes to a line number and continues with the code. Here you can use it to start an end of game routine.
Step 6
Let’s finish this routine off with:
Endif Endif Goto 29 Print “Sorry, you are dead. End of game. Press Spacebar to start again.” While inkey <> 32 cycle Repeat Goto 1
This closes the If statements, then goes to line 29 (if you pressed the Green button) to continue the game, skipping the end of game routine.
Step 7
From line 25 we start the end of game routine as stated on line 15, goto 25. This only works if the variable lives equals 0; the player’s lives have run out. It prints a ‘sorry you are dead’ message and asks to press the Spacebar to start the game all over again from line 1, the goto 1 part.Step 8
We can now continue the game from line 29, adding another press the Spacebar routine, followed by a clear screen ready for the next part of the adventure.
Print “Press the Spacebar to continue…” While inkey <> 32 cycle Repeat Cls
0 Response to "Coding with FUZE BASIC – Part 2"
Post a Comment