Scratch Programming: avoid shark (V)

"  Content on all the lessons mastered yet? Over and over with no programming best way to learn is to practice, practice, practice. I must remember that more hands, more brains ohhh "

 

01

game introduction

 

This is a simple game , use the mouse to control the realization of a small starfish swimming in the water, while the need to avoid shark; if you encounter a shark, that is the end of the game.

 

02

Design ideas

 

  • This game is mainly composed of an underwater background and a small starfish, four shark composition;
  • Starfish follow the mouse;
  • If starfish and sharks collide, that is the end of the game.

 

03

Implementation process

 

The first step: Shark role to achieve

From "Animal" category under Library System Role Select "Shark 2", to determine the import role.

 

Shark character design for the script to achieve production of animation and swimming in the water. Complete code is shown below:

Follow Me Scratch Programming: avoid shark (V)

The completion of the code after design, three identical copy of sharks role, then the code will also be copied.

 

Step two: Starfish role to achieve

The role of the library system selected from the "animal" under the category "Starfish", OK to import the roles.

 

Starfish script for the character design to achieve production of animation and let the sea yesterday following the mouse.

 

Here mainly through "mouse X of" detection "module coordinate " and "Y mouse coordinates to obtain the position of the mouse" two instruction blocks, and then through the "X-coordinate is moved to the Y-coordinate" of "moving" module starfish achieved instruction block following the mouse.

 

FIG complete code as follows:

Follow Me Scratch Programming: avoid shark (V)

 

Follow Me Scratch Programming: avoid shark (V)

The method of setting icon set "hit color" instruction color parameter

 

Step 3: Add background

 

The role of the library from the system, select the "outdoor" in the "Underwater1" background; OK to import the background.

 

Step Four: run the program, to the following figure

Follow Me Scratch Programming: avoid shark (V)

 

Step Five: Save the file.

 

Under the File menu "Save to computer" you can save good works.

 

04

to sum up

 

We should grasp this lesson:

  • Learning function to obtain the coordinates of the mouse, and use the return value of a control character;
  • Learning to use conditional instructions;
  • Learn to use "hit color" event ;

 

 

05

Outward Bound

 

You can control the starfish can only be moved in the vertical direction or the horizontal direction it?

Guess you like

Origin www.cnblogs.com/scratch3/p/11423493.html