Labyrinth game programming scratchThe following are some basic points for programming maze games with Scratch:
** 1. Initial preparations **
1. ** Create an account **: Create an account in Scratch. You can use QQ email.
2. ** Material preparation **
- [Labyrinth Map: You can draw it yourself, take a photo, and upload it, or search it online.]
- ** Character related **
- ** Main Character **: You can upload a picture of your child or use the materials provided by the website.
- [Treasure (Target): Able to upload pictures of your child's favorite toys and food. You can also use website materials.]
** 2. Game design and programming logic **
1. ** Stage coordinate system understanding **
- The stage area was a two-dimensional coordinate system with the center (0, 0) as the origin, x as the abyssal coordinate, and y as the ordinate. An increase of 1 in the x coordinate meant a shift of 1 to the right (→), an increase of-1 in the x coordinate (i.e., x - 1) meant a shift of 1 to the left (→), an increase of 1 in the y coordinate meant a shift of 1 to the top (→), and an increase of-1 in the y coordinate meant a shift of 1 to the bottom (→).
2. ** Game Screen Construction **
- ** Setting of background **: upload a map character as the background of the game. When the game starts, place it at the bottom to prevent it from blocking other characters.
- ** Character Creation **
- ** Main character **: Move the mouse to the "Cat Head" at the bottom right corner of the page, upload or select the main character from the material library, and adjust the size and initial position.
- ** Treasure Character **: You can upload it yourself or choose it from the material library, then manually drag it to the corresponding position in the maze from the stage area.
3. ** Code logic construction **
- ** Coordinates variable setting **: You need to set two variables to store the x-axis and y-axis coordinates of the main character. When the game starts, set these two variables as the x-axis and y-axis coordinates of the stage area.
- ** Direction Control **
- ** Overall logic **: Since the game is continuous, it is necessary to add a control code for "repeated execution".
- ** Direction key operation **: Take pressing the right (→) direction key as an example. The logic is "If you press the → key, the x coordinate will increase by a certain value (the value can be controlled by yourself)". You can also add sound effects (such as "Boing" and other sounds). Choose "Wait until the end of the broadcast" to avoid noise. The operation logic of the other direction keys (→, →, →) was similar, except that the left and right direction corresponded to the addition and reduction of the x coordinate, and the up and down direction corresponded to the addition and reduction of the y coordinate.
- ** Bumping into a wall **: When you hit a wall, you can use the coordinate variable you set before to return to the previous step. You can also add sound to increase the interaction.
For example, in the maze game of cat and mouse, the function analysis was as follows:
1. [** Backgrounds **: You can let the baby draw the background himself.]
2. ** Character **: Choose the cat and mouse and adjust their sizes. In terms of code writing for the cat, the cat would run to the starting point by clicking the green flag. Then, it would click the buttons on the keyboard, and the cat would move up, down, left, and right. If it encountered a black color (representing obstacles such as walls) during the movement, it would not work. Finally, when it caught a mouse, it would meow and stop the program.
In some other maze game programming, such as getting the key in the maze, opening the lock, getting the gemstone and reaching the exit of the door, etc., similar programming logic such as character control, direction operation, obstacle judgment, etc., and may involve the transmission of information (need to carefully study its logic). There may be some bugs in the code (such as passing through certain directions during color judgment related operations, etc.), which need to be continuously debugged and improved.