Learning Scratch with a baby 13----Perfect the maze

In the last class, we drew a maze, and then the little mouse walked through the maze unimpeded. Of course, this is not what we want. So immediately modify the content so that the little mouse can't go through the maze, only the scary ghost can go through the maze.

First of all, we went back to the code of the little mouse and found the loop part that controls the little mouse. At this time, I will ask questions in due course.

'Is there any way to prevent the little mouse from going through the maze? '
'Bounce when hitting a maze'
'There is no such thing'
'Then I don't know'
'...'

Will I give up easily?

' Then you think about it, our maze is a 'character', how do we know if we have encountered a certain character? '
'Ah, check if you have touched the maze'
'That's right! '

What we have to do is when the mouse hits the maze, move a certain distance in the opposite direction of its current movement, so that the effect looks like the mouse is trapped in the maze and cannot pass through the wall.

throw out the blocks

insert image description here
What does the -5 step mean and why is it 5?

In order to understand the content here, I explained the principle in detail.
insert image description here
Then move on to the collision explanation.
insert image description here
Although the mouse in the left picture below did not touch the cheese, and the mouse in the right picture did not touch the vertical line, but the cheese and the vertical line entered the inside of the mouse's rectangular frame, so the program will think that the two characters collided. Therefore, in actual programming, pay attention to the impact of this situation on the operation of the game.

insert image description here
Then put the newly added module into the control module of the little mouse.

insert image description here
insert image description here
insert image description here
After the new module was added, the little mouse was basically unable to move, so the children just showed their skills again and redrawed the maze. The gap between the walls of the maze should be as reasonable as possible so that the little mouse will not be immobilized.
insert image description here
In other words, the gap is really suitable, but it is too big, right?

Now I can finally play games, haha, the kids are very proud.

How can I make you wish? Immediate question, if I move the initial position of the maze, such as this, what do you do?

The child thought for a while, and decisively added the code block.
insert image description here
'Well, it's okay, then let's start adding new enemies. '
'No, I'm going to draw a few more mazes. '
'I'll draw later'
'I've already started drawing, don't bother me. '
'...well, we'll add new enemies next class.

Guess you like

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