![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2021/12/ratch_kao_dounaru.png)
こんにちは!
「ステップアップドリル:変数ブロックの使い方入門」に ようこそ!
「スクラッチしよう!楽しく学ぶプログラミング教室」の担任ラッチです。
![スック](https://scratchsiyou.com/wp-content/uploads/2022/01/sukku_futu-300x300.png)
スックだよ!
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2021/12/ratch_kao_dounaru.png)
今回の「ステップアップドリル」で作る作品は、こちら!
![「スクラッチしよう!8-1-06 ステップアップドリル:ねっちボール 迷路!」 scratch](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-gif2-1.gif)
![スック](https://scratchsiyou.com/wp-content/uploads/2022/01/sukku_futu-300x300.png)
敵が 迷路の中を 自由に 動くよ
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2021/12/ratch_kao_dounaru.png)
敵が 動く速さは 毎回 ちがうよ
ローカル変数「てきの速さ」ブロックが 使われているんだ
![変数ブロック](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation1.png)
![変数表示](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation3-1.png)
![新しい変数](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation2.png)
![スック](https://scratchsiyou.com/wp-content/uploads/2023/11/sukku_futu-1-300x300.png)
動く方向も ちがうね
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2021/12/ratch_kao_dounaru.png)
そう!敵が 迷路の中を 自由に 動き回るプログラムに したよ
それでは、ローカル変数が どのように使われているか 学んでいこう
![スック](https://scratchsiyou.com/wp-content/uploads/2023/09/sukku_ok-300x300.png)
いいよ!
今回作るスクラッチの作品は、これっ!
![スック](https://scratchsiyou.com/wp-content/uploads/2023/07/sukku_futu-1-300x300.png)
迷路は 自分で 作成できるよ
今回のプログラミングで 学ぶことは
1.てきが 通路のまん中を 走るスクリプトが わかるよ
2.てき ごとに 動く速さが ちがう スクリプトが わかるよ
3.ねっちボールを 指で 上下左右に動かす スクリプトが わかるよ
4.ゲーム‐オーバーと クリアの スクリプトが わかるよ
![「スクラッチしよう!8-1-06 ステップアップドリル:ねっちボール 迷路!」 scratch ゲームオーバーとクリア](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation6.png)
プログラミングの仕方を説明します
通路のまん中を 走るプログラミング
1.てきが 通路のまん中を 動くスクリプトが わかるよ
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2021/12/ratch_kao_dounaru.png)
最初に、スプライト「迷路」を 描きます
![「スクラッチしよう!8-1-06 ステップアップドリル:ねっちボール 迷路!」 scratch スプライト「迷路」](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation7-1.png)
フリーBGM:DOVA-SYNDROME 午後のカメレオンは星の波動を数え… written by Masuo
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2021/12/ratch_kao_dounaru.png)
次に、スプライト「てき」「ねっちボール」「ゴール」と背景を 追加します
![「スクラッチしよう!8-1-06 ステップアップドリル:ねっちボール 迷路!」 scratch スプライトと背景](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation7-1-1.png)
![「スクラッチしよう!8-1-06 ステップアップドリル:ねっちボール 迷路!」 scratch 各スプライトのコスチューム](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation19-1.png)
![スック](https://scratchsiyou.com/wp-content/uploads/2023/07/sukku_futu-1-300x300.png)
スプライト「ねっちボール」の 作り方は
この動画を 見てね
フリーBGM:DOVA-SYNDROME 午後のカメレオンは星の波動を数え… written by Masuo
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2021/12/ratch_kao_dounaru.png)
では、スプライト「てき」の
![「スクラッチしよう!8-1-06 ステップアップドリル:ねっちボール 迷路!」 scratch スプライト「てき」](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation12.png)
プログラムから 作りましょう
![スック](https://scratchsiyou.com/wp-content/uploads/2023/07/sukku_futu-1-300x300.png)
O.K!
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2021/12/ratch_kao_dounaru.png)
「てき」が 迷路の中を 動く時 通路のまん中を 通るように します。
![スック](https://scratchsiyou.com/wp-content/uploads/2023/12/sukku_futu-1-300x300.png)
うん、うん。
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2021/12/ratch_kao_dounaru.png)
この真ん中を 通るプログラムは、
てきが 隣の マス目(20px)へ 移動することで できるんだ
![スック](https://scratchsiyou.com/wp-content/uploads/2023/12/sukku_are-1-300x300.png)
あぁ、なるほど
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2021/12/ratch_kao_dounaru.png)
「○歩動かす」ブロックで
![「○歩動かす」ブロック](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation20.png)
てきを 20px動かすことができるんだ
![スック](https://scratchsiyou.com/wp-content/uploads/2023/12/sukku_futu-1-300x300.png)
つまり、てきの1歩は、1px なんだね!
![「スクラッチしよう!8-1-06 ステップアップドリル:ねっちボール 迷路!」 scratch 1歩動かす=1px](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation22.png)
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2023/12/ratch_kao_yes-300x300.png)
そのとぉぉぉ……り!
それでは、「ずっと」ブロックを 使って てきを 動かしてみるよ
![「ずっと」ブロック](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation23.png)
![スック](https://scratchsiyou.com/wp-content/uploads/2023/12/sukku_wao-300x300.png)
あらっ!速すぎなぁ~い
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2023/12/ratch_kao_dounaru.png)
そうだね!
そういう時は、「○回繰り返す」ブロックを 使うと
![「○回繰り返す」ブロック](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation24.png)
てきの動く速さを 変えることが できるんだ
![「○歩動かす」ブロック](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-v48-2.png)
![「スクラッチしよう!8-1-06 ステップアップドリル:ねっちボール 迷路!」 scratch スプライト「てき」動く速さ10](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation26-3.png)
![「スクラッチしよう!8-1-06 ステップアップドリル:ねっちボール 迷路!」 scratch スプライト「てき」動く速さ5](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation28-2.png)
![「スクラッチしよう!8-1-06 ステップアップドリル:ねっちボール 迷路!」 scratch スプライト「てき」動く速さ4](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation30-3.png)
![「スクラッチしよう!8-1-06 ステップアップドリル:ねっちボール 迷路!」 scratch スプライト「てき」動く速さ2](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation32-3.png)
![スック](https://scratchsiyou.com/wp-content/uploads/2023/12/sukku_are-1-300x300.png)
なるほどね。
動く速さ×くりかえし回数= 20に なって
次のマス目に 移動するんだね
![「スクラッチしよう!8-1-06 ステップアップドリル:ねっちボール 迷路!」 scratch スプライト「てき」動く速さ4](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-v49.png)
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2023/12/ratch_kao_dounaru.png)
そう!これが 前に進むプログラム。
そして、
迷路の黒い壁に ぶつかったら、方向を変える プログラムを 作るよ
・ 迷路の壁に ぶつかる
・ 20歩 下がる(元のマス目に もどる)
・ 方向(上・下・右・左)をランダムに 決める
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2023/12/ratch_kao_dounaru.png)
「もし○なら」ブロックを 使って
![「もし○なら」ブロック](https://scratchsiyou.com/wp-content/uploads/2024/01/scratchdrillocal06-explanation74.png)
壁に当たったら、元のマスに戻るように するよ
![スック](https://scratchsiyou.com/wp-content/uploads/2023/12/sukku_are-1-300x300.png)
あっ!ほんとだ
壁に ぶつかったら、下がったぞ
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2023/12/ratch_kao_dounaru.png)
でしょ!
そして、そこで、「○度に 向ける」ブロックを 使って
![「○度に向ける」ブロック](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation35.png)
方向を ランダムに 決めるんだ
![スック](https://scratchsiyou.com/wp-content/uploads/2023/12/sukku_question-1-300x300.png)
うぅ…ん?
「○から○までの乱数」ブロックは
「0,1,2,3 」が ばらばらに 出てくるんだよね…
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2023/12/ratch_kao_dounaru.png)
「○度に向ける」ブロックの
![「○度に向ける」ブロック](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation35-1.png)
プログラムは これ!
![「スクラッチしよう!8-1-06 ステップアップドリル:ねっちボール 迷路!」 scratch スプライト「てき」上下左右の向き](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation48-800x750.png)
![スック](https://scratchsiyou.com/wp-content/uploads/2023/12/sukku_futu-1-300x300.png)
なるほどね!
「0、90,180,270」が ランダムに 出てくるんだね
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2023/12/ratch_kao_dounaru.png)
そうなんだ!そして これが、
壁にぶつかったら 方向を変える プログラムだよ
![「もし○なら」ブロック](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation33-1.png)
![](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation49.png)
![スック](https://scratchsiyou.com/wp-content/uploads/2023/12/sukku_futu-1-300x300.png)
壁に ぶつかると
方向が 変わる仕組みが わかったよ
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2023/12/ratch_kao_dounaru.png)
そして、前に進むプログラムを 合体させれば
![「スクラッチしよう!8-1-06 ステップアップドリル:ねっちボール 迷路!」 scratch スプライト「てき」動くスクリプト](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation51.png)
てきは、通路のまん中を通り、迷路を自由に 動き回るようになるんだ
![スック](https://scratchsiyou.com/wp-content/uploads/2023/12/sukku_are-1-300x300.png)
たった?!
7つのブロックで できるの…
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2023/12/ratch_kao_dounaru.png)
すごいでしょう!
それでは、「x座標を○、y座標を○にする」ブロックを 使って
![「x座標を○、y座標を○にする」ブロック](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation52.png)
スタート位置を決めて てきを 動かしてみるよ
1.通路のまん中を 通って 迷路の中を 自由に動く
![スック](https://scratchsiyou.com/wp-content/uploads/2023/12/sukku_futu-1-300x300.png)
簡単に できちゃうんだね!
てきの 動く速さが ちがうプログラミング
2.てき ごとに 動く速さが ちがう スクリプトが わかるよ
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2023/12/ratch_kao_dounaru.png)
それでは 「○のクローンを作る」ブロックを 使って
![「○のクローンを作る」ブロック](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation56-1.png)
てきを 4体に しましょう
![スック](https://scratchsiyou.com/wp-content/uploads/2023/12/sukku_futu-1-300x300.png)
「隠す」ブロックで
![「隠す」ブロック](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation57-2.png)
スプライト「てき」を 隠すよ!
1.てきを 4体に する
![スック](https://scratchsiyou.com/wp-content/uploads/2023/12/sukku_are-2-300x300.png)
あれっ?4体のてきは、
毎回 最初は 右に動くんだね…
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2023/12/ratch_kao_yes-1-300x300.png)
おぉぅぅぅ…っと!
隠れているスプライト「てき」の向きが 90度のままだ!
![スック](https://scratchsiyou.com/wp-content/uploads/2023/12/sukku_futu-2-300x300.png)
うん、うん
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2023/12/ratch_kao_dounaru.png)
「○度に向ける」ブロックを 使って
![「○度に向ける」ブロック](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation35-2.png)
隠れているスプライト「てき」の 向きを 上・下・右・左のランダムに 変えよう
2,スタート時に 向きを ランダムに決める
![スック](https://scratchsiyou.com/wp-content/uploads/2023/12/sukku_futu-2-300x300.png)
お~、いいね!
![ラッチ先生](https://scratchsiyou.com/wp-content/uploads/2023/11/ratch_kao_dounaru-1.png)
さあ、次は、
ローカル変数「てきの速さ」を 使って
![変数ブロック](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation1-1.png)
![変数表示](https://scratchsiyou.com/wp-content/uploads/2023/12/scratchdrillocal06-explanation3-2.png)
てきの動く速さを ランダムに 決めましょう
コメント