First, the introduction of Ladybugs
1: Add Control:
First introduce the controls contained in the box, there are two canvases, an image sprite, a gravity sensor, a clock (set to 10Ms). Renamed. Set the image sprite's move speed to 10 and introduce a ladybug image
2. Adding logic
The programming idea is to add a function (clock) that is always called, that is, the code that is running in the program. It is called only once to 10ms.
So we're supposed to be introducing a function that constantly plots ladybugs.
First, set the global variable of a health value. Global Energy
Then write a program for Updateladybug, which is used to continually draw the ladybug. The logic is: over time, energy is continuously reduced by 1, and the displayenergy is used for the mapping of health values. The plot of health means: first draw the background color to white, and then the value of global energy as the pixel value to draw the red blood bar.
Then, if the health value is 0, then, enter the Gameover state, in this state, so that the various enable ladaybug all turn off and replace the picture for the dead picture, turn off the gravitational induction.
When the health value is not 0, set the direction of the ladybug to move in the direction of gravity induction, set the speed is positive correlation of tilt degree.
Second, the introduction of aphids
1. Component Join
Add a picture sprite again,
2. Adding logic
Added logic function to update aphids
Using a random function, here, the possibility of setting up a%20 makes the aphid shift the direction of movement (which is said to be reasonable), and then a function that is resurrected after the preset of a dead, that is, the possibility of%80*%5 is raised when a random number is dialed, and it has no effect when alive.
How to complete the function of eating aphids is to use the collision detection function, write a new function for Eataphid, if eaten, the energy plus 50, and then set the aphid attribute to False, then set the next occurrence of the location.
Use the encapsulated function for design.
If a collision with the aphid is detected and the aphids are visible, the aphid function is called to eat.
Third, the introduction of frogs
1. Adding components
Add a picture Wizard
2. Adding logic
Add a function to refresh the Frog action
There is a 10% possibility to move the direction of the change (ie, about 100ms change once)
Add collision Detection (frogs and ladybugs), and this way, complete the game's overall frame of construction.
Iv. accession to the re-initiation
1. Component Join
2. Logic Join
is to perform all the restores.
Five, add the score board
2. Adding logic
Add logic to add 0.1 if alive, and change the value on the label.
Restore in the restart, and you can finish the production at the end.
Appinventor Study Notes (v)--Ladybug Run application Learning