Step 4 – Grass Patches and Throwing PokéBalls

Tilemap


  • Edit your tilemap to contain a patch of “grass”. This can be a cluster of any tiles that are different from the surrounding tiles.
  • Tile Overlaps


  • The Scene section has the block “on sprite of kind Player overlaps [tile] at location”. This block checks to see if our player is overlapping with a specific tile. In this case, it’s our “grass” tile we chose from the tilemap.
  • We then add the Logic “if true then” block to check that we are moving by asking if our velocity (speed & direction) is greater than 0 for x or y movement. The “or” is important because that means either can be true instead of both having to be true. If we don’t add this, it will constantly check until it is true, potentially creating some annoying combat if you’re trying to get out of the grass.
  • Our next “if true then” block (nested if) says we have a very low chance of finding a Pokemon. It’s low because MakeCode actually checks if this is true for every pixel. That’s 256 checks per tile!
  • Finally, we add our new tilemap. This should be another grass block, but should be totally uniform (all the same tile). And below that we call our “encounter” function to pick the sprite and get it moving.
  • Throwing A Pokeball


  • We can’t waste our Pokeballs without being in an encounter. So under our Controller block “on B button pressed”, we put a Logic “if true then” block filled with the Scene block “tile to center of mySprite” with the tile being what we chose in our tilemap in our last step.
  • Finally, add the Sprites block “set projectile to…” Use the pokeball Sprite in our presets and set the velocity to vx 0 and vy -50 (remember, negative y numbers go UP.