We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Dragon Area

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.

Assignment

The given pos_x and pos_y for any unit is the center point of that unit!

Tips

  • The super() function allows you to call methods of a parent class.
  • To calculate the Dragon's hit box:
    • 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.