diff --git a/docs/courses/csintro/blocks/unit-2/lab0202-part1.md b/docs/courses/csintro/blocks/unit-2/lab0202-part1.md index 5d50a005d46..a71a50fa539 100644 --- a/docs/courses/csintro/blocks/unit-2/lab0202-part1.md +++ b/docs/courses/csintro/blocks/unit-2/lab0202-part1.md @@ -1,4 +1,5 @@ # Lab 2.2 Part 1: How Old Are You? +### @explicitHints true ## Introduction to variables @showdialog @@ -8,49 +9,63 @@ a player's score or lives. We can create our own variables, too! +![Lab 2.2.1](https://arcade.makecode.com/api/_RdC9TMWEuKR1/thumb) + ## Splash! Let's learn about a new block that you can use to display a message on the screen. -1. In your -``||loops(noclick):on start||`` -container, add a -``||game:splash ("")||`` +--- + +1. In your
+``||loops(noclick):on start||``
+container, add a
+``||game:splash ("")||``
block. You can find that block in the ``||game:Game||`` drawer of the toolbox. 1. Type a phrase into the new block. Any phrase will do! +--- + + Run your project to see how this block works. +#### ~ tutorialhint + ```blocks game.splash("Hello, world!") ``` ## Join together! -Instead of just one space for text, let's give ourselves some more room. -We need a new block ... and this time, it's in a secret location! +Instead of just one slot for text, let's give ourselves more room. +We need a new block...and this time, it's in a secret location! -The drawer that we need is called ``||text:Text||`` **Text**, +The drawer that we need is called ``||text:Text||``, and it is in the **Advanced** section of the toolbox. + Click on **Advanced** to see the secret drawers in the toolbox! -Check the hint to see a screenshot showing this secret drawer. +![Advanced drawers in the toolbox.](/static/courses/csintro/S01.L02.02.P01.text_drawer.png) + +--- -1. From the -``||text:Text||`` -**Text** -drawer, drag a -``||text:join ("Hello") ("World")||`` -**join ("Hello") ("World")** -block into your -``||game(noclick):splash("")||`` + +1. From the +``||text:Text||`` drawer, drag a
+``||text:join ("Hello") ("World")||``
+block into your +``||game(noclick):splash("")||`` block. +--- + + Run your project to see how these blocks work together. Check the hint if you need help. -![Advanced drawers in the toolbox.](/static/courses/csintro/S01.L02.02.P01.text_drawer.png) + +#### ~ tutorialhint ```blocks game.splash("Hello" + "World") @@ -58,169 +73,263 @@ game.splash("Hello" + "World") ## Speak your mind! -Let's learn more about how the **Join** block works. +Let's learn more about how the ``||text(noclick):join ("Hello") ("World")||`` +block works. + +--- + -1. Change the text in your -``||text:join ("Hello") ("World")||`` -**join ("Hello") ("World")** +1. Change the text in your
+``||text:join ("Hello") ("World")||``
block. 1. Run your project and see how it's changed. 1. Do this a few times until your understand how this block works. Now, let's try something else! -- Expand the -``||text:join ("Hello") ("World")||`` -**join ("Hello") ("World")** +- Expand the
+``||text:join ("Hello") ("World")||``
block. -~hint How do I expand a block? -Some blocks have a plus sign on the right side of the block. Select the + + +~hint How do I expand a block? 🤷🏽 + +--- + +Some blocks have a plus sign (+) on the right side of the block. Click the plus sign to expand it. The block will show more information! hint~ -- Now, collapse the -``||text:join ("Hello") ("World")||`` -**join ("Hello") ("World")** +- Now, collapse the
+``||text:join ("Hello") ("World")||``
block. -~hint How do I collapse a block? -Some blocks will have a minus sign on the right side of the block. -Select the minus sign to collapse it. The block will hide some information! +~hint How do I collapse a block? 🤷🏻‍♀️ + +--- + +Some blocks will have a minus sign (-) on the right side of the block. +Click the minus sign to collapse it. The block will hide some information! hint~ -Play around with the -``||text:join ("Hello") ("World")||`` -**join ("Hello") ("World")** +Play around with the
+``||text:join ("Hello") ("World")||``
block. Expand it, collapse it, and enter your own text. Watch how your project responds. +--- + + When you are ready, move on to the next step. -## Only room for three! +## Room for three! Let's get our project ready for our first variable. -1. Expand or collapse your -``||text:join ("Hello") ("World")||`` -**join ("Hello") ("World")** +--- + + +1. Expand or collapse your
+``||text:join ("Hello") ("World")||``
block so that it shows three spaces for text. 1. In the first space, enter **You are ** *with a space at the end*. 1. In the second space, enter your age (or any number that you wish). 1. In the third space, enter ** years old** *with a space at the beginning*. +--- + + Run your project to see how it works. Check the hint if you need help. +--- + + **Question**: Why were the spaces in steps 2 and 4 necessary? +#### ~ tutorialhint + ```blocks game.splash("You are " + "0" + " years old") ``` ## Whose age? -Our project works, but it doesn't show the player's age ... it shows yours. -Sure, we could ask the player to change the code and type in their age, -but that's not very friendly! +Our project works, but it doesn't show the player's age...it shows yours. -Let's get our project ready so that we can ask the player to enter their age. +Let's get our project ready to ask the player to enter their age. To do that, we need to create a variable. +--- + + 1. Open the ``||variables:Variables||`` drawer. -1. At the top of the drawer, select the -**Make a Variable...** -button. -1. In the dialog that appears, enter an appropriate name (like *age*). -1. Select the **Ok** button. +2. At the top of the drawer, select
+**Make a Variable...**
+3. In the dialog that appears, enter an appropriate name (like *playerAge*). +4. Select the **Ok** button. + +~hint Why not just age? 🤷🏿‍♀️ + +--- + +You'll find that many programming languages have special words. +Short words like time, score, date, (etc.) often already have special meanings attatched to them. + +For this reason, whenever you're thinking of a variable for a common word (sprite, age, name, etc.) +it's best to add a modifier to make sure it's special. That's why we default to variables like +mySprite, playerAge, userName, and such! + +hint~ + Now, we have a variable that we can use! -1. Drag a -``||variables:set age to (0)||`` -block **to the top** of your -``||loops(noclick):on start||`` +5. Drag a
+``||variables:set [playerAge] to (0)||``
+block **to the top** of your
+``||loops(noclick):on start||``
container. -1. Set the variable's value to your own age. +6. Set the variable's starting value to your own age. + + + +#### ~ tutorialhint + +```blocks +let age: number = 14 +game.splash("You are " + "0" + " years old.") +``` + + + + +## What's my age again? We've created a variable. Now, we need to use it! -1. From the -``||variables:Variables||`` drawer, drag an -``||variables:age||`` -block and drop it in the middle spot of your -``||text:join ("You are ") ("0") (" years old.")||`` -**join ("You are ") ("0") (" years old.")** +--- + + +1. From the +``||variables:Variables||`` drawer, drag
+``||variables:playerAge||``
+into the middle spot of your
+``||text:join ("You are ") ("0") (" years old.")||``
block. 1. Run your project to see how it works. -1. Change the value of the **age** variable and watch how your program -responds. +1. Change the value of **playerAge** in your _initialization_ block +and watch how your program responds. 1. Do this a few times until you are comfortable with how the variable works with the **join** block. + + +~hint What is initialization? 🤷🏻 + +--- + +The word _initialization_ comes from the word _initial_...meaning _first_. We use that term +because, before you can use a variable, you need to _first_ tell the computer what it is. + +The first time a
``||variables:set [variable] to [0]||``
+block is used in a program, several things happen: +- The new variable name is added to our ``||variables:Variables||`` category +- The variable is given a starting value +- The computer recognizes the _type_ (number, image, string, etc.) of the variable, and knows +that it needs to make sure that type matches everywhere in the program + +hint~ + +--- + + Check the hint if you need help. +#### ~ tutorialhint + ```blocks let age: number = 14 -game.splash("You are " + age + " years old.") +game.splash("You are " +playerAge+ " years old.") ``` ## Does order matter? -What happens when we switch the order of these two blocks? +What happens when we switch the order of your two blocks? + +--- -1. Switch the order of the blocks in your -``||loops(noclick):on start||`` + +1. Switch the order of the blocks in your
+``||loops(noclick):on start||``
container. 1. Run your code to see how your program responds. -**Question**: Does the order of these two blocks matter? Why or why not? +--- + + +**Question**: Does the order of these two blocks matter? Why do you think that is? + ## I want your input! We have a variable now, but we still haven't asked the player for their age. + Let's do that now! -1. From the -``||game:Game||`` drawer, drag an -``||game:ask for number ("")||`` -block and drop it into the red block -that sets the value of your variable. -1. In this new block, enter a prompt for the player, -like "How old are you?" +--- + + +1. From the
+``||game:Game||`` drawer, drag
+``||game:ask for number ("")||``
+into the red initialization block. +1. In the text field of the ``||game:ask||`` block, enter a prompt for the player, +like. "How old are you?" + +--- Check the hint if you need help. + +#### ~ tutorialhint + ```blocks -let age = game.askForNumber("How old are you?") -game.splash("You are " + age + " years old.") +letplayerAge= game.askForNumber("How old are you?") +game.splash("You are " +playerAge+ " years old.") ``` -## Ooh! A keyboard! +## Ooh! A number pad! -Run your program and notice how it responds now. +Run your program and notice how it responds. -Now you know how to display a keyboard on the screen! +Use these instructions to interact with the number pad. + +--- -Use these instructions to interact with the keyboard. - Use the D-pad (up, down, left, and right) to move the cursor. -- To press a key, use the **A** button. +- To select a number, use the **A** button. - If you make a mistake, use the **B** button as a backspace. - When you are done, use the D-pad to move the cursor to the **Ok** button. Then, use the **A** button to select **Ok**. +--- + + Run your project a few times so that you see how your project works and to get used to the on-screen keyboard. + ## Complete! @showdialog Good work! We will return to these ideas in the next couple of lessons. For now, move on to Part 2! ```ghost -let age = game.askForNumber("How old are you?") -game.splash("You are " + age + " years old.") +letplayerAge= game.askForNumber("How old are you?") +game.splash("You are " +playerAge+ " years old.") ``` \ No newline at end of file diff --git a/docs/courses/csintro/blocks/unit-2/lab0202-part2.md b/docs/courses/csintro/blocks/unit-2/lab0202-part2.md index 1c4e69e8875..aea230f8f2d 100644 --- a/docs/courses/csintro/blocks/unit-2/lab0202-part2.md +++ b/docs/courses/csintro/blocks/unit-2/lab0202-part2.md @@ -1,4 +1,5 @@ # Lab 2.2 Part 2: How Many Items? +### @explicitHints true ## How many items? @showdialog @@ -7,19 +8,28 @@ Let's look at another way that we can use variables. In this project, we will use a variable to keep track of how many sprites are on the screen. +![Lab 2.2.2](https://arcade.makecode.com/api/_LoRf3w2ruPUc/thumb) + ## Let's find a hero! First, let's create a hero for our story. -Create your hero sprite. Add block to your project so that your hero: +--- + +Create your hero sprite using an appropriate name and image. + +Add blocks to your project so that your hero: + +- Is controlled by the player with the directional pad +- Stays on the screen at all times + +--- -- Has an appropriate variable name. -- Has an image assigned to it. -- Is controlled by the player with the directional pad. -- Stays on the screen. Check the hint if you need help and to verify your code. +#### ~ tutorialhint + ```blocks let heroSprite = sprites.create(sprites.duck.duck3, SpriteKind.Player) controller.moveSprite(heroSprite) @@ -28,19 +38,27 @@ heroSprite.setStayInScreen(true) ## Add some sprites! -Now, let's add a sprite to the screen whenever the player wants one. +Now, let's add more sprites to the screen whenever the player to. + + +--- Add an event handler to your project so that, whenever the player -presses the **A** button, a new sprite appears. Make sure the new sprite: +presses the **A** button, a new sprite appears. Make sure each new sprite: + +- Has an appropriate variable name +- Has an image assigned to it +- Has a kind other than _Player_ assigned to it +- Appears at a random location on the screen + +--- -- Has an appropriate variable name. -- Has an image assigned to it. -- Has a kind assigned to it (anything except *Player*). -- Appears at a random location on the screen. Run your project to see if it works as you expect it to. Check the hint if you need help. +#### ~ tutorialhint + ```blocks let foodSprite: Sprite = null controller.A.onEvent(ControllerButtonEvent.Pressed, function () { @@ -53,36 +71,73 @@ controller.A.onEvent(ControllerButtonEvent.Pressed, function () { Let's create a simple story for your project. +--- + +Add a splash screen at the start of your game +that explains your story. + - Who is your hero? - What are the objects that your hero is adding to the screen? -- Add an appropriate splash screen at the start of your game -that explains your story. +- Why is that happening? + +--- + When you have added a story to your game, move on to the next step. +#### ~ tutorialhint + +```blocks + +game.splash("I'm a hungry duck who needs strawberries so I can fuel up for my long flight!") +let heroSprite = sprites.create(sprites.duck.duck3, SpriteKind.Player) +controller.moveSprite(heroSprite) +heroSprite.setStayInScreen(true) +``` + ## Count 'em up! Now, let's keep track of how many items the player has added to the screen. +--- + + 1. Make a new variable for your project. This variable will store -the number of sprites that the player has created. Give the variable +the total number of sprites the player has created. Give the variable an appropriate name. -1. Add a block to your -``||loops(noclick):on start||`` +1. Add a block to your
+``||loops(noclick):on start||``
container that sets -the value of the variable to zero. -1. In your event handler for the **A** button, add a block that changes -the value of your variable by **1**. +the initial value of the variable to zero. +1. In your event handler for the **A** button, add a block to increment your new variable. + +--- + + +~hint What's "increment" again? + +--- -~hint What is a increment? When we increase the value of a variable by one, we often say that we are "incrementing" the variable. + +(Although, it's also possible to increment by 3, 5, 10, or even 1000.) + hint~ We've created the variable, but we aren't using it yet. We'll do that next! +#### ~ tutorialhint + ```blocks +let foodCount = 0 let foodSprite: Sprite = null +game.splash("I'm a hungry duck who needs strawberries so I can fuel up for my long flight!") +let heroSprite = sprites.create(sprites.duck.duck3, SpriteKind.Player) +controller.moveSprite(heroSprite) +//@highlight +foodCount = 0 + controller.A.onEvent(ControllerButtonEvent.Pressed, function () { foodSprite = sprites.create(sprites.food.smallStrawberry, SpriteKind.Food) foodSprite.setPosition(randint(8, 152), randint(8, 112)) @@ -96,20 +151,28 @@ controller.A.onEvent(ControllerButtonEvent.Pressed, function () { Let's show a message whenever the player wants to know how many sprites are on the screen. +--- + Add an event handler for the **B** button to your workspace. + In your event handler: -- Use a -``||game:splash||`` -block or a -``||sprites:say||`` +- Use a +``||game:splash||`` +block or a +``||sprites:say||`` block to display the value of your variable. -- Feel free to use a -**join** block to make your message more interesting! +- Feel free to use a +``||text:join||`` block to make your message more interesting! + +--- + Run your project to see if it works as expected. Check the hint if you need some help. +#### ~ tutorialhint + ```blocks let foodCount = 0 controller.B.onEvent(ControllerButtonEvent.Pressed, function () { @@ -121,21 +184,35 @@ controller.B.onEvent(ControllerButtonEvent.Pressed, function () { Now, let's say that the player can pick up objects, too. -1. Add an -``||sprites:on overlap||`` +--- + + +1. Add an
+``||sprites:on overlap||``
event handler to your workspace. -1. Change the block so that it runs when the player collides with another sprite. -1. In the event handler, destroy the sprite when the player touches it. -1. Remember to update your counting variable! +1. Change the block so that it runs when the Player collides with your other sprite kind. +1. In the event handler, destroy the other sprite when the player touches it. +1. Remember to decrement your counting variable! + +--- + Run your project to see if it works as expected. Check the hint if you need some help. -~hint What is a decrement? +~hint What's "decrement" again? + +--- + When we decrease the value of a variable by one, we often say that we are "decrementing" the variable. + +(Though we _can_ decrement by other numbers, as well.) + hint~ +#### ~ tutorialhint + ```blocks let foodCount = 0 sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) { @@ -150,6 +227,8 @@ Good work! You have learned a few ways to use variables! Submit your project to your instructor if requested to do so. + + ```ghost controller.B.onEvent(ControllerButtonEvent.Pressed, function () { game.splash("I see " + foodCount + " strawberries!") diff --git a/docs/courses/csintro/blocks/unit-2/lab0203.md b/docs/courses/csintro/blocks/unit-2/lab0203.md index b9029f69f32..69555d628f5 100644 --- a/docs/courses/csintro/blocks/unit-2/lab0203.md +++ b/docs/courses/csintro/blocks/unit-2/lab0203.md @@ -1,27 +1,38 @@ # Lab 2.3: Variables and Math +### @explicitHints true ## Variables and math! @showdialog -Variables are helpful for our programs, -since they let us store information that we need in our program. +Variables are really helpful, +since they let us store information we want to use in our program. -Variables become even more powerful when we can combine them! +Variables become even more powerful when we combine them! -In this lab, you will discover different ways to use math with variables. +In this lab, you'll discover different ways to do math with variables. + +![Lab 2.3](https://arcade.makecode.com/api/_6rp7vgR10M1P/thumb) ## Ooh! A playground! -First, let's build a playground. +Time for a coding playground. + +--- -Add blocks to your -``||loops(noclick):on start||`` + +Add blocks to your
+``||loops(noclick):on start||``
container that: -- Asks the player for two numbers. -- Stores those numbers in two different variables. +- Ask the player for numbers two times +- Store those numbers in two different variables + +--- + View the hint to check your code. +#### ~ tutorialhint + ```blocks let number1 = game.askForNumber("First number?") let number2 = game.askForNumber("Second number?") @@ -29,54 +40,78 @@ let number2 = game.askForNumber("Second number?") ## Sum? Product? What's the difference? -Now, let's use these two numbers that your project has collected from the player. +Let's use the two numbers collected from the player. + +--- -Add blocks to your -``||loops(noclick):on start||`` + +Add blocks to your
+``||loops(noclick):on start||``
container so that your project shows the *sum* of the two numbers. -The block to add two numbers is in the -``||math:Math||`` -drawer. -Run your project to test that it works. Try different numbers. -View the hint to check your code. -~hint What is a sum? +~hint What is a sum? 🤷🏽‍♀️ + +--- + The sum is the result of two numbers added together. In other words, -use the addition (or "plus") operator. +use the addition (or "plus") operator from the ``||math:Math||`` drawer to get the sum. + hint~ + +--- + + +Run your project to test that it works. Try lots of different numbers! + + +#### ~ tutorialhint + ```blocks let number1 = game.askForNumber("First number?") let number2 = game.askForNumber("Second number?") game.splash("" + number1 + " + " + number2 + " = " + (number1 + number2)) ``` -## Complete @showdialog +## It's all in the numbers + +Let's learn about some of the other blocks in the ``||math:Math||`` drawer! -Good work! Now, learn about some of the blocks in the ``||math:Math||`` drawer! +--- - Start with the block that you already have in your project. Notice that the "plus sign" can be changed to different symbols. - For each of these operations, run your project a few times. - Enter some numbers. (Try small ones at first.) - Make a record of each of your trials. - (In other words, write down the numbers that you enter each time + (In other words, write down the numbers that you enter...and the result...each time you run your program.) - See if you can figure out what each operation does. - Once you have explored all of the operators in this first math block, -try some of the remaining blocks in the -``||math:Math||`` +experiment with the remaining blocks in the +``||math:Math||`` drawer in the same way. - You may not understand all of the operators that you find. That's OK! - Be sure to write down all of your trials to show the work you have done. +--- + Your instructor may give you a worksheet that you can use to write down -your trials and your explanations. If not, then use any method that you like +your trials and your explanations. If not, use any method that you like to record your trials and your results. Have fun! + +## Complete + +**Great work!** + +Make sure to turn in your lab if your instructor has asked you to do so. + + + ```ghost let number1 = game.askForNumber("First number?") let number2 = game.askForNumber("Second number?") diff --git a/docs/courses/csintro/blocks/unit-2/lab0204.md b/docs/courses/csintro/blocks/unit-2/lab0204.md index 3dca55a1090..a4127a496a5 100644 --- a/docs/courses/csintro/blocks/unit-2/lab0204.md +++ b/docs/courses/csintro/blocks/unit-2/lab0204.md @@ -1,15 +1,16 @@ # Lab 2.4: Silly Story Time! +### @explicitHints true ## Silly stories @showdialog -In this lab, you will create a silly story in MakeCode Arcade! +In this lab, you'll create a silly story in Microsoft MakeCode Arcade! -## First draft +![Lab 2.4](https://arcade.makecode.com/api/_6YYL5gDzd48J/thumb) -First, you need to create a silly story. +## First draft -Start by writing a story. Nothing very long. -Just two or three sentences for now. +First, you need to write a very short story. Use a piece of paper or a word processor. +Nothing very long...just two or three sentences for now. To create a silly version of your story, remove some of the words and replace them with blanks. @@ -21,25 +22,34 @@ Or, you could ask for something a little more specific It's up to you! + ## Ask me anything! Now, let's collect information from the player. +--- + + 1. For each of the blanks in your silly story, create a variable. -Give your variable a good name (like *adjective* or *firstNoun*). +Give your variable a good name (like *adjective1* or *firstNoun*). 1. Ask the player to provide a value for each variable. - - Use the - ``||game:ask for number||`` + - Use
+ ``||game:ask for number||``
for variables that will hold numbers. - - For the rest of the variables, use the + - For the rest of the variables, use the
``||game:ask for string||`` block instead. +--- + + Run your project to make sure that it asks the player for all of the information that you need for your story. Check the hint if you need some help. +#### ~ tutorialhint + ```blocks let aNumber = game.askForNumber("Enter a number.") let aColor = game.askForString("Enter a color.") @@ -49,16 +59,24 @@ let aColor = game.askForString("Enter a color.") Now it's time to show your story. We'll start with a simple presentation. -Use a -``||game:show long text||`` -block with a **join** block +--- + + +Use a
+``||game:show long text||``
+block with a ``||text:join||`` block to display your silly story. -Remember that the **join** block is the **Text** drawer in the +Remember that the **join** block is the ``||text:Text||`` drawer in the **Advanced** section of the toolbox. +--- + + Check the hint if you need some help. +#### ~ tutorialhint + ```blocks let aNumber = game.askForNumber("Enter a number.") let aColor = game.askForString("Enter a color.") @@ -67,22 +85,29 @@ game.showLongText("I am " + aNumber + " years old and my hair color is " + aColo ## Complete @showdialog -Good work! Now, get creative! Try some of these ideas, or try some of your own! +Good work! Now, you can get creative! Try some of these ideas, or try some of your own! + +--- + - Illustrate your story with a background and sprites. - Is there a hero sprite, and if so, will the player be in control of it? Will any sprites move automatically? - Expand your story. Perhaps include multiple scenes. - Add sound effects to your story. -- Add background music to your story. Explore the - ``||music:play melody||`` - block and the - ``||music:play song||`` - block, found in the - ``||music:Music||`` +- Add background music to your story. Explore the
+ ``||music:play melody||``
+ block and the
+ ``||music:play song||``
+ block, found in the
+ ``||music:Music||``
drawer of the toolbox. +--- + Have fun! + + ```ghost let aNumber = game.askForNumber("Enter a number.") let aColor = game.askForString("Enter a color.") @@ -90,4 +115,69 @@ game.splash("I am " + aNumber + " years old and my hair color is " + aColor + "! game.showLongText("", DialogLayout.Center) music.play(music.stringPlayable("- - - - - - - - ", 120), music.PlaybackMode.UntilDone) music.play(music.createSong(hex`00780004080200`), music.PlaybackMode.UntilDone) +controller.A.onEvent(ControllerButtonEvent.Pressed, function () { + if (projectileCount < maxProjectiles) { + fireSprite = sprites.create(lab2imgs.flame, SpriteKind.Projectile) + fireSprite.setPosition(flamethrower.x, flamethrower.y) + fireSprite.setVelocity(0, -200) + fireSprite.setFlag(SpriteFlag.AutoDestroy, true) + projectileCount += 1 + } +}) +sprites.onCreated(SpriteKind.Projectile, function (sprite) { + music.play(music.melodyPlayable(music.pewPew), music.PlaybackMode.InBackground) +}) +sprites.onDestroyed(SpriteKind.Projectile, function (sprite) { + projectileCount += -1 +}) +sprites.onOverlap(SpriteKind.Projectile, SpriteKind.Enemy, function (sprite, otherSprite) { + info.changeScoreBy(1) + sprites.destroy(sprite) + sprites.destroy(otherSprite, effects.spray, 500) + music.play(music.melodyPlayable(music.smallCrash), music.PlaybackMode.InBackground) + enemyVelocity += 5 + if (enemyVelocity > maxEnemyVY) { + enemyVelocity = maxEnemyVY + } +}) +sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) { + info.changeLifeBy(-1) + sprites.destroy(otherSprite, effects.fire, 500) + music.play(music.melodyPlayable(music.smallCrash), music.PlaybackMode.InBackground) +}) +let iceSprite: Sprite = null +let fireSprite: Sprite = null +let maxEnemyVY = 0 +let enemyVelocity = 0 +let maxProjectiles = 0 +let projectileCount = 0 +let flamethrower: Sprite = null +scene.setBackgroundColor(11) +flamethrower = sprites.create(lab2imgs.flamethrower, SpriteKind.Player) +flamethrower.setPosition(80, 110) +controller.moveSprite(flamethrower) +flamethrower.setStayInScreen(true) +info.setScore(0) +info.setLife(3) +projectileCount = 0 +let difficulty = game.askForNumber("Difficulty?") +if (difficulty == 1) { + maxProjectiles = 5 + enemyVelocity = 15 + maxEnemyVY = 100 +} else if (difficulty == 3) { + maxProjectiles = 2 + enemyVelocity = 50 + maxEnemyVY = 200 +} else { + maxProjectiles = 3 + enemyVelocity = 25 + maxEnemyVY = 150 +} +game.onUpdateInterval(1000, function () { + iceSprite = sprites.create(lab2imgs.icecube, SpriteKind.Enemy) + iceSprite.setPosition(randint(8, 152), 0) + iceSprite.setVelocity(0, enemyVelocity) + iceSprite.setFlag(SpriteFlag.AutoDestroy, true) +}) ``` diff --git a/docs/courses/csintro/blocks/unit-2/lab0205-part1.md b/docs/courses/csintro/blocks/unit-2/lab0205-part1.md index b66cda0286f..c3ec68e17d5 100644 --- a/docs/courses/csintro/blocks/unit-2/lab0205-part1.md +++ b/docs/courses/csintro/blocks/unit-2/lab0205-part1.md @@ -1,63 +1,80 @@ # Lab 2.5 Part 1: Pick a Number! +### @explicitHints true ## Pick a number! @showdialog -Let's make a game where the player guesses a number that the game show host +Let's make a game where the player tries to guess a number that the game show host has chosen. +![Lab 2.5.1](https://arcade.makecode.com/api/_cMkLyW8wc8vk/thumb) + + + ## Set the stage Let's set the stage with a sprite for the game show host. -1. To your -``||loops(noclick):on start||`` +--- + + +1. To your
+``||loops(noclick):on start||``
container, add a block that creates a -sprite for your game show host. - - Give the sprite an appropriate variable name. - - Give the sprite an appropriate image. +sprite for your host. + - Give the sprite an appropriate variable name + - Give the sprite an appropriate image - Have the game show host say, "Guess which number I am thinking of." - - At the bottom of your - ``||loops(noclick):on start||`` - container, add a - ``||loops:pause (500) ms||`` - block from the - ``||loops:Loops||`` + - At the bottom of your
+ ``||loops(noclick):on start||``
+ container, add a
+ ``||loops:pause (500) ms||``
+ block from the
+ ``||loops:Loops||``
drawer. - - Set the pause to `1000` milliseconds. We want the game to pause + - Set the pause to something between **`2000`** and **`5000`** milliseconds. We want the game to pause long enough for the player to read the prompt. - - Feel free to change the length of the pause to a different value. + +--- + Run your project to make sure it works as expected. -View the hint if you need some help. + + + +#### ~ tutorialhint ```blocks let hostSprite = sprites.create(sprites.castle.princessFront0, SpriteKind.Player) hostSprite.sayText("Guess which number I am thinking of.") -pause(1000) +pause(5000) ``` ## Let's be random! Now, we need the host to pick a number. +--- + + 1. Create a new variable that will hold your game show host's secret number. -1. To the **bottom** of your -``||loops(noclick):on start||`` +1. To the **bottom** of your
+``||loops(noclick):on start||``
container, -set the value of your new variable to a random number from 1 to 10. - - Remember that the - ``||math:pick random||`` - block is in the - ``||math:Math||`` +set the value of your new variable to a random number between 1 and 10. + - Remember that the
+ ``||math:pick random||``
+ block is in the
+ ``||math:Math||``
drawer. -View the hint if you need some help. + +#### ~ tutorialhint ```blocks let hostSprite = sprites.create(sprites.castle.princessFront0, SpriteKind.Player) hostSprite.sayText("Guess which number I am thinking of.") -pause(2000) +pause(5000) // @highlight let hostsNumber = randint(1, 10) ``` @@ -66,19 +83,27 @@ let hostsNumber = randint(1, 10) Now, let's get the player's guess. +--- + + 1. Create a new variable that will hold the player's guess. 1. To the **bottom** of your -``||loops(noclick):on start||`` +``||loops(noclick):on start||``
container, ask the player for a number. Store the guess in your new variable. +--- + + Run your project to make sure it works as expected. View the hint if you need some help. +#### ~ tutorialhint + ```blocks let hostSprite = sprites.create(sprites.castle.princessFront0, SpriteKind.Player) hostSprite.sayText("Guess which number I am thinking of.") -pause(2000) +pause(5000) let hostsNumber = randint(1, 10) // @highlight let playerGuess = game.askForNumber("Choose a number between 1 and 10.") @@ -87,42 +112,67 @@ let playerGuess = game.askForNumber("Choose a number between 1 and 10.") ## Was I right? Now, let's see if the player was correct! To do so, we need to create a -*conditional statement*. +*conditional* statement. + +~hint What is a conditional? + +--- + +A conditional tests whether something is true or false. It only +runs the associated code under the _condition_ that the statement was true. + +We are going to add a conditional in the form of an ``||logic(noclick):if / else||`` statement. + +```block +if (true) { + +} else { + +} +``` + -~hint What is a conditional statement? -A conditional statement is sometimes called an "if" statement. -It tests whether something is true or false. hint~ -1. To the **bottom** of your -``||loops(noclick):on start||`` +--- + + +1. To the **bottom** of your
+``||loops(noclick):on start||``
container, -add an -``||logic:if (true) then [] else []||`` -block. You'll find that block in the -``||logic:Logic||`` +add an
+``||logic:if (true) then [] else []||``
+block. You'll find that block in the
+``||logic:Logic||``
drawer. -1. In place of the -``||logic(noclick):(true)||`` -value, drop a -``||logic:(0) = (0)||`` -block. You will find that in the +1. In place of the
+``||logic(noclick):(true)||``
+value, drop a
+``||logic:<(0) = (0)>||``
+block. You will find that in the
``||logic:Logic||`` drawer, also. -1. Use blocks from the -``||variables:Variables||`` +1. Use blocks from the
+``||variables:Variables||``
drawer to make the -block say something like this: +block say something like this:
``||logic(noclick):if||`` ``||variables(noclick):hostsNumber||`` ``||logic(noclick):=||`` ``||variables(noclick):playerGuess||`` -Use the hint to check your code. We'll fill in the -``||logic(noclick):if||`` + +--- + +Use the hint to check your code. + +We'll fill in the +``||logic(noclick):if / else||`` container next. +#### ~ tutorialhint + ```blocks let hostSprite = sprites.create(sprites.castle.princessFront0, SpriteKind.Player) hostSprite.sayText("Guess which number I am thinking of.") -pause(2000) +pause(5000) let hostsNumber = randint(1, 10) let playerGuess = game.askForNumber("Choose a number between 1 and 10.") if (hostsNumber == playerGuess) { @@ -134,26 +184,34 @@ if (hostsNumber == playerGuess) { ## Say what? -Now, complete the ``||logic(noclick):if||`` container. +Time to fill up the ``||logic(noclick):if / else||`` container. + +--- + + +- In the top half of the container,
+(the ``||logic(noclick):if||``)
+add blocks to make the host +say that the player was correct.
+ - Use a **join** block to also show the correct number +- In the bottom half of the container,
+(the ``||logic(noclick):else||``)
+add blocks to make the host +say that the player was incorrect.
+ - Use a **join** block to also show the correct number + +--- -- In the top half of the -``||logic(noclick):if||`` -container, add blocks to make the game show host -say that the player was correct. -Use a **join** block to also show the host's number. -- In the bottom half of the -``||logic(noclick):if||`` -container, add block to make the game show host -say that the player was incorrect. -Use a **join** block to also show the host's number. Run your project to see if your code works as expected. Use the hint to check your code. +#### ~ tutorialhint + ```blocks let hostSprite = sprites.create(sprites.castle.princessFront0, SpriteKind.Player) hostSprite.sayText("Guess which number I am thinking of.") -pause(2000) +pause(5000) let hostsNumber = randint(1, 10) let playerGuess = game.askForNumber("Choose a number between 1 and 10.") if (hostsNumber == playerGuess) { @@ -165,12 +223,18 @@ if (hostsNumber == playerGuess) { ## Complete @showdialog -Good work! Let's use conditional statements to create another game in Part 2! +**Good work!** +🥳 🥳 🥳 + +We'll use conditional statements to create another game in Part 2! + + + ```ghost let hostSprite = sprites.create(sprites.castle.princessFront0, SpriteKind.Player) hostSprite.sayText("Guess which number I am thinking of.") -pause(2000) +pause(5000) let hostsNumber = randint(1, 10) let playerGuess = game.askForNumber("Choose a number between 1 and 10.") if (hostsNumber == playerGuess) { diff --git a/docs/courses/csintro/blocks/unit-2/lab0205-part2.md b/docs/courses/csintro/blocks/unit-2/lab0205-part2.md index 4bb09ba0572..07a5a4c3b11 100644 --- a/docs/courses/csintro/blocks/unit-2/lab0205-part2.md +++ b/docs/courses/csintro/blocks/unit-2/lab0205-part2.md @@ -1,42 +1,57 @@ # Lab 2.5 Part 2: Can You Even? +### @explicitHints true ## Is it even? @showdialog -Many programs need to test whether a number is even or odd. Let's write one! +Many programs need to test whether a number is even or odd. + +Let's write a tool for that! + +![Lab 2.5.2](https://arcade.makecode.com/api/_bFJerdL13K0e/thumb) + ## Collecting the evidence First, let's get a number to test from the player. +--- + + 1. Create a variable that will store the player's number. -1. To your -``||loops(noclick):on start||`` -container, -add blocks that ask the player for a number. -Store the response in your new variable. +1. To your ``||loops(noclick):on start||`` +container, add blocks that ask the player for a number. +(Store the response in your new variable.) + +--- + Run your project to test your code. You can also check the hint. +#### ~ tutorialhint + ```blocks let theNumber = game.askForNumber("Enter a number.") ``` -## So, is it even or not? +## Is it even or not? Now, let's display a message to say whether the number is even. You guessed it: We need to write another conditional statement! -1. To the **bottom** of your -``||loops(noclick):on start||`` -container, add an -``||logic:if (true) then [] else []||`` +--- + + +1. To the **bottom** of your
+``||loops(noclick):on start||``
+container, add an
+``||logic:if (true) then [] else []||``
block. -1. Use blocks from the -``||variables:Variables||``, -``||logic:Logic||``, and -``||math:Math||`` -drawers to make the block say the following: +1. Use blocks from the
+``||variables:Variables||``,
+``||logic:Logic||``, and
+``||math:Math||``
+drawers to make the block say the following:
``||logic(noclick):if||`` ``||math(noclick):remainder of||`` ``||variables(noclick):(your variable)||`` ``||math(noclick):/ (2)||`` ``||logic(noclick):= (0) then||``. @@ -44,11 +59,19 @@ drawers to make the block say the following: add blocks to display an appropriate message. ~hint How do I know if the number is even? + +--- + If the number is even then, when you divide it by two, the remainder is zero. hint~ +--- + + Run your project to test your code. Check the hint if you get stuck. +#### ~ tutorialhint + ```blocks let theNumber = game.askForNumber("Enter a number.") if (theNumber % 2 == 0) { @@ -60,7 +83,10 @@ if (theNumber % 2 == 0) { ## Complete @showdialog -Good work! Let's make a fortune telling device in Part 3! +**Good work!** +🎉 🎉 🎉 + +Let's make a fortune telling device in Part 3! ```ghost let theNumber = game.askForNumber("Enter a number.") diff --git a/docs/courses/csintro/blocks/unit-2/lab0205-part3.md b/docs/courses/csintro/blocks/unit-2/lab0205-part3.md index d2ed7dd1ce9..14f3daf8366 100644 --- a/docs/courses/csintro/blocks/unit-2/lab0205-part3.md +++ b/docs/courses/csintro/blocks/unit-2/lab0205-part3.md @@ -1,4 +1,5 @@ # Lab 2.5 Part 3: Magic Four Ball! +### @explicitHints true ## Magic four ball! @showdialog @@ -6,26 +7,37 @@ Some people need help making big decisions. You can help them by making a magic four ball. It's like a magic eight ball, but with only four answers! +![Lab 2.5.3](https://arcade.makecode.com/api/_59T26bVHiHV8/thumb) + ## Ask me anything (again)! Let's set the scene so that the player has a character to talk to. -1. In your -``||loops(noclick):on start||`` +--- + + +1. In your
+``||loops(noclick):on start||``
container, create a sprite that represents the fortune teller. - - Give the sprite variable an appropriate name. - - Give the sprite an appropriate image. + - Give the sprite variable an appropriate name + - Give the sprite an appropriate image - Make the sprite say something like, "Think of a question, then press the A button." +--- + + Run your program and see if it behaves as expected. + Check the hint if you need some help. +#### ~ tutorialhint + ```blocks let fortuneTellerSprite: Sprite = null -scene.setBackgroundColor(9) -fortuneTellerSprite = sprites.create(sprites.builtin.villager1WalkFront1, SpriteKind.Player) +scene.setBackgroundColor(1) +fortuneTellerSprite = sprites.create(lab2imgs.crystal_ball, SpriteKind.Player) fortuneTellerSprite.sayText("Think of a question, then press the A button.") ``` @@ -33,37 +45,42 @@ fortuneTellerSprite.sayText("Think of a question, then press the A button.") Now, let's respond to the player's question with a random response. -1. Add a -``||controller:on (A) button (pressed)||`` +--- + + +Add an
+``||controller:on (A) button (pressed)||``
container to your workspace. All of the following blocks will go in this container. 1. Create a new variable called **answer**. 1. Set this new variable to a random number from 1 to 4. -Remember that the +Remember that the
``||math:pick random||`` block is in the ``||math:Math||`` drawer. -1. Now, add an -``||logic:if (true) then [] else []||`` -block. -1. Select the **(+)** plus sign to add enough branches to your -``||logic(noclick):if||`` -block to handle four different options. -1. Add blocks to your -``||logic(noclick):if||`` -block to make each branch say -something like -``||logic(noclick):if||`` ``||variables(noclick):answer||`` -``||logic(noclick): = (1) then||`` -1. In each branch of the -``||logic(noclick):if||`` -block, make the fortune teller say a different message. - - Make each message unique. +1. Add an
+``||logic:if (true) then [] else []||``
+container. +1. Select the **(+)** plus sign to add enough branches to your
+``||logic(noclick):if / else||``
+container to handle four different options. +1. Add enough conditionals from the ``||logic(noclick):Logic||`` drawer to your
+``||logic(noclick):if / else||`` container to make the branches say +something like
+``||logic(noclick):if < answer = (1) > then||`` +1. In each branch of the
``||logic(noclick):if / else||`` container, make the fortune teller say a different message. + - Make each message unique - Be creative! - - Try to have an equal number of positive and negative responses. + - Try to have an equal number of positive and negative responses + +--- + Run your program and see if it behaves as expected. + Check the hint if you need some help. +#### ~ tutorialhint + ```blocks controller.A.onEvent(ControllerButtonEvent.Pressed, function () { option = randint(1, 4) @@ -79,14 +96,24 @@ controller.A.onEvent(ControllerButtonEvent.Pressed, function () { }) let option = 0 let fortuneTellerSprite: Sprite = null -scene.setBackgroundColor(9) -fortuneTellerSprite = sprites.create(sprites.builtin.villager1WalkFront1, SpriteKind.Player) +scene.setBackgroundColor(1) +fortuneTellerSprite = sprites.create(lab2imgs.crystal_ball, SpriteKind.Player) fortuneTellerSprite.sayText("Think of a question, then press the A button.") ``` ## Complete @showdialog -Good work! What are some other ways that you could use conditional statements? +Great work! +🎈 🎈 🎈 + +What are some other ways that you could use conditional statements? + + + + +```package +lab2imgs=github:kiki-lee/lab2imgs#v0.0.2 +``` ```ghost controller.A.onEvent(ControllerButtonEvent.Pressed, function () { @@ -103,7 +130,7 @@ controller.A.onEvent(ControllerButtonEvent.Pressed, function () { }) let option = 0 let fortuneTellerSprite: Sprite = null -scene.setBackgroundColor(9) -fortuneTellerSprite = sprites.create(sprites.builtin.villager1WalkFront1, SpriteKind.Player) +scene.setBackgroundColor(1) +fortuneTellerSprite = sprites.create(lab2imgs.crystal_ball, SpriteKind.Player) fortuneTellerSprite.sayText("Think of a question, then press the A button.") ``` diff --git a/docs/static/courses/csintro/Unit2LabThumbnail-2-1-1.png b/docs/static/courses/csintro/Unit2LabThumbnail-2-1-1.png index da717e0c72e..60d67d6f47a 100644 Binary files a/docs/static/courses/csintro/Unit2LabThumbnail-2-1-1.png and b/docs/static/courses/csintro/Unit2LabThumbnail-2-1-1.png differ diff --git a/docs/static/courses/csintro/Unit2LabThumbnail-2-1-2.png b/docs/static/courses/csintro/Unit2LabThumbnail-2-1-2.png index 8540559cf5f..3ef2aa6b95c 100644 Binary files a/docs/static/courses/csintro/Unit2LabThumbnail-2-1-2.png and b/docs/static/courses/csintro/Unit2LabThumbnail-2-1-2.png differ diff --git a/docs/static/courses/csintro/Unit2LabThumbnail-2-1-3.png b/docs/static/courses/csintro/Unit2LabThumbnail-2-1-3.png index f6edf7c68f4..15e13399639 100644 Binary files a/docs/static/courses/csintro/Unit2LabThumbnail-2-1-3.png and b/docs/static/courses/csintro/Unit2LabThumbnail-2-1-3.png differ diff --git a/docs/static/courses/csintro/Unit2LabThumbnail-2-1-4.png b/docs/static/courses/csintro/Unit2LabThumbnail-2-1-4.png index 6a9119feb07..9332a47fe63 100644 Binary files a/docs/static/courses/csintro/Unit2LabThumbnail-2-1-4.png and b/docs/static/courses/csintro/Unit2LabThumbnail-2-1-4.png differ diff --git a/docs/static/courses/csintro/Unit2LabThumbnail-2-1-5.png b/docs/static/courses/csintro/Unit2LabThumbnail-2-1-5.png index 19aa7db75c8..15e02fbe3b3 100644 Binary files a/docs/static/courses/csintro/Unit2LabThumbnail-2-1-5.png and b/docs/static/courses/csintro/Unit2LabThumbnail-2-1-5.png differ diff --git a/docs/static/courses/csintro/Unit2LabThumbnail-2-6-1.png b/docs/static/courses/csintro/Unit2LabThumbnail-2-6-1.png index ba3a1fa2701..342de290795 100644 Binary files a/docs/static/courses/csintro/Unit2LabThumbnail-2-6-1.png and b/docs/static/courses/csintro/Unit2LabThumbnail-2-6-1.png differ diff --git a/docs/static/courses/csintro/Unit2LabThumbnail-2-6-2.png b/docs/static/courses/csintro/Unit2LabThumbnail-2-6-2.png index aba6117ef44..793170bc063 100644 Binary files a/docs/static/courses/csintro/Unit2LabThumbnail-2-6-2.png and b/docs/static/courses/csintro/Unit2LabThumbnail-2-6-2.png differ diff --git a/docs/static/courses/csintro/Unit2LabThumbnail-2-6-3.png b/docs/static/courses/csintro/Unit2LabThumbnail-2-6-3.png index 59c546d6182..cfe1d5a829f 100644 Binary files a/docs/static/courses/csintro/Unit2LabThumbnail-2-6-3.png and b/docs/static/courses/csintro/Unit2LabThumbnail-2-6-3.png differ diff --git a/docs/static/courses/csintro/Unit2LabThumbnail-2-6-4.png b/docs/static/courses/csintro/Unit2LabThumbnail-2-6-4.png index de1e49ec15b..f661fbd9c83 100644 Binary files a/docs/static/courses/csintro/Unit2LabThumbnail-2-6-4.png and b/docs/static/courses/csintro/Unit2LabThumbnail-2-6-4.png differ