PencilCoder

Chase Other Sprites!

Goals:

  • Use sprites as arguments in functions such as jumpto or turnto.

Coding Snippets:

  • coding snippets
  • The turnto, moveto, and jumpto functions can accept sprites as arguments.
  • When passing a sprite to jumpto or moveto, use a second argument to specify a maximum distance to move.
  • Turn off an unwanted warning by setting the built-in nowarn variable to true.

Math and Computer Concepts:

  • The statement b.jumpto r is similar to b.jumpto r.getxy(), but there is an important difference:  the latter must be preceded by a call to await done defer(). That isn't necessary with b.jumpto r because the definitions for jumpto, moveto, and turnto include code which takes care of the animation queue issues for us when these functions are called with sprites as arguments.
  • Pencil Code is set up to issue a warning when running programs that could potentially have animation queue problems. This is not a bug, but a failsafe designed to encourage good coding behavior.
  • Computer software is often configurable, meaning it has default settings which can be changed to make it behave in a way more to our liking. The coding snippet illustrates modifying a default Pencil Code warning feature by updating the nowarn setting.

Activities:

Save each of the following in a folder called ChaseSprites.

Copyright © PencilCoder.net