Skip to content

Commit

Permalink
Polishing off changes to Unit 2 (#6724)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiki-lee committed Feb 24, 2025
1 parent 061e50f commit bd99ba0
Show file tree
Hide file tree
Showing 16 changed files with 699 additions and 269 deletions.
273 changes: 191 additions & 82 deletions docs/courses/csintro/blocks/unit-2/lab0202-part1.md

Large diffs are not rendered by default.

143 changes: 111 additions & 32 deletions docs/courses/csintro/blocks/unit-2/lab0202-part2.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Lab 2.2 Part 2: How Many Items?
### @explicitHints true

## How many items? @showdialog

Expand All @@ -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)
Expand All @@ -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 () {
Expand All @@ -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 <br/>
``||loops(noclick):on start||`` <br/>
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))
Expand All @@ -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 () {
Expand All @@ -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 <br/>
``||sprites:on overlap||`` <br/>
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) {
Expand All @@ -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!")
Expand Down
85 changes: 60 additions & 25 deletions docs/courses/csintro/blocks/unit-2/lab0203.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,117 @@
# 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 <br/>
``||loops(noclick):on start||`` <br/>
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?")
```

## 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 <br/>
``||loops(noclick):on start||`` <br/>
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?")
Expand Down
Loading

0 comments on commit bd99ba0

Please sign in to comment.