Learning Scratch with a Baby Part 12 - Ghost Appears

Although the ghost can't wait to appear on the stage, the problem of the last class still needs to be solved first. First of all, when the cheese randomly appears, it will run to the outside of the screen.

Because we used building blocks,
insert image description here
since the coordinates of the cheese represent the center point of the cheese graphic, when moving to the edge, the cheese part will appear outside the screen.
insert image description here
The solution is actually very simple, we can use the following blocks instead of random position blocks.
insert image description here
insert image description here
Because it involves coordinates and random numbers, I explained it carefully to the children. The children already know the function of moving to the x and y coordinate blocks, and I explained the meaning of the random number again. Then drag the cheese to the left of the screen, let the children record the value of the x coordinate at this time, then drag the cheese to the far right of the screen, and record the value of the x coordinate again. In this way, such values ​​are obtained.

insert image description here

Put this building block into the program, replace the original building block, and then keep pressing the green flag to start the program. The children found that although the position of the cheese kept changing from left to right, they never saw only part of the cheese.

Now that the left and right blocks are completed, the next step is up and down. The children honestly drag the cheese to the bottom and the top position that does not exceed the score, record the y coordinate value, drag out the random number block, and complete this One step operation.

insert image description here
I kindly asked the children if they were all done. The children were triumphant, and all the answers were completed. As a result, after running the game, after not playing for a long time, the cheese fell mercilessly off the screen again.

insert image description here

The child looked puzzled, so I had to remind patiently. 'Look at the blocks inside the loop. '

After carefully reading the building blocks in the cycle, I finally found that there is still a fish that slipped through the net. After the children dragged and replaced the building blocks with great difficulty, they finally solved the problem of cheese out of bounds.

insert image description here

In fact, it is the mouse and keyboard that limit children's play!

After playing the modified game for a while, I immediately entered the solution to the second problem, the problem of the little mouse running diagonally. In fact, this problem is easier to modify than explain.

Very carefully explained the reason why the little mouse runs diagonally, because in our judgment statement, it is only to judge whether a certain button of the direction key is pressed, for example, if the left button is pressed, the little mouse will face Walk a short distance to the left, and if you press the down button while pressing the left button, the mouse will go down a distance again after already going left. No matter how many buttons are pressed at the same time, the little mouse will execute these actions sequentially, and after these actions are completed quickly, it seems to us that the little mouse is walking various slashes.

How to solve it?

It's very simple, use another judgment block to ensure that only one button is pressed at a time, and the buttons have priority levels, left and right, right and up, up and down.
'Why such a priority? '
'Because that's what we chose when we wrote it. '
'...'

Find the judgment block if-then-else, modify the program:

insert image description here

This solves the mouse running problem. Because if the left button is pressed, the program will not handle other button presses. The other keys can be deduced in the same way.

I don't know if the kids understand? But don't worry, there are still many places to use this module later. And, it's still a lot of fun.

Then finally came the main event.
'I know, drawing a maze. '
'Well, no, haha'
'...'

Appearance of ghosts! ! !

insert image description here
In order to test the children's mastery, I described the work content of the ghost:
the ghost should appear in a specific position, and then move towards the little mouse continuously. If it touches the little mouse, the game will be over.
Under my prompting, the children found the building blocks and built such building blocks:

insert image description here
Not surprisingly, I let the children run the game and immediately discovered the problem. The ghost was frozen in a certain direction in an extremely strange way. And there is no intention of moving at all.
insert image description here
why? The children thought for a while, and it was because the cycle was useless. He decisively joined the loop, but what happened to the ghost's weird sense of direction? The kid was a little confused. I guess I forgot. I have no choice but to remind that there is one flip setting block missing.
'Oh, I remembered. '
'I told you so. '

Then I completed the construction of the ghost building blocks, and added a shape-changing building block by the way.
insert image description here
insert image description here
insert image description here
Next, I added a piece of code for the ghost to disappear. The children were too frightened to be scared, and they were too scared if they didn’t disappear. This kind of situation was too stressful, so this code only appeared in my game, and the children gave up decisively. .
insert image description here
The last step before drawing the maze, add music. We put the music in the background, not in any of the character's code areas. Because it belongs to the scene.
insert image description here
Finally started drawing the maze. Similarly, create a new character, and then use the straight line tool to draw a maze.

The children drew carefully for a long time, and the maze was finally released. The size of the little mouse was not considered at all. Although the little mouse can go through the maze now, soon, the little mouse's body will no longer be able to use this superpower. It is destined that the child will have to redraw a simpler maze, but forget it now, let him play freely.
S

Guess you like

Origin blog.csdn.net/jackwsd/article/details/113817038