Step 12: Move Pikachu Code

Goal:


Now that all our game over and restart code is done, lets go ahead and create some controls for our game.

We are going to use tilt/motion controls to make pikachu move on the screen. By tilting the phone one way or the other we are going to make the image slide around on the screen and try avoid the pokeball.

Steps:

  1. From AccelerometerSensor, place an AccelerationChange block.
  2. From Pikachu, place a MoveTo block inside of the AccelerationChange block.
  3. From Math, attach a -(minus) block to the x slot of the MoveTo block.
  4. From Pikachu, place a Pikachu.X block in the left side of the -(minus) block.
  5. From the AccelerationChange block, hover over the orange xAccel circle, then grab the get xAccel block and place it in the right side of the -(minus) block.
  6. From Math, attach a +(plus) block to the y slot in the MoveTo block.
  7. From Pikachu, place a Pikachu.Y block into the left side of the +(plus) block.
  8. From the AccelerationChange block, hover over the orange yAccel circle, then grab the get yAccel block and place it in the right side of the +(plus) block.

Code: