

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 7
click for more info
Not enough gems
Cost: 6 gems
1: Polymorphism
incomplete
2: Get Edges
incomplete
3: Overlap
incomplete
4: Dragon Area
incomplete
5: Polymorphism Review
incomplete
6: Operator Overloading
incomplete
7: Operator Overload Review
incomplete
8: Overriding Built-in Methods
incomplete
9: Polymorphism Practice
incomplete
10: Polymorphism Practice
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Our Unit class has its simple version of in_area - it just checks if the center point of the unit is within the given area. But the Dragon is a big creature, and it doesn't make sense to check if a single point is within the area. So, we'll use a hit box instead!
This is the current behavior:
We want to change it so that a dragon is within an area if its hit box overlaps with it:
Since Dragon is a child class of Unit, it can override the in_area of the Unit class with its own behavior. Yay polymorphism! The Dragon still acts like a Unit (has an in_area method), but it has its own implementation.
The given pos_x and pos_y for any unit is the center point of that unit!
super() function allows you to call methods of a parent class.x1 should be the dragon's pos_x (center x) minus half of the dragon's width.y1 should be the dragon's pos_y (center y) minus half of the dragon's height.x2 should be the dragon's pos_x (center x) plus half of the dragon's width.y2 should be the dragon's pos_y (center y) plus half of the dragon's height.