A4 - Extending the Sprite Class
Run update.bat to retrieve the template for this assignment.
When you look through the file a4.py, you'll notice we now have three classes:
Level_1(an extension ofoa.View)Player(an extension ofoa.Sprite)Bee(an extension ofoa.Sprite)
A class is a template for an object, sort of like what a cookie cutter is for a gingerbread cookie.
The class defines all functionality that its objects will have.
In our case, it defines what each object type will do when its first created (on_create) and on every animation frame (on_step).
Note, that the keyword self refers to the level within the Level_1 class, the player within the Player class, and so on.
We use it often with a class to refer to our own attributes and methods.
Read through the code, and try to understand what each line is doing. We'll go through it together in class as well.
Your Task
-
Create another bee in a location of your choice (this requires you to add just one line of code)
-
Create another class for an enemy type of your choice. You can model it off of the
Beeclass (start by just copying the bee, then modifying as needed). Try to make it behave differently than the bee. For instance, maybe it moves at a different speed, and/or moves vertically rather than horizontally. Maybe it switches direction when it gets within 100 pixels of the screen edge rather than touching the screen edge. Feel free to get creative! -
In the
Level_1class, create at least two instances of your new enemy.