Skip to content

Commit

Permalink
Finishing Unit 3 and updating GJiaB (#6742) (#6746)
Browse files Browse the repository at this point in the history
* Finishing Unit 3 and updating GJiaB

* Delete .vscode/settings.json

This shouldn't have been in there

* Update docs/courses/csintro/blocks/unit-3/lab0304-part3.md



* Update docs/courses/csintro/blocks/unit-3/lab0304-part3.md



* Update imageUrl in skillmap.md

Adding actual thumbnail to last lesson

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
  • Loading branch information
kiki-lee and Copilot authored Mar 3, 2025
1 parent 90bf549 commit 929965e
Show file tree
Hide file tree
Showing 14 changed files with 1,334 additions and 576 deletions.
8 changes: 6 additions & 2 deletions docs/courses/csintro.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ Labs from each unit are grouped in the tiles below.
]
```

<!-->

## Individual Tutorials

Individual activities from the tiles above are provided as standalone tutorials below.

<!---
### Blocks semester
-->
#### Unit 0 Activities
Expand Down Expand Up @@ -235,7 +237,7 @@ Individual activities from the tiles above are provided as standalone tutorials
"name": "Lab 3.4",
"description": "High scores",
"url": "https://arcade.makecode.com/--skillmap#docs:/courses/csintro/blocks/unit-3/lab-3-4-skillmap",
"imageUrl": "https://arcade.makecode.com/api/S61379-50555-16499-36625/thumb"
"imageUrl": "https://arcade.makecode.com/api/_6t78hiKYxRpt/thumb"
}, {
"name": "Lab 3.5",
"description": "Animated sprites",
Expand All @@ -244,12 +246,14 @@ Individual activities from the tiles above are provided as standalone tutorials
}
]
```
-->

## See also

[Courses Home Page](/courses),
[Arcade Tutorials](/tutorials),
[Beginner Skillmaps](/beginner-maps),
[Kiki's Corner](https://medium.com/kikis-corner),

### ~hint

Expand Down
157 changes: 117 additions & 40 deletions docs/courses/csintro/blocks/unit-3/lab0301-part1.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Lab 3.1 Part 1: Introduction to loops
# Lab 3.1 Part 1: Repeat That, Please
### @explicitHints true

## Repeat that, please! @showdialog

In this lab, we will explore a family of loops called *definite loops*.

*Definite loops* are loops that run a specific number of times.

In Part 1, we'll use one of those loops: The **repeat** loop.
In Part 1, we'll use one of those loops: the **repeat** loop.


```block
let foodSprite: Sprite = null
Expand All @@ -16,29 +18,48 @@ for (let index = 0; index < 6; index++) {
}
```

<br/>

---

<br/>


![Lab 3.1.1](https://arcade.makecode.com/api/_KLfa0XDaz1Vo/thumb)



## Take an apple; leave an apple

Let's create a hero character and drop food randomly on the screen.
Let's create a hero sprite and drop food randomly on the screen.

---

1. Create a sprite for your hero character
- Give the sprite's variable an appropriate name
- Give the sprite an image
1. Allow the player to move the hero sprite around the screen
1. Whenever the player presses **A**, add a new sprite to the screen
- Give the new sprite's variable an appropriate name
- Give the sprite an image
- Place the sprite at a random location on the screen

---

1. Create a sprite for your hero character.
- Give the sprite's variable an appropriate name.
- Give the sprite an image.
1. Allow the player to move the hero sprite around the screen.
1. Whenever the player presses **A**, add a sprite to the screen.
- Give the new sprite's variable an appropriate name.
- Give the sprite an image.
- Place the sprite at a random location on the screen.

Run your project and verify that it works as described.

Check the hint if you need any help.

#### ~ tutorialhint

```blocks
controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
foodSprite = sprites.create(sprites.food.smallApple, SpriteKind.Player)
foodSprite.setPosition(randint(8, 152), randint(8, 112))
})
let foodSprite: Sprite = null
let heroSprite = sprites.create(sprites.food.smallTaco, SpriteKind.Player)
let heroSprite = sprites.create(sprites.castle.princess2Right1, SpriteKind.Player)
controller.moveSprite(heroSprite)
```

Expand All @@ -49,26 +70,51 @@ wanted to drop two pieces of food. That's easy enough to do: just duplicate
the blocks that we have.

But what if we wanted to drop three? Or five?
Or ten? Or what if you wanted to change the number of sprites throughout
Or ten? Or what if you wanted to change the number of sprites dropped throughout
the game?

There is a better way to do this: Use a **repeat** loop.

1. From the
``||loops:Loops||`` drawer, drop a
``||loops:repeat (4) times||``
loop into your
``||controller(noclick): on (A) button (pressed)||``
container.
1. Move the other blocks in that container to the **inside** of the
``||loops(noclick):repeat||`` container.
1. Change the number of repeats to **2**.
~hint What is a Repeat Loop? πŸ€·πŸ½β€β™€οΈ

---

In MakeCode Arcade, we call this a **repeat loop**:

```block
for (let index = 0; index < 4; index++) { }
```

This loop allows you to tell the computer how many times you want the code inside to run, then it will repeat the code that many times before moving on.

_Note: The repeat will only include the code **inside** the container.
It will keep looping through that code until it has run the number of times that you
asked it to, and once it's done it will immediately continue running the rest of your program._

hint~

---


1. From the
``||loops:Loops||`` drawer, drop a <br/>
``||loops:repeat (4) times||`` <br/>
loop into **the top** of your <br/>
``||controller(noclick): on (A) button (pressed)||`` <br/>
container
1. Move the existing blocks from that container **into** the
``||loops(noclick):repeat||`` loop
1. Change the number of repeats to **2**

---

Run your project and verify that the player drops **two** pieces of food
each time you press **A**.

Check the hint if you need help.

#### ~ tutorialhint

```blocks
controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
for (let index = 0; index < 2; index++) {
Expand All @@ -81,43 +127,71 @@ let foodSprite: Sprite = null

## Kick the tires!

Give your new loop a try! As you try different **repeat** values,
Experiment with your new loop! As you try different **repeat** values,
answer the questions below.

---


**Questions**

- Are there any numbers that are **not** allowed as a repeat value?
- Are there any numbers that are **not** allowed to be a repeat value?
- Are there any numbers that work in unexpected ways?
- How might you use a **repeat** block in your own projects?

## Food fight!

Instead of dropping food at random locations, let's throw projectiles
from the player.
Instead of dropping food at random locations, let's make it look like the hero is throwing it!

---


1. **Delete** all of the blocks inside of the ``||loops(noclick):repeat||`` container.
Keep the loop, though!
1. Add the following blocks to your ``||loops(noclick):repeat||`` loop:
1. Create a variable called **speedX**.
1. Set **speedX** to a random value between 10 and 40.
1. Create another variable called **speedY**.
1. Add blocks so that it reads:
``||variables:set speedY to||`` ``||math:50 -||``
``||variables:speedX||``.
1. Create a projectile that starts at your hero sprite with
velocities **speedX** and **speedY**.
1. Create a variable called **speedX**
1. Initialize **speedX** to a random value between 10 and 40
1. Create another variable called **speedY**
1. Set **speedY** so that it reads:<br/>
``||variables:set [speedY] to [50 - speedX]||``
1. Create a projectile that starts from your hero sprite with velocities of
**speedX** and **speedY** (for x and y respectively)

These blocks will send the projectiles in random(ish) directions, but will
keep their speeds roughly the same.


~hint A Different Projectile πŸš€

These blocks will send the projectiles in random directions, but will
keeps their speeds roughly the same.
---

Run your project and see how it operates differently from before.
In previous projects, we created projectiles as if they were normal sprites,
then we added extra blocks to set starting positions and velocity.

Try different repeat values!
This time, we want to use the built-in ``||variables(sprites): set [projectile]||`` block
to create the projectile, and have it do all the rest for us!

How might you use this mechanism in your own projects?
```block
let speedX = 0
let speedY = 0
let foodSprite: Sprite = sprites.createProjectileFromSprite(sprites.food.smallApple, heroSprite, speedX, speedY)
```

hint~

---


Run your project and see how it operates now.
Try different values for the repeat!

How might you use this in your own projects?

Check the hint if you need any help.

#### ~ tutorialhint

```block
controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
for (let index = 0; index < 2; index++) {
Expand All @@ -130,7 +204,10 @@ controller.A.onEvent(ControllerButtonEvent.Pressed, function () {

## Complete! @showdialog

Good work! You have worked with the **repeat** loop!
**Good work!** <br/>
πŸ‘πŸ½ πŸ‘πŸ½ πŸ‘πŸ½

You have successfully used the **repeat** loop!

Try these extensions if you have time:

Expand Down
Loading

0 comments on commit 929965e

Please sign in to comment.