Kit's Yarn Game (with kittens)

by Kit Krueger

09 Mar 2016

This game is a turtle version of the first scene in Lewis Carroll’s *Through the Looking-Glass*, which Alice spends sitting in an armchair trying to wind a ball of worsted while being distracted by two kittens. The blue turtle, Alice, moves in response to the user, while Kitty and Snowdrop (the black and white turtles, respectively) chase the yarn at random speeds. This gave me the opportunity to incorporate different types of code, as the autonomous movement requires different orders than the movement on command.
I finally managed to use the modules in a way that made logical and aesthetic sense, which pleases me greatly (the trick for me was coding with the organization in mind; anything that I wrote in the setup module never referred back to the game module, so there were no feedback errors). The classes were another exciting accomplishment, and they made a lot of sense for this program; for example, the two cat objects behave the same way but independently of each other, so I could write their behavior into the class and their specific actions into the game.
Probably the most difficult bit was working out the proper order for the in-game functions. They went through several incarnations, some redundant and some dysfunctional, before arriving in their current nested state. Transitioning between levels was, by my standards, complex, especially as it incorporated the level_two and level_up functions from the setup module.
My milestones stayed reasonably accurate; their specificity helped me keep the goals in mind, but I did end up changing some ideas as I figured out what was possible. The idea of multiple yarn balls depended on the resize function, which does not work in Trinket; having two cats instead of three does not change the game much. I ended up having two levels instead of counting a score within one. Apart from that, the whole project came out essentially as I imagined it.

Milestones:

  • Create background that resembles a sitting room, possibly using an imported image. The imported image was difficult to size and would have disrupted the game, so I just used some at the beginning and end.
  • Create Alice turtle (probably blue). She will be the active character.
  • Make Alice respond to keyboard arrows.
  • Create a class for the cat objects. They will be the same shape (turtles or possibly imported images) but different colors and, ideally, different sizes. Sizes are not changeable.
  • Name three cats. Dinah is large and black, Snowdrop is small and white, and Kitty is small and black. There are two (Kitty and Snowdrop).
  • Design an object to represent the ball of yarn. It will be a gray circle.
  • Make the cats move randomly.
  • Make yarn move when cats intersect with it, leaving string train (yarn.pendown).
  • Have the yarn spawn smaller gray circles and leave them behind. Size of turtle does not change, and the game worked without this.
  • Have a way for Alice to wind the yarn again, possibly using yarn.clear (individual clears for the spawned balls).
  • Have a counter for the number of yarn balls picked up. I incorporated levels instead.
  • Trigger winning sequence when counter reaches 10 (or whatever number seems to best fit the game). This happens when the second level has been beaten.
  • Design winning sequence in separate module.
  • Optional: Give user the option to restart the game. I did not get to this, but I’m all right with that.
Kit is an LS student who enjoys academic libraries as well as holding coats and snickering. Find Kit Krueger on Twitter, Github, and on the web.