{"id":1454,"date":"2013-10-28T09:58:26","date_gmt":"2013-10-27T22:58:26","guid":{"rendered":"http:\/\/legoeng.local\/?p=1454"},"modified":"2017-12-14T15:54:27","modified_gmt":"2017-12-14T04:54:27","slug":"riceditor-tutorial-create-a-cannon-game","status":"publish","type":"post","link":"http:\/\/legoeng.local\/riceditor-tutorial-create-a-cannon-game\/","title":{"rendered":"RicEditor tutorial: Create a cannon game"},"content":{"rendered":"

Before you start<\/h2>\n

This post is a tutorial on how to work with “RIC” image files to create a simple game using the NXT display. For an example of what the finished game will look like and an introduction to RIC files, please see: Create your own games with “RIC” files<\/a>.<\/p>\n

To start making RIC-based games on the NXT, LVLM (LabVIEW for LEGO MINDSTORMS) must be installed on your computer. Then you must download the\u00a0RicEditor<\/a>\u00a0This file is a zip file, so you have to extract it. The extracted file to run isi RicEditor.llb. A “.llb” file is a LabView LiBrary file. This file consists of many files. When you double-click this file, the following window will appear after a while:<\/p>\n

 <\/p>\n

\"startriceditor\"<\/a><\/p>\n

Here you can see all the files in this library. Double-click the first file (SN_NXTRICEdtior.vi). If everything is OK, you will get the start window for the RicEditor:
\n
\"how-1\"<\/a><\/p>\n

Congratulations, you are ready to start creating RIC files!<\/p>\n

<\/p>\n

How to create a RIC file<\/h2>\n

We are now going to demonstrate how to make a RIC file for a shooting game. Here we have three objects: a cannon, a bullet and a falling stone. First we start to draw the three moving objects:<\/p>\n

\"how-1\"<\/a><\/p>\n

As you can see there are a total of 9 layers that make these three objects:<\/p>\n

    \n
  1. Circle: this is the big circle on the top.<\/li>\n
  2. Sprite: The circle is filled, and this layer is the fill.<\/li>\n
  3. Copybits: This layer ensures the fill of the circle will be shown on the screen.<\/li>\n
  4. Circle: The small circle which is the bullet.<\/li>\n
  5. These three lines makes up the triangle that represents the cannon.<\/li>\n
  6. “<\/li>\n
  7. “<\/li>\n
  8. Sprite: The fill of the triangle (cannon).<\/li>\n
  9. CopyBits: This layer ensures the fill of the triangle (cannon) will be shown on the screen.<\/li>\n<\/ol>\n

    The two layers Sprite and CopyBits may be a bit confusing. But in a RIC file only circles, rectangles and lines will be shown directly. Other objects can be created by using a combination of a sprite and a copybit. A sprite is a bitmap. The total size of a sprite is 1024X512 pixels, but in this program the size is limited to the size of the NXT screen (100X64). So, when you draw with the commands Pencil, text and fill, these pixels is added as bits in the sprites bitmap. The program will then create a copybit, which will copy the bits from the sprite over to the LCD display memory. So let’s select the first sprite layer:<\/p>\n

    \"how-2a\"<\/a><\/p>\n

    The Sprite (fill) turns red. Notice the circle outside is NOT red. It is an own layer. We now select the CopyBits layer below:<\/p>\n

    \"how-2b\"<\/a><\/p>\n

    Here are two important things to notice:<\/p>\n

      \n
    1. You can see a red dashed rectangle. This is the border of the CopyBits.<\/li>\n
    2. Some of the filled circle is outside the rectangle. This is of course the circle layer.<\/li>\n<\/ol>\n

      To summarize this stone consist of three layers: the Circle, a sprite and the CopyBits.<\/p>\n

      If we want to move the stone, we need to move both the fill and the circle at the same time. This is a bit cumbersome to do, so now we are going to make a custom copybit for the three objects on the screen (the bullet, stone and the cannon). Let’s start with the cannon. Press the create copybit button:<\/p>\n

      \"how-2c\"<\/a>This window will pop up:<\/p>\n

      \"how-2\"<\/a><\/p>\n

      We want to copy only a part of the screen so we select Copy Bits.Another window will appear:<\/p>\n

      \"how-3\"<\/a><\/p>\n

      We move the mouse pointer to the upper left corner of the cannon, we left click and drag out to select the cannon (a red rectangle shows which bits we have selected to copy).<\/p>\n

      The next part needs an explanation. The Destination X and Destination Y is used to set the X and Y coordinates for this new object (the copybit). But we have to select whether it should be constant or a parameter.<\/p>\n

      If we select constant we set the actual coordinate in the blue indicator. Then we have no chance to change the coordinate in our program afterwards.<\/p>\n

      If we select parameter it is possible to change the parameter later in our program. The value in the blue indicator then represents which parameter we want to use. In a RIC file you can have as many as 16 parameters numbered from 0 to 15. We select parameter 0 for the Y coordinate of the cannon and parameter 1 for the X coordinate of the cannon.<\/p>\n

      It is very<\/i><\/b> important<\/b> to remember what each parameter are controlling so we prefer you to write it down on a paper or in a i.e. word processor. We are not going to show how to change the value of the parameters right now, but leave it to the programming part. We press Ok and return to the Editor again:<\/p>\n

      \"how-4\"<\/a>
      \nBut look, what has happened to the layers list? If we count, the number of layers has changed from 9 to 6! Three are gone! What has happened? To understand this let’s take a closer look at the two layers list:<\/p>\n

       <\/p>\n

      \"layers<\/a><\/p>\n

      When we create a custom copybit, a new sprite is added. The size of this sprite equals the size of the screen. So the program find out what objects are inside the copybit. All objects inside will be removed (deleted) from the layers list. In this case 5 layers. Finally the CopyBits we have created will be added. Now let’s copy the bullet.Press the create CopyBits button and select CopyBits.<\/p>\n

      The window below will pop up:<\/p>\n

      \"bulletcopybit\"<\/a><\/p>\n

      Now we select the \u201dbullet\u201d in the picture with the mouse and select parameters 2 and 3 for the X and Y coordinates. We do the same with the \u201cfalling stone\u201d as shown below:<\/p>\n

      \"copystone\"<\/a><\/p>\n

       <\/p>\n

      Now all our objects are copied to the file.Lets go back to the RIC Editor and select the layer Sprite. All the objects included in this layer will turn red when we select the layer. As we can see everything on the screen is in the layer:<\/p>\n

      \"allcopybitsmade\"<\/a><\/p>\n

      But what is missing? Yes of course a text \u201cscore\u201d to tell us our score. Enter the text tool and we get this window:<\/p>\n

      \"texttool\"<\/a><\/p>\n

      Enter the text score and select a useful font. I prefer using small font with size 10. It is also possible to move the text as I have done (top left corner):<\/p>\n

      \"texttool<\/a><\/p>\n

      Press the OK button and we come back to the Editor:<\/p>\n

      \"textadded\"<\/a><\/p>\n

      Notice we’ve got a Sprite and CopyBits for the text as we got when we filled the triangle and the circle. Finally we want a number on the screen telling us our score. Press the Num Box button:<\/p>\n

      \"numbox\"<\/a><\/p>\n

      The following window will pop up:<\/p>\n

      \"select<\/a><\/p>\n

      We have used parameters 0 to 5 so we must use number 6 for this one. We press OK and come back to the Editor:
      \n
      \"Numboxplaced\"<\/a><\/p>\n

      The NumBox will automatically be placed in the lower left corner (coordinates (0,64)). But at this time we want to place it next to the text Score. We select the move layer tool. it is important of course to select the layer NumBox before you do this:<\/p>\n

      \"move<\/a><\/p>\n

      Now your picture should look something like this:<\/p>\n

      \"finally\"<\/a>
      \nThe RIC file is now finished. Now let’s <\/span>see how to view the RIC file<\/span>.<\/p>\n

      <\/p>\n

      How to view the RIC file<\/h2>\n

      While we have been making our RIC file, there has been a small preview window on the screen. But it is important to know that this is NOT a NXT screenshot. It is in fact a LabVIEW picture. But we can both watch the picture on the NXT screen and test the parameters for the file. Before we start we have to connect the NXT brick to the PC. Then we press the view button in the RicEditor:<\/p>\n

      \"viewbutton\"<\/a><\/p>\n

      You’re asked to save the file:<\/p>\n

      \"savericfile\"<\/a>After pressing OK a file dialogue will pop up:<\/p>\n

      \"saveas\"<\/a><\/p>\n

      We select a file name (i.e. cannon.ric) and press save. We\u2019ll get a new window as shown below:<\/p>\n

      \"view-1\"<\/a><\/p>\n

      Note this picture is NOT<\/strong> the same LabVIEW picture as is on the main program. This is in fact a screenshot of the NXT’s Screen. If you look at the NXT’s screen you will see they are identical. But this picture does not make any sense. Where are our objects (bullet, cannon and falling stone)? And why is the score -4090?<\/p>\n

      Well, if you look in the parameters list you can see they are all greyed. This means the NXT is not receiving any value. Let’s start adding values to the parameters. We start with parameter 0 and 1. Setting them both to 1, and then the cannon will appear on the screen:<\/p>\n

      \"view-2\"<\/a><\/p>\n

      Continuing with parameter 2 and 3 the bullet will appear:<\/p>\n

      \"view-3\"<\/a><\/p>\n

      And finally, adding parameter 4 and 5 we get the falling stone:<\/p>\n

      \"view-4\"<\/a><\/p>\n

      Setting parameter 6 to 2 and the score is also OK:<\/p>\n

      \"view-6\"<\/a><\/p>\n

      But what is wrong now? Why can’t we see the cannon and the bullet? The answer is layers. Press the Done button and go back to the main window for the RicEditor:<\/p>\n

      \"checklayers\"<\/a><\/p>\n

      Layers 2-4 are CopyBits for the cannon, bullet and falling stone respectively. When the objects are drawn on the screen they are drawn in layers, meaning i.e. layer 3 (the bullet) comes over layer 2 (the cannon) when they have the same coordinates (or more exactly when they, in some way touch each other).<\/p>\n

      This is shown more clearly in the figure below:<\/p>\n

      \"view-9\"<\/a><\/p>\n

      Here we see the bullet is lying on a layer over the cannon. To solve this problem these two layers must swap in the layers list. This can be done by using the move up or move down buttons:<\/p>\n

      \"moveup-down\"<\/a><\/p>\n

      We first select the second layer element (the bullet). So we press the move down button. The bullet is now longer down in the layers list than the cannon. So the cannon will be in front of the bullet. Our new picture is shown below:<\/p>\n

      \"allinpalce\"<\/a><\/p>\n

      Notice the values for the bullets coordinates (parameter nr. 2 and 3). The values are 18 and 40 where 18 is the y coordinate. if we now change this to 0, the bullet will disappear, or more exactly it will be behind the cannon:<\/p>\n

      \"bulletbehind\"<\/a><\/p>\n

      The RIC file is now finished so please save your file. But before we start with the programming, it is a good idea to set the start values for the parameters. This will ensure the objects start at the same position every time we start the game. When we start programming, we are going to use local variables. This means we have to give each parameter a name. You could of course choose what ever you want, but it is best to use logical names, and don’t select too long names. In the table below we give suggestions for this RIC file:
      \n
      \"parameters\"<\/a><\/p>\n

      We are now going to start the programming. The first to do is to set up the start up loop.<\/p>\n

      <\/p>\n

      How to set up the start up loop<\/h2>\n

      When creating moving objects on the NXT screen, the important thing is to change the objects coordinates. This is done by changing the values of the parameters, since the parameters are the objects coordinates. The way this is done is shown in the start up loop below:
      \n
      \"game_4vit\"<\/a><\/p>\n

      It is this loop that makes the “animation” in the picture. every 1\/10 of a second the picture is drawn once again after the screen has been erased. And if, in meanwhile, an objects parameters has changed, this object will “move” to the new position. This loop is of course very important to the program, but once it is finished, we can leave it alone. It will continuously update our RIC file. The create Code button will help us make this start up loop. We start by pressing the Create Code button:
      \n
      \"CreateCode\"<\/a><\/p>\n

      When you press this button the following window will appear on the screen:
      \n
      \"set<\/a><\/p>\n

      By default the parameters name is the same as the parameter number. But it is best to select more logical names as we did in the view RIC file part of this website:
      \n
      \"parameter_table\"<\/a><\/p>\n

      We insert this for the parameters:
      \n
      \"namingparameters\"<\/a><\/p>\n

      We press the OK button and then we’ll get a new VI or program with the start up loop inside:<\/p>\n

      \"startprogram\"<\/a>When the program start the values in the front panel is passed via the build array command and further to the draw command. But by default all the values are zero. So we have to change them to our start up values:<\/p>\n

      \"startuovalues\"<\/a><\/p>\n

      PLEASE NOTE!!! A very common mistake for beginners of LabVIEW is that changing the values like this DOES NOT make these values the default values for the control. So, even if you save the file and open it again, the values are all zero, because zero is the default value. To make this current values the defalut, we right click the control, and select data operations\/Make Current value default:<\/p>\n

      \"makecurrentvaluedefault\"<\/a><\/p>\n

       <\/p>\n

      We have to do this for all the 7 controls and then we SAVE the file. The name of the file might be cannon_game.vi. But one thing is missing: the command advanced picture needs to know the name of our RIC file:<\/p>\n

      \"helpadvanced<\/a><\/p>\n

      Connector 3 asks for a filename. To fix this we select the wiring tool, right-click on this connector, and select create\/constant:<\/p>\n

      \"create<\/a><\/p>\n

      In the constant that pop up we enter the filename (i.e. cannon.ric):<\/p>\n

      \"filenamedone\"<\/a>Now the start up loop is finished! Now there is a lot of things we can do! I think we can start with moving the cannon around the screen with the NXT buttons.<\/p>\n

      <\/p>\n

      Moving the cannon with the NXT buttons<\/h2>\n

      In this part of the game we want to fix the moving of the cannon with the NXT buttons (moving left and right). It is also important to keep in mind we have to move the bullet at the same time. To program this we must create a new WHILE loop in our program:
      \n
      \"adding<\/a>These loops will run in parallel, so this is in fact a way to do multitasking. Let’s start with programming the right button task: moving the cannon and bullet to the right. We need the icon read sensor:<\/p>\n

      \"read_sensor\"<\/a><\/p>\n

      We place this in the WHILE loop:<\/p>\n

      \"addread_sensor\"<\/a><\/p>\n

      By default we get the command Read Touch. Change it by selecting Read NXT Buttons from the pull-down menu:
      \n
      \"select<\/a><\/p>\n

      Now the WHILE loop looks like this:<\/p>\n

      \"NXT_Buttoniconadded\"<\/a><\/p>\n

      This icon reads the specified NXT button (left,enter, right). The yes\/no (true\/false) output will return a yes if the specified NXT button is pressed at the moment:<\/p>\n

      \"helptxtNXTButton\"<\/a>In the lower left corner there is a connector called Button. We right-click and select create a constant here:<\/p>\n

      \"creatconstantbutton\"<\/a>A new constant is added:<\/p>\n

      \"enterbuttonconstant\"<\/a>We want to start with the right button. Select it by moving the mouse over the control and mouse click left:<\/p>\n

      \"select<\/a><\/p>\n

      Now this icon will return a yes (true) any time the right button is pressed. We connect the Yes\/No connector to the handy icon select:<\/p>\n

      \"selechelp\"<\/a><\/p>\n

      This icon returns the value wired to the t input or f input, depending on the value of s. If s is TRUE, this function returns the value wired to t. If s is FALSE, this function returns the value wired to f. The select command is found in the palette NXT programming\/Comparison:
      \n
      \"selectpalette\"<\/a><\/p>\n

      We place this icon on the diagram window, and connect the Yes\/no connector on the NXT Btns to the select:<\/p>\n

      \"connectselector\"<\/a>Now we must add the connectors t and f on the select command. We first place the mouse pointer on the t connector, right-click and select create constant:<\/p>\n

      \"creatconstantselect\"<\/a>A numeric constant will pop up:<\/p>\n

      \"selecttrue\"<\/a><\/p>\n

      The value is by default set to zero. We must change it to 1 because we want to add 1 to the cannons x coordinate when we press the right button. Now it looks like this:<\/p>\n

      \"addoneselect\"<\/a><\/p>\n

      Notice this constant is orange. This is because it is of the type double precision. The advanced picture command use the type 32-bits integer, so we have to change the representation. Right-click on the constant and select representation\/I32:<\/p>\n

      \"change<\/a><\/p>\n

      The constant will now change to the colour blue:<\/p>\n

      \"changed<\/a>The blue colour tells us this is an Integer. By right-clicking the f (false) on the select command and then select create constant we got a constant for the false part of the select:<\/p>\n

      \"createconstantfalse\"<\/a><\/p>\n

      The value for this one must be zero because we don’t want to add anything to the cannons x coordinate when the right button is not pressed. Also notice this will automatically be an integer because the two inputs always will be the same. So the question of interest is: how to add the number from the select command to the control Xcannon on the front panel, so the x coordinate of the cannon will increase with 1? The answer is local variables<\/strong>. Local variables are found in the palette NXT programming\/Structures:<\/p>\n

      \"local<\/a><\/p>\n

      We place a local variable on the block diagram:<\/p>\n

      \"localvariableadded\"<\/a><\/p>\n

      We can see a question mark inside the local variable. This means the variable is not configured. We have to select which control or indicator it should read or write. Left-click on the local variable and you’ll get a list of all the controls and indicators in the front panel:<\/p>\n

      \"locvariablelist\"<\/a><\/p>\n

      In this list all the controls and indicators are listed. Here we select Xcannon. Now it looks like this:<\/p>\n

      \"xcannon_added\"<\/a><\/p>\n

      To the left of the local variable you can see an arrow. It is pointing in to the house, which means this local variable is configured for writing. At this moment we want to read the local variables value (the cannons x-value). So we right-click and select Change to read:<\/p>\n

      \"change<\/a><\/p>\n

      Notice the changes in the local variable:<\/p>\n

      \"lcoalconfigured\"<\/a><\/p>\n

      Now the arrow is to the right and it is pointing out of the house\/local variable, meaning we are reading the variable. If we now insert an add command and do some wiring our diagram looks like this:<\/p>\n

      \"xcannonaadded\"<\/a><\/p>\n

      So let’s add a second local variable:<\/p>\n

      \"secondlocalv\"<\/a><\/p>\n

      So you can left-click the local variable and select Xcannon:<\/p>\n

      \"selectXcannon\"<\/a><\/p>\n

      Finally wire the add command to this local variable:<\/p>\n

      \"localvariable<\/a><\/p>\n

      So, it’s time to give an explanation on how this code works.<\/p>\n

      At first the value of the Xcannon is read (from the control). Let’s say the value is 34. Then, if the right button on the NXT is pressed, the number one is added to the value of Xcannon. It is important to know that the value of Xcannon is not changed until the last local variable is executed. This local variable has an arrow pointed in, which means this value is written to Xcannon. In this way we have changed the value of a control on the front panel. The value of Xcannon is changed from 34 to 35. If we press the right button once again, it will change to 36 and so on.<\/p>\n

      But what if we press the left button? As the program is now of course nothing will happen. To change this we first delete the wire between the add and the local variable:<\/p>\n

      \"remove<\/a><\/p>\n

      So let’s add a subtract command:<\/p>\n

      \"addsubtract\"<\/a><\/p>\n

      Here we need the same code as for the right button. The only difference is the constant Right button. So, by selecting this part of the code we can in fact program by using copy\/paste short cut keys. First, select the code you want to copy:<\/p>\n

       <\/p>\n

      \"selectcode\"<\/p>\n

       <\/p>\n

      Around the code we have selected there is a dashed line. Press CTRL+C to copy the code. Then, point with the mouse pointer where you want the code to appear. Finally press CTRL+V to paste the code:<\/p>\n

      \"codepasted\"<\/a><\/p>\n

      Press the arrow keys on your keyboard and move the code so it won’t lie over the other code:<\/p>\n

      \"codemoved\"<\/a><\/p>\n

      So we must change the constant Right Button to Left button by clicking on the drop-down menu:<\/p>\n

      \"dorpdownmenu\"<\/p>\n

      So we can wire the select command to the subtract command:<\/p>\n

      \"wiringselectortosubtract\"<\/a><\/p>\n

      Now almost everything is perfect, but there is still a problem. If we press the Right button long enough, the cannon will leave the screen (the x coordinate becomes greater than 100). To solve this problem we must use the function “In Range and Coerce”.<\/p>\n

      You’ll find it in the palette NXT Robotics\/NXT Programming\/Numeric:<\/p>\n

      \"coerce<\/a><\/p>\n

      Below is the help-text for this command:<\/p>\n

      \"helpinrangeandcoerce\"<\/a><\/p>\n

      Here x is the value we want to check (at this time Xcannon). If it is between the upper and lower limit, the value will be unchanged. But if it is greater than the upper limit it is coerced to the value of the upper limit. The same of course for the lower limit. The boolean In Range? is true if the value lies between upper and lower limit, else it is false.<\/p>\n

      At this moment we are not interested in that value, but we’ll have a closer look on this feature while checking out for collisions (when we want to check if the bullet hit the stone). We now insert the command in the diagram as shown below:<\/p>\n

      \"inrangeplaced\"<\/a><\/p>\n

      It is naturally to think the limits are 0 and 100. But let’s take a closer look at the cannon drawn with gridlines for the coordinates:<\/p>\n

      \"cannongrid\"<\/a><\/p>\n

      It is important to know that the CopyBits coordinates is the lower left corner of the object. So when the cannons coordinates are (100,64) as shown above, the whole cannon is outside the NXT screen. Hence the upper limit must be 100-14=86 (since the cannon is 14 pixels wide). The lower limit is of course 0. We add constants to the connectors upper limit and lower limit, and add the numbers 0 and 86:<\/p>\n

      \"upperandlowerlimitadded\"<\/a><\/p>\n

      So let’s have a look at the whole WHILE loop:<\/p>\n

      \"buttonwhileloop\"<\/a><\/p>\n

      This loop will fix the moving of the cannon, but NOT the bullet. To fix the movement of the bullet let us first look at the figure below:<\/p>\n

      \"bulletaandcannoningrid\"<\/a><\/p>\n

      Here the bullet and cannon has the right positions, it looks like the bullet comes out of the cannon at the middle position. The coordinates for the x-values are Xcannon=34 and Xbullet=40. The difference is 6 pixels. This means the bullets X-coordinate always must be 6 greater than the caons X-coordinate. we solve this by inserting an add command:<\/p>\n

      \"insertadd\"<\/a><\/p>\n

      The upper left corner we connect to the value of the Xcannon. For the lower left corner we create a constant with the number 6:<\/p>\n

      \"added6\"<\/a><\/p>\n

      The result of the add command is the X-coordinate for the bullet. Let’s add a local variable for Xbullet, and write to it as shown below:<\/p>\n

      \"whilebutton\"<\/a><\/p>\n

      The WHILE structure is nearly finished. but we have to wire the loop condition in the lower right corner. We could have created constant for this. But we want it to stop the loop when the game is over. Therefore we add a local variable for the control game over?, change it to read and wiring this to the loop conditinal:<\/p>\n

      \"movingwithbuttonsOK\"<\/a><\/p>\n

      You can test the program now. But you will soon discover the cannon moves too fast. We can add a Wait for time (ms). Go to NXT Robotics\/NXT I\/O:<\/p>\n

      \"waitfortime\"<\/a><\/p>\n

      We can place the Wait command anywhere in the WHILE structure:<\/p>\n

      \"waitadded\"<\/a><\/p>\n

      Press the dropdown menu on the comman and select Time (msec):<\/p>\n

      \"changetomsec\"<\/a><\/p>\n

      Right click the lower left corner and select Create constant:<\/p>\n

      \"endloop\"<\/a><\/p>\n

      As a suggestion try with 25 msec. You can also try other values of course. it depends on how difficult you want it.<\/p>\n

      So this part of the program is OK. Lets move to how to check for collisions between the falling stone and the bullet.<\/p>\n

      <\/p>\n

      Check for collisions between the falling stone and the bullet<\/h2>\n

      The goal for this game i to shoot the falling stone. For that reason it is of course important to find out if they have collided. At a first glance this sounds easy, they will collide when their coordinates are the same. But the picture below show this is not a good solution: \"check_for_collision\"<\/a> Clearly the bullet and stone will collide, but their x coordinates are not the same, and will never be. Therefore we have to check if the bullets x coordinates are within the falling stones x coordinate and the x coordinate plus its width. The stone is 9 pixels wide.<\/p>\n

      \"stone_pixels\"<\/a> So lets start with the programming. We first have to create a new while loop:
      \n
      \"While_loop_collision\"<\/a><\/p>\n

      We must fix the loop condition, add a local variable, set it to read and select game over. if you have done it correct the loop now looks like this: \"add_game_over_local_var\"<\/a>To check out for collisions we have to use the function “In Range and Coerce”: \"helpinrangeandcoerce\"<\/a> We find this in NXT Robotics\/Numeric:
      \n
      \"Numeric<\/a><\/p>\n

      We insert this into the While loop:
      \n
      \"insert_coerce_in_while\"<\/a><\/p>\n

      The variable we want to check is Xbullet. We first insert a local variable. We find it in the menu NXT Programming\/Structures:<\/p>\n

      \"localvariable<\/a> We insert this in our program: \"insert<\/a> We then configure it to Xbullet. press on the house and select Xbullet in the list: \"select_XBullet\"<\/a> So we right-click Xbullet and select changer to read: \"Xbullet_Change_to_read\"<\/a> So we wire this local variable to what is called x on the variable In range and coerce: \"xbullet_wired_to_in-range\"<\/a><\/p>\n

      So we must insert upper and lower limit. Lower limit will be Xstone. We inserts a local variable which is in the menu NXT Programming\/Structures:<\/p>\n

       <\/p>\n

      \"localvariable<\/a> We insert this one as shown below:<\/p>\n

      \"localvariableadded2\"<\/a> We configure it to Xstone and read. Now it should look like this: \"localvariableadded3\"<\/a> We wire this to the lower limit on the In range and coerce command: \"lowerlimitOK\"<\/a> So we must fix the upper limit. This should be Xstone+9 as mentioned before. We first insert an add command. It is in the NXT Programming\/Numeric menu:<\/p>\n

       <\/p>\n

      \"NumericAdd\"<\/a> We insert this: \"plusAdded\"<\/a> We have to add a local variable Xstone here also. Unfortunately it is not possible to use copy\/paste here, so we must insert a new local variable and configure it. But that we have done a lot of times now? After this is done our program looks like this: \"XstoneUpper\"<\/a> We wire this to the add command: \"wiretoadd\"<\/a> So we move the mouse pointer to the lower left of the add command. We right\/click and select create constant…\"creatconstanttoadd\"<\/a><\/p>\n

      In the constant we write the number 9. After that we wire the result of the add command to the upper limit on the in\/range and coerce command. Now it should look like this: \"in-range-coercefixed\"<\/a> The command In-Range and coerce will now check if the bullets x coordinate lies in between the upper and lower value of the stones X coordinate. If it is is, the connector In-Range? will become true: \"helpinrangeandcoerce\"<\/a><\/p>\n

      So when we have a collision the In Range connector becomes true. But, at the same time, the y coordinates must also be In Range. For that reason we must create a similar code for the y coordinates. But remember, we can not copy\/paste the code, it is not possible for local variables- I guess you have become familiar with this now, so the code will look like this when you are finished:<\/p>\n

      \"Inrage_Ybullet\"<\/a><\/p>\n

      But here you might see a problem. If there should be a collision, both Xstone and Ystone must be In Range at the same time. To fix this we must use the boolean operator AND, found in NXT Programming\/Boolean:<\/p>\n

      \"AND_menu\"<\/a><\/p>\n

      We insert this command as shown below: \"insertAND\"<\/a> Before we to the wiring lets explain the AND command. The help text is shown below (press CTRL+H and move the mouse pointer over the AND command):<\/p>\n

      \"ANDHelp\"<\/a><\/p>\n

      We see this command has two inputs. If both of them are true, the output is true. If one is TRUE and the other is FALSE, the output is FALSE. Or more exactly, IF x AND y is TRUE THEN the output is TRUE. For instance, for the OR command, IF X OR Y is TRUE, then the output is TRUE. For the OR command only one of them must be true. So, what do we want to do when we get the result TRUE, meaning the stone and bullet has collided? The first thing is obvious, the player’s score must increase, for example by one point.<\/p>\n

      But another thing to be done is to stop the bullet and the stone. We can also add a sound here, a beep to indicate the collision. To get all this done we need a CASE structure found in NXT Programming\/Structures:<\/p>\n

      \"CaseMenu\"<\/a> We insert this:<\/p>\n

      \"CaseAdded\"<\/a> So we must finish the wiring:<\/p>\n

       <\/p>\n

      \"finishwiring\"<\/a><\/p>\n

      So we can fix the score. Add two local variables and place them inside the TRUE part of the CASE structure. Select Score for both, one is set to read, the other to write as shown below:<\/p>\n

      \"Addscore_in_CASE\"<\/a><\/p>\n

      So we insert a add command, and a constant with the value 1, and do the wiring as shown below:<\/p>\n

      \"scorefixed\"<\/a><\/p>\n

      We also want to stop the bullet and stone, but this must be done in separate loops. We can do this by adding a new indicator called hit?. It will get its value from the AND command. Move the mouse to the green question mark on the CASE structure, and be sure to be inside the CASE structure. Then right-click and select create indicator:<\/p>\n

      \"createindicatorHIT\"<\/a><\/p>\n

      No it looks like this:<\/p>\n

      \"booleaninserted\"<\/a><\/p>\n

      Change the text or name of this indicator to Hit?:<\/p>\n

      \"Hittextfixed\"<\/a>We now have an indicator to keep track of the bullet hitting the stone. And of course, since this is an indicator we can create local variables elsewhere in the program to read\/write to this indicator. More on this when programming the movement of the stone.<\/p>\n

      Finally we must add the sound that indicates the collision. We insert the command Sound found in the menu NXT Robotics\/NXT I\/O:<\/p>\n

      \"sound_In_menu\"<\/a><\/p>\n

      We insert this into the CASE structure:<\/p>\n

      \"Sound_In_Case\"<\/a><\/p>\n

      So let’s look at the help for the Sound command:<\/p>\n

      \"Tone_help\"<\/a><\/p>\n

      The duration is by default set to 500 ms. A better value is 50ms. We move the mouse-pointer over this connector, right-click and select create constant. So we set the value to 50 ms. Now it looks like this:<\/p>\n

      \"duration50ms\"<\/a><\/p>\n

      So it is good to wait a bit before continuing. We insert a wait command found in NXT robotics\/NXT I\/O:<\/p>\n

       <\/p>\n

      \"Wait_In_menu\"<\/a><\/p>\n

       <\/p>\n

      We insert this behind the sound command:<\/p>\n

      \"wati_inserted\"<\/a><\/p>\n

      I would recommend to wait for 100ms. Press the down arrow on the command and select Wait for msec:<\/p>\n

       <\/p>\n

      \"Waitformsec\"<\/a><\/p>\n

      So you can right-click the Time connector, select create constant, and set he constant to 100:<\/p>\n

      \"wait_100msec\"<\/a><\/p>\n

      Finally we wire The Tone and msec command:<\/p>\n

      \"Wire_Tone_and_Wait\"<\/a><\/p>\n

      Congratulations, the loop for collisions are now fixed! Lets move on to moving the stone.<\/p>\n

      <\/p>\n

      How to move the falling stone<\/h2>\n

      This part of the program will be a new task so we have to add a WHILE structure :<\/p>\n

      \"while_loop_falling\"<\/a><\/p>\n

      When the stone falls we want it to start at a random x value. So we have to add a random number generator. We find this under NXT Programming\/Numeric:
      \n
      \"random_number\"<\/a><\/p>\n

      We insert this in to the WHILE structure:
      \n
      \"random_inserted\"<\/a><\/p>\n

      So let’s have a look at the help for this command (press CTRL+H to get the help window):
      \n
      \"random_number_help\"<\/a><\/p>\n

      This command will give us a random number between zero and the max value. the x value for the NXT screen is limited from 0 to 100. but since the width of the falling is 9 the upper limit for the random number must be 100-9=91. We right-click the lower left corner of the command and select Create constant:
      \n
      \"create_constant_random\"<\/a><\/p>\n

      Now it looks like this:
      \n
      \"added_constant\"<\/a><\/p>\n

      We change the number to 91:
      \n
      \"random_91\"<\/a>We want to give Xstone this random value. But first, to move the stone in the y direction we must add a second WHILE structure inside the first one as shown below (You’ll find the WHILE strucuture in NXT Programming\/structures)::<\/p>\n

      \"Loop_in_loop\"<\/a><\/p>\n

      So we add local variable inside the inner WHILE structure. We find it in NXT Programming\/Structures:<\/p>\n

      \"local<\/a><\/p>\n

      We insert this:<\/p>\n

      \"Localadded\"<\/a><\/p>\n

      We must configure this variable. Move the mouse-pointer over it until you get a cursor like a hand and then click on it and select Xstone
      \n
      \"Select_Xstone\"<\/a><\/p>\n

      Now it looks like this:
      \n
      \"Xstone_Addeed\"<\/a><\/p>\n

      This local variable is configured as write to by default, which is what we want now. We wire the Random value to the local variable Xstone:
      \n
      \"Random_conected_to_Xstone\"<\/a><\/p>\n

      The X value for the stone is set. Now we must of course change the stones Y value so as it falls down. Since the stone should fall down, the coordinate must start at its highest value which is 64. If you look at the lower left corner of the WHILE structure you can see a blue square with the letter i inside:
      \n
      \"lowerleft_While\"<\/a>The i stands for iteration, which tells us how many times the loop has execute. We can in fact call it a loop counter. And now we are going to use this counter to change the value of the Y coordinate for the falling stone. This time I think it is best to do the programming first and then explain afterwards. First we add a local variable, and configure it to Write and Ystone:
      \n
      \"ystone_Added\"<\/a><\/p>\n

      Now it looks like this:<\/p>\n

      \"Yston_configured\"<\/a><\/p>\n

      We add a minus comannd found in NXT Programming\/Numeric:
      \n
      \"Minus\"<\/a><\/p>\n

      We arrange it like this:
      \n
      \"Minus_added\"<\/a><\/p>\n

      So we wire the counter with the lower left corner of the minus (Subtract) command:
      \n
      \"iteration_to_subtract\"<\/a><\/p>\n

      So we move the mouse-pointer on upper left corner of the minus (subtract) command. We right-click and select create constant:
      \n
      \"create_constant_minus\"<\/a><\/p>\n

      The constant that pops up we set equal to 64:
      \n
      \"constant_64_added\"<\/a><\/p>\n

      Finally we wire the subtracted value to the local varaible Ystone:
      \n
      \"Ystone_falling_OK\"<\/a><\/p>\n

      In this way the value of Ystone will decrease for ech time the WHILE strucutre runs. the first time it is 64-0=64. the second time it is 64-1=63 and so on. If we test the program like it is now the stone will fall down and never stop. But there are a couple of reasons to stop the falling stone:<\/p>\n

        \n
      1. When the game is over (In programming it is a good thing to stop all loops when the program is finished).<\/li>\n
      2. The stone has hit the ground.<\/li>\n
      3. The bullet has hit the stone.<\/li>\n<\/ol>\n

        This adds up 3 cases when we want this WHILE structure to stop. If one of these three occurs the WHILE structure should stop. If we look back to page 6 where we worked with collisons, we used the AND<\/a> to check out if the Y cooridnate and X coordinate for the bullet was in a specific range. We checked two condiditons at a time, now we want to check out 3. And another difference is that now when only one of the three becomes TRUE the result should be TRUE. For that reason we now must use the command OR instead of AND. And since we need more than two inputs we must use the command OR Array Elements:<\/p>\n

        \"OR<\/a><\/p>\n

        We add this command and wire the output (left side connector) to the loop condition:<\/p>\n

         <\/p>\n

        \"OR_Array_Added\"<\/a><\/p>\n

        If we look at the help text for this command we see the input on the left side is an Boolean Array:<\/p>\n

        \"help<\/a><\/p>\n

        It is not easy to see, but the green wire on the left side is wider than green wire on the right side. This indicates we have an array as input. We therefore have to add the command Build Array:<\/p>\n

        \"BuildArray\"<\/a><\/p>\n

        We insert this and place behind the OR Array Elements:<\/p>\n

        \"Build_Array_added\"<\/a><\/p>\n

        When you insert the Build Array command it has only one input, and we want 3. To add more inputs, move the mousepointer over the command until you get an arrow:<\/p>\n

         <\/p>\n

        \"addmoreinputs\"<\/a><\/p>\n

        Then move the mouse downwards until you get 3 inputs. Now it should look like this:<\/p>\n

        \"Build_array_added_New\"<\/a><\/p>\n

        So we wire Build Array command to the OR Array elements:<\/p>\n

        \"wiring_OR_Array\"<\/a><\/p>\n

        You see we got a bad wire here. The reason is clear, the value of a Build Array command is by default set to Real. The OR Array elements need Boolean values. But we don’t care of this at the moment, at once we have wired a boolean to the Build Array this will be fixed automatically. then all the inputs and outputs will be set to Boolean because for the Build Array all the inputs and outputs must be of the same type.<\/p>\n

        So over to what should stop the WHILE structure. The first is when the game is over. We insert a local variable found at NXT Programming\/Structures:<\/p>\n

        \"localvariable<\/a><\/p>\n

        We insert this one:<\/p>\n

        \"Global_Inserted\"<\/a><\/p>\n

        So we right-click the local variable and select Game Over:<\/p>\n

        \"Set_To_Game_Over\"<\/a><\/p>\n

        Now it looks like this:<\/p>\n

        \"Game_over_Fixed\"<\/a><\/p>\n

        So we right-click and select Change To Read:\"Change_to_Read\"<\/a><\/p>\n

        Finally we wire to the OR Array an to the outer WHILE structure:<\/p>\n

        \"Wire_Outer\"<\/a><\/p>\n

        Notice the wire between the Build Array and OR Array Elements is no longer a bad wire. So we must check if the falling stone has hit the ground. this will happen when Ystone becomes zero. We insert an Equal to 0 command found in NXT Programming\/Comparison:<\/p>\n

        \"equal_to_0\"<\/a><\/p>\n

        We insert this, and connect the left connector to the value of Ystone, and the right connector to the middle connector of the OR Array Element:<\/p>\n

        \"Equal_to_Zero_Inserted\"<\/a><\/p>\n

        Finally, if the bullet has hit the falling stone we must also stop the falling stone. To fix this we add a local variable for Hit? and wiring it to the Build Array in the same way as for game over. The result is shown below:<\/p>\n

        \"HIt_Added\"<\/a><\/p>\n

        There is a problem here to solve. When the falling stone is hit, the local variable HIT? becomes TRUE and the loop ends. But to prevent the loop to stop again we must change the local variable Hit? to FALSE. And here is our problem:<\/p>\n

          \n
        1. If the value of the local variable is TRUE it must be changed to FALSE<\/li>\n
        2. If the local variable is FALSE it must also be FALSE.<\/li>\n<\/ol>\n

          So how to fix a test that is FALSE either the value of HIT? is TRUE or FALSE? The answer is the command select found in NXT Programming\/Comparison:
          \n
          \"Select_Menu\"<\/a><\/p>\n

          We insert the Select command:<\/p>\n

          \"Select_inserted\"<\/a><\/p>\n

          So we wire Hit? to the middle connector of the select command:<\/p>\n

          \"Hit_to_Select\"<\/a><\/p>\n

          Before we go on lets look at the help text for the Select command:<\/p>\n

          \"Select_Help\"<\/a><\/p>\n

          Here is the resulting test. The connector t is the result when s is TRUE and f is the result if t is false. At this time we want it to be FALSE for both t and f. We have to insert a boolean constant called False found in NXT Programming\/Boolean:<\/p>\n

          \"False_Constant\"<\/a><\/p>\n

          We add this and connect it to both the t and f connector:<\/p>\n

          \"False_Constant_added\"<\/a><\/p>\n

          The local variable Hit? is then set to the result of the select command. We insert a local variable found in NXT Programming\/Structures:<\/p>\n

          \"local<\/a><\/p>\n

          We insert this one, right-click and select HIT?:<\/p>\n

          \"Hit_Inserted\"<\/a><\/p>\n

          The local variable is by default configured as Write so we can just wire it to the s of the select command:<\/p>\n

          \"Hit_connected\"<\/a><\/p>\n

          Finally to slow down the falling stone we enter at wait for msecs and wait for 50 msecs:<\/p>\n

          \"falalingstone_finished\"<\/a><\/p>\n

           <\/p>\n

          <\/p>\n

          Moving the bullet<\/h2>\n

          In this game we want to fire a bullet when we press the ENTER button. We are going to use the same principle as for the falling stone: we use the counter inside a WHILE structure and let it count from 0 to 64. The difference is of course that we must start the WHILE structure when the ENTER button is pressed. First we start with a “outside” WHILE structure, and make sure to wire the loop condition to the local variable Game over.
          \n
          \"Movingbulletloop\"<\/a><\/p>\n

          So we insert a sensor command found in NXT I\/O:<\/p>\n

          \"read_sensor\"<\/a><\/p>\n

          We insert this command and select red NXT Buttons:
          \n
          \"select<\/a><\/p>\n

          We go back to the block diagram:<\/p>\n

          \"NXT_Button_Addded\"<\/a><\/p>\n

          Since this command by default is set to check for the ENTER button, we don’t need to set what button to check. The output from this command is yes if the button is pressed (TRUE) or no (FALSE) otherwise. This value we’ll send to a CASE structure. We find the CASE structure in the menu NXT Programming\/Structure\/Case Structure;<\/p>\n

          \"CaseMenu\"<\/a><\/p>\n

          We insert this and wire it to the NXT Button command:<\/p>\n

          \"CASEInserted\"<\/a><\/p>\n

          So let’s insert a WHILE structure in the TRUE part of the Case structure:<\/p>\n

          \"WHILE_loop_added\"<\/a><\/p>\n

          We want to use the counter to move the bullet. We insert a local variable found in NXT Programming\/Structures:
          \n
          \"localvariable<\/a><\/p>\n

          So we insert a local variable in this inner WHILE structure:<\/p>\n

          \"Local<\/a><\/p>\n

          When it is inserted we move the mouse-pointer on it, right-click and the select Ybullet:<\/p>\n

          \"SelectYbullet\"<\/a><\/p>\n

          The local variable is configured to WRITE:<\/p>\n

          \"Ybulletconfigurd\"<\/a><\/p>\n

          We wire the local variable to the counter (the blue I in the lower left corner):<\/p>\n

          \"Ybulletwired\"<\/a><\/p>\n

          The Y coordinate for the bullet will increase with 1 for each time the loop runs. But when it is greater than 64 it is at the top of the NXT screen and then we must terminate the WHILE structure. We insert a Greater? command found in NXT Programming\/Comparison:<\/p>\n

          \"greaterORequal\"<\/a><\/p>\n

          Inserted it looks as below:<\/p>\n

          \"greaterthanadded_1\"<\/a><\/p>\n

          We wire the upper left corner to the wire connected to the counter:<\/p>\n

          \"counterconnectedtogreaterthan\"<\/a><\/p>\n

          For the lower left corner we right-click and select Create constant. We set the value to 64:<\/p>\n

          \"64constantadded\"<\/a><\/p>\n

          It is easy think we now must wire the right corner of the Greater? command to the stop sign. But remember, the bullet must also stop when it hit the falling stone. We need to insert the local variable HIT? found in NXT Programming\/Structures:<\/p>\n

          \"localvariable<\/a><\/p>\n

          We right-click the local variable and select HIT? from the list:<\/p>\n

          \"SelectHIT\"<\/a><\/p>\n

          We have to change this local variable to read. Right-click and select Change To Read:<\/p>\n

          \"HIT<\/a><\/p>\n

          Since both conditions (YBullet>64 and the fact that the bullet has hit the stone) should terminate the WHILE structure, we must insert an OR command found in NXT Programming\/Boolean:<\/p>\n

          \"OR<\/a><\/p>\n

          We insert this and wire both conditions as shown below:<\/p>\n

          \"OR<\/a><\/p>\n

          Finally we wire the output of the OR command to the red stop sign (the condition terminal):<\/p>\n

          \"STOP<\/p>\n

          To slow down the bullet we insert a wait for msecs and set it to 15 msecs. This we have done before, it should now look like this:<\/p>\n

          \"wait<\/a><\/p>\n

          Our loop is now finished!<\/p>\n

           <\/p>\n

          <\/p>\n

          Check for number of lives: Game over<\/h2>\n

          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:
          \n
          \"ridEditor\"<\/a><\/p>\n

          Press the text tool. This window will pop up:
          \n
          \"TrextToSprite\"<\/a><\/p>\n

          Then enter the text Lives:<\/p>\n

          \"textLivesAdded\"<\/a><\/p>\n

          So let’s move it to the upper right corner. Make sure to have some empty space to the right of the text Lives:<\/p>\n

          \"TextLivesPlaced\"<\/a><\/p>\n

          Now it looks like this:<\/p>\n

          \"Livefinished\"<\/a><\/p>\n

          So you can press the Numbox button:<\/p>\n

          \"numbox\"<\/a><\/p>\n

          The following window will pop up:<\/p>\n

          \"ParameterWindow\"<\/a><\/p>\n

          The number of this parameter is 7. Type 7 and press OK. \"NumboxAdded\"<\/a><\/p>\n

          Finally move the Numbox to the upper right corner:<\/p>\n

          \"sevenplaced\"<\/a><\/p>\n

          The file is now finished, remember to save it.<\/p>\n

          But how will our program fix this new parameter? Lets look into the start up loop once again:<\/p>\n

          \"startprogram\"<\/a>We 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:<\/p>\n

          \"ExpandBuildArray\"<\/a><\/p>\n

          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:<\/p>\n

          \"Entryadded\"<\/a><\/p>\n

          We move the mouse pointer to this point, right-click and select create control. Here is the result:<\/p>\n

          \"controladded\"<\/a><\/p>\n

          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:<\/p>\n

          \"NewStartupLoop\"<\/a><\/p>\n

          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:<\/p>\n

          \"ViewAsIcon\"<\/a><\/p>\n

           <\/p>\n

          After that it looks like the others:
          \n
          \"Cosemthicchange\"<\/a><\/p>\n

          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:<\/p>\n

          \"Front_Panel\"<\/a><\/p>\n

          Let’s first do some simple tidying up on this front panel:.<\/p>\n

          \"Front_panel_tied_up\"<\/a><\/p>\n

          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:<\/p>\n

          \"3_entered\"<\/a><\/p>\n

          So we must make this to be the default value. Right-click the control an select Make current value default:<\/p>\n

          \"make<\/a><\/p>\n

          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:<\/p>\n

          \"WHILE_Lives\"<\/a><\/p>\n

          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:<\/p>\n

          \"LESS_COMMAND\"<\/a><\/p>\n

          Now it looks like this:<\/p>\n

          \"Lessthaninserteed\"<\/a><\/p>\n

          We have to insert a local variable found at NXT Programming\/structures:<\/p>\n

          \"localvariable<\/a><\/p>\n

          We insert a local variable:<\/p>\n

          \"Localvariableaddedingameover\"<\/a>We left-click on this one and select Ystone:\"ystone_Added\"<\/a><\/p>\n

          Finally we right-click and select Change To Read:<\/p>\n

          \"YStone_change_to_read\"<\/a><\/p>\n

          So we wire the local variable to the upper left corner of the Less? command:<\/p>\n

          \"Localwired\"<\/a>We right-click the lower left corner and select create constant:<\/p>\n

          \"Create_constant_less\"<\/a><\/p>\n

          We set the value of the constant equal to 5:<\/p>\n

          \"constant_equal_5\"<\/a><\/p>\n

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

          \"CaseMenu\"<\/a><\/p>\n

          We insert this and wire it to the left corner of the Less? command:<\/p>\n

          \"AddCase\"<\/a><\/p>\n

          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:<\/p>\n

          \"Add_Sound_control\"<\/a><\/p>\n

          Inserted it looks like this:<\/p>\n

          \"Souncontrol_added\"<\/a><\/p>\n

          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:<\/p>\n

          \"SelectPlaySoundFile\"<\/a><\/p>\n

          The command now change to the Play Sound File. Here is the help text for this command:<\/p>\n

          \"Help_Text_Sound_File\"<\/a><\/p>\n

          The upper middle connector is a text for the filename. We right-Click on the middle upper connector and select create constant:<\/p>\n

          \"Create_Constant_Play_sound_file\"<\/a><\/p>\n

          In the constant that appear we type in the filename woops.rso:<\/p>\n

          \"woops_rso\"<\/a><\/p>\n

          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:<\/p>\n

          \"decrement\"<\/a><\/p>\n

          We insert this into the TRUE part of the CASE structure (I have also made the CASE structure wider to get more space):<\/p>\n

          \"Decrement_Added\"<\/a><\/p>\n

          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:<\/p>\n

          \"Local_Varaibles_Added\"<\/a><\/p>\n

          These local variables must be configured. We left-click on the variables and select lives:<\/p>\n

          \"select_lives\"<\/a><\/p>\n

          After this change your program should look like this:<\/p>\n

          \"Local_variable_Lives_Configured\"<\/a><\/p>\n

          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:<\/p>\n

          \"Change<\/a>Now your program should look like this:<\/p>\n

          \"lives_configured\"<\/a><\/p>\n

          We now have to do some wiring:<\/p>\n

          \"Wiring_Done\"<\/a><\/p>\n

          After the wiring you should pay attention to the blue rectangles on the edge of the CASE structure:<\/p>\n

          \"Tunnels\"<\/a><\/p>\n

          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:<\/p>\n

          \"Select_False_Case\"<\/a><\/p>\n

          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):<\/p>\n

          \"Casenotwired\"<\/a><\/p>\n

          To finish the wiring we just wire from tunnel to tunnel:<\/p>\n

          \"tunnel_to_tunnel_wired\"<\/a><\/p>\n

          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:<\/p>\n

          \"equal_to_0\"<\/a><\/p>\n

          Inserted:<\/p>\n

          \"Equaltozeroadded\"<\/a><\/p>\n

          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\"<\/a><\/p>\n

          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:<\/p>\n

          \"Lives_fixed\"<\/a><\/p>\n

          After this our game is finished.<\/p>\n

          Enjoy!!<\/p>\n

          <\/p>\n

          Resources<\/h2>\n

          The package RicEditor.zip<\/a> contains the following files:<\/p>\n

            \n
          1. RicEditor.llb – This is the RicEditor. Download this file and follow the instructions<\/a>\u00a0on how to install and run the RicEditor.<\/li>\n
          2. cannon.ric – This is the completed ric file from this tutorial, just in case you either don’t want to create it yourself or ran into problems with it.<\/li>\n
          3. cannon_game.vi – This is the completed LabVIEW program from this tutorial.<\/li>\n<\/ol>\n

             <\/p>\n","protected":false},"excerpt":{"rendered":"

            Before you start This post is a tutorial on how to work with “RIC” image files to create a simple game using the NXT display. For an example of what the finished game will look like and an introduction to RIC files, please see: Create your own games with “RIC” files. To start making RIC-based […]<\/p>\n","protected":false},"author":8,"featured_media":6796,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[99,159],"tags":[280,143,281,240],"_links":{"self":[{"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/posts\/1454"}],"collection":[{"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/comments?post=1454"}],"version-history":[{"count":0,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/posts\/1454\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/media\/6796"}],"wp:attachment":[{"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/media?parent=1454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/categories?post=1454"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/tags?post=1454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}