Step 6: Coding Pikachu Health Check

Goal:


Now that our sprite and our screen looks good, lets go ahead and code what the can do.

Let’s start with what needs to happen Pikachu is collided with by the pokeball, setting his health, and what happens when his health reaches zero.

Steps:

  1. In the top right corner of the screen, find the button called Blocks, and click it.
  2. From Variables, place an initialize global block on the screen and call it health.
  3. From Math, attach a 0(zero) block to the end of the initialize global block and set it to 100.
  4. From Pikachu, place a CollidedWith block on the screen.
  5. From Control, place an IF/THEN block.
  6. From Math, attach an =(equal) block to the IF portion of the IF/THEN block and then change it to <(Less Than).
  7. From Variables, place a get block in the left side of the <(Less Than) block and set it to health.
  8. From Math, place a 0(zero) block in the right side of the <(Less Than) block.

Code: