Step 3 – Encounter and Catch Functions

Encounter Function


  • This function sets up the encounter for us when we run into a Pokemon. The first thing it needs to do is store our current location so we don’t pop up out of place when the battle is done. Create the new variables “newX” and “newY” and set them to the Sprites blocks “mySprite x” and “mySprite y”.
  • Next, we create a sprite named “wild” of kind “Enemy”. To pick a random sprite form our array, we sue the “pokemon get value at” array block.
  • Fill that with a Math block “pick random 0 to (length of array pokemon – 1)”. We use the subtraction because, remember, the length of an array ≠ the position in the array. When there is 1 item in the array, the position of that item is 0.
  • The next half is a lot easier. Add a move block, but make sure the yv (y velocity) is set to 0. We don’t want to go up or down. Then add the Scene block “center camer at x 80 y 60”. That’s the exact center of the length of our screen.
  • Set mySprite position to x 64 y 95. Then set wild position to x 128 y 24. This offests them and adds some distance between for us to through our pokeballs.
  • Feel free to add some long text announcing that a Pokemon has appeared.


  • Catch or Run Function


  • This function will let us choose whether or not we want to catch this pokemon. Starting with creating a function called “catchOrRun” and filling it with a Logic “if true then” block asking us what we want to do.
  • If you press A (OK), it will cause our wild pokemon to glide across the screen, bouncing on the walls. If you press B (Cancel), it will change the sprites to dust as they run away and call reset so we can keep looking for pokemon.
  • Add it to the end of your “encounter” function.