RicEditor tutorial: Create a cannon game

Check for number of lives: Game over

We have to check for number of lives, but now, unfortunately, I see we have forgotten to add the parameter lives. No problem. We can do it now. Start the RicEditor and open the file cannon.ric:
ridEditor

Press the text tool. This window will pop up:
TrextToSprite

Then enter the text Lives:

textLivesAdded

So let’s move it to the upper right corner. Make sure to have some empty space to the right of the text Lives:

TextLivesPlaced

Now it looks like this:

Livefinished

So you can press the Numbox button:

numbox

The following window will pop up:

ParameterWindow

The number of this parameter is 7. Type 7 and press OK. NumboxAdded

Finally move the Numbox to the upper right corner:

sevenplaced

The file is now finished, remember to save it.

But how will our program fix this new parameter? Lets look into the start up loop once again:

startprogramWe must now add a new parameter, and this time it is easiest to add it manually. Move the mouse-pointer over the buildArray command. An arrow will appear:

ExpandBuildArray

Move the mouse downwards to add a new entry. if we move the mouse over the BuildArray command you’ll see the new entry as a blue dot:

Entryadded

We move the mouse pointer to this point, right-click and select create control. Here is the result:

controladded

The name of the control is by default set to element. Just type the name Lives, move the control to a place beside the others, right-click the wire and select Clean up wire. if you’re lucky it looks like this:

NewStartupLoop

We see this control differ from the others. It is because it is viewed as an icon. We can change this by right-clicking and hook of view as icon:

ViewAsIcon

 

After that it looks like the others:
Cosemthicchange

It is important to say that this is just a cosmetically change and won’t affect the program at all. When we create a control the value is by default set to 0. We can change this to 3 (3 lives) in the front panel. Press CTRL+E to open the front panel:

Front_Panel

Let’s first do some simple tidying up on this front panel:.

Front_panel_tied_up

Now it looks better. But we must change the value of lives to 3 (or how many lives do you want?) Press the up arrow key three times or just type 3:

3_entered

So we must make this to be the default value. Right-click the control an select Make current value default:

make current value default

After this is done it is important to save the project (to store the new default value). So we are ready to program the game over loop. We start with inserting a WHILE Structure found in NXT Programming/Structures:

WHILE_Lives

When the bullet hit the ground we will loose a life. This will happen when the Y coordinate for the stone (Ystone) is less than 5. We insert a Less? command found in NXT Programming/Comparison:

LESS_COMMAND

Now it looks like this:

Lessthaninserteed

We have to insert a local variable found at NXT Programming/structures:

localvariable menu

We insert a local variable:

LocalvariableaddedingameoverWe left-click on this one and select Ystone:ystone_Added

Finally we right-click and select Change To Read:

YStone_change_to_read

So we wire the local variable to the upper left corner of the Less? command:

LocalwiredWe right-click the lower left corner and select create constant:

Create_constant_less

We set the value of the constant equal to 5:

constant_equal_5

The last corner of the Less? command is a boolean. We must wire this to a Case structure found in NXT Programming/Structures:

CaseMenu

We insert this and wire it to the left corner of the Less? command:

AddCase

In this CASE structure there is two things we want to do. First, when the stone crashes, we want to play sound, I suggest to use the woops sound. Second we want to reduce the number of lives with one. First we insert the Sound Control command found in NXT I/O:

Add_Sound_control

Inserted it looks like this:

Souncontrol_added

We don’t want to play a tone but a sound file. Press on the purple arrow and select Play Sound File in the drop-down menu:

SelectPlaySoundFile

The command now change to the Play Sound File. Here is the help text for this command:

Help_Text_Sound_File

The upper middle connector is a text for the filename. We right-Click on the middle upper connector and select create constant:

Create_Constant_Play_sound_file

In the constant that appear we type in the filename woops.rso:

woops_rso

We must now fix the number of lives. This would be a kind of countdown. So we insert the command decrement found NXT Programming/Numeric:

decrement

We insert this into the TRUE part of the CASE structure (I have also made the CASE structure wider to get more space):

Decrement_Added

So we need two local variables to READ and WRITE to the local variable Lives. We’ll found it in NXT Programming/Structures. We add one on each side of the CASE structure:

Local_Varaibles_Added

These local variables must be configured. We left-click on the variables and select lives:

select_lives

After this change your program should look like this:

Local_variable_Lives_Configured

By default the local variable is set to Write. The left side one must be changed to Read. We left click on the local variable and select Change To Read:

Change lives to readNow your program should look like this:

lives_configured

We now have to do some wiring:

Wiring_Done

After the wiring you should pay attention to the blue rectangles on the edge of the CASE structure:

Tunnels

These blue rectangles are in LabVIEW called tunnels. We see the one to the right is filled white and not blue as the other. This means it is not wired correct. There is a rule in LabVIEW saying: an outgoing tunnel must be wired in all the cases. We have only wired the True case and not the False case. Press on the right arrow at the top of the CASE structure:

Select_False_Case

We can see that the right-hand side tunnel is not wired (the left hand side is not wired either, but for an incoming tunnel there are no rules saying it must be wired in all the cases):

Casenotwired

To finish the wiring we just wire from tunnel to tunnel:

tunnel_to_tunnel_wired

Now the left hand tunnel is also filled meaning it is correct wired. So, what happens here you might wonder. Well, if Ystone is less than 5, the number of lives (the local variable lives) is subtracted with 1. When the program start Lives equals 3. So when it becomes zero, we want the program to end by setting the local variable game over to TRUE. We add the command Equal To 0 found in NXT Programming/Comparison:

equal_to_0

Inserted:

Equaltozeroadded

When Lives equals zero we want the local variable Game Over to become TRUE. We add local variable, left-click and select game over:Game_Over_Inserted

So we wire the left connector to the local variable Lives and the right connector to the local variable game over. Finally we wire the right connector to the loops conditional terminal:

Lives_fixed

After this our game is finished.

Enjoy!!

The following two tabs change content below.
Svein-Tore Narvestad

Svein-Tore Narvestad

I have used LEGO Mindstorms as a teacher since 1999, and have used it widely. For example, to measure noise in kindergartens, to have the students create lemonade blenders using small pumps connected to the NXT, and in process control with industrial equipment: pneumatics, industrial sensors, etc.