Alex's+Star+Catcher+with+a+Cat+Tutorial


 * Alexander Comby **
 * Lower School Project **


 * Today we are creating a simple but fun star catcher game. The game will consist of a cat that you will be able to control. The goal is to collect as many stars as possible, which are falling from the sky. If three stars hit the ground, the game will be over. **
 * Our first Sprite will be the cat, he will be able to move left and right but also to jump. Start by creating three variables from the data section. Call them; “Jumping?”, “Velocity” and “GroundY”. The velocity variable will be used later for the jumping part. **


 * . [[image:https://lh5.googleusercontent.com/0EvqzF6Bh4JA-bBz1_-fTe6C5WGsKDiIzqvlnYp2OGIpPQ3gwexZlMyebySXVcvs7FbWO8Bacc1skVn-DamSgdcQehPzikhmntAQylFrkmrxltzjOt1QIegmXQ]]**


 * Now we will start coding the cat’s movements. Include the following code to the script. I will explain what is happening. **




 * First, we have to give values to the variables we previously created. The GroundY variable will set the cat to the bottom of the page, feel free to change that value to bring up or down the sprite. The Jumping variable has two roles, it determines whether or not the sprite is jumping. If not, the cat stays on the ground, which is normal. The jumping variable will be set to true later. The “If” block checks continuously for the conditions that we will write in it and the “forever” block makes a loop that goes forever. **


 * Then we assign the left and right arrow keys with the control of the movement. Here we see that if the left arrow key is pressed, the sprite will look left and move left, the same thing is happening with the right arrow key except it goes to the right. The last thing for this part is to change the costume of the sprite when it goes left and right. In other words, we are creating a more realistic movement by making the sprite really walk. **




 * We can see that the sprite already has its other costume is already set up. The only thing we have to do is set up the costume so that it changes when we make it walk. **


 * Next we have to set up the jump. But first we have to create the jump block. **




 * When you create it, the script will ask to to define the block. Include the following code to your script. [[image:https://lh4.googleusercontent.com/HIQmn42lqyceguMppHpMT2EPoqYxEpna8vNnSFe0g_679Ur7O4XchKPHCpZv_YWQFtChtDX-jVCYLBkgN-2hDazGxP2Uj8Pmw66ridPBGQD8XbI06wDqgIuj1g]]**


 * The Previous jumping variable now does its other role, we set it to true. When it is set to true, it disables the role it has when it is set to false. In other words, we tell the program that the sprite is jumping and not walking. **
 * For now, the sprite is only allowed to jump if it is on the ground. **


 * When the sprite is about to jump, the initial vertical velocity for the jump should be high in order to jump at a reasonable height. I decided to use 25 as the first change to y when the sprite is jumping. **


 * As the sprite’s y value changes by the velocity, there is a jump occurring because the position changes by 25. Now that the sprite is in the air, we still have to make it come back down. Now as long as the position of the sprite is bigger than the ground, it will come back down until it becomes smaller. This is why we use a “Repeat Until” block. In simpler terms, as long as the sprite is in the air, it has to come down. **


 * And finally, after the jump is complete, we have to set the jumping variable back to false in order to tell the program that the sprite is walking. **


 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">The final thing to do is assign the jump to a key, the key will be the up arrow. Drag the jump block to the script. [[image:https://lh4.googleusercontent.com/u2bmm0OKTDZcWZV6Gs2lICzKrL2NA9tZ5RtNkTkVf41NJIlZESH763LypNoyh53O3tUMYl6rnMQo0T3UDPjp-UbQg7a8-uTvZkvi2gdFg-jArbbsiNZpcEdqqQ]]**


 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">Now we are done with the main sprite. We will now create a second sprite that will be placed at the bottom. This sprite is only used for sensing when the star, that we are supposed to catch, will hit the ground. **




 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">Click on the second image to paint a new sprite. **




 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">Click on the line and make a line that goes all the way across the screen. For the code of the line, simply give it a y position. Feel free to change it so that it is really at the bottom of the screen. **




 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">Now for our last sprite, click on the first image of the “New Sprite” area. When you are offered to choose the sprite within their library, select the star and click “ok”. **


 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">Before we start coding the star, add a new backdrop that you will call “Game Over” and type the same message on the screen. [[image:https://lh5.googleusercontent.com/iRMHtMSeYf17Aj4vrjJsFNv6iytJZGOMfim7wDYwo3IqcNxU5_Kkx7XMxB0KW_WfE7K1dPWrW3-ukNi_2xxzBhbxdTl5kKOPzz_YlnZ2V8q7svdJ0F8Jmv6V0w]]**


 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">Now create a “score” and “lives” variables and I will explain right after it. **




 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">We are going to set up a system of lives so that after a certain amount of times the star touches the ground, the game is over and the screen changes to the game over background we made earlier. **
 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">The “score” variable is going to keep track of how many times your character caught the falling stars. **


 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">Copy the following code to the script of the star. **




 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">Here we are setting the number of lives to 3, you can change it to how many you want. Also, the score is always 0 at the start of a game, therefore set the score to zero. **
 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">Now we want the star to appear from the top of the screen, so we know what the y position has to be. But we will make it so that it’s horizontal or x position is chosen at random on the screen, this is what the “Pick Random” block is for. **




 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">We will make it so that when the star touches the cat, in this case called “Sprite1”, the score goes up by one and so that when it happens, the star reappears at the top like before. This block checks constantly if either option from the image is happening. If the star is not touching the cat, or “Sprite1”, than the star keeps falling towards the ground. **




 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">In this case, it checks if the star is touching the ground, or “Sprite2”. **
 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">If it does, one life will be removed, the star disappears, goes back at the top and shows back again. **


 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">Now for the final part of this game. **




 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">The final lines of code check that if the number of lives are equal to zero, than the game over screen appears and the game stops. Include this code to EVERY sprite script at the end. Do not forget to put it inside a “forever” block. **


 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">This is what the code for the star should look like. **




 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">Again, notice how all of the “if” blocks are inside a “forever” block. **




 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">And the code for the ground, or line we set up on the bottom, should look like this. **
 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">Do not forget to do the same for the cat. **


 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">Now for a little challenge! **


 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">Try to set up an intro backdrop that presents your game. Don’t forget to make your Sprites appear only when the intro screen disappears. **


 * <span style="background-color: transparent; color: #000000; font-family: Cambria; font-size: 16px; text-decoration: none; vertical-align: baseline;">This great game is brought to you by Alexander Comby®. **