1 / 14

FlameBullet - Texture2D tex ; // Attributes - Rectangle rect ; - Vector2 pos , origin;

FlameBullet - Texture2D tex ; // Attributes - Rectangle rect ; - Vector2 pos , origin; - double rotation; - bool isAlive ; - Game1 mainGame ; - int age; - Color color ; - public void Update(); // Methods - public void Draw();. Player - Texture2D tex ; // Attributes

yamin
Download Presentation

FlameBullet - Texture2D tex ; // Attributes - Rectangle rect ; - Vector2 pos , origin;

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. FlameBullet - Texture2D tex; // Attributes - Rectangle rect; - Vector2 pos, origin; - double rotation; - boolisAlive; - Game1 mainGame; - int age; - Color color; - public void Update(); // Methods - public void Draw(); Player - Texture2D tex; // Attributes - Rectangle rect; - Vector2 pos, origin; - double rotation; - boolisAlive; - Game1 mainGame; - Vector2 bulletVel; - double xPart, yPart; - public void Update(); // Methods - public void Draw();

  2. Find all the common attributes and methods… FlameBullet - Texture2D tex; // Attributes - Rectangle rect; - Vector2 pos, origin; - double rotation; - boolisAlive; - Game1 mainGame; - int age; - Color color; - public void Update(); // Methods - public void Draw(); Player - Texture2D tex; // Attributes - Rectangle rect; - Vector2 pos, origin; - double rotation; - boolisAlive; - Game1 mainGame; - Vector2 bulletVel; - double xPart, yPart; - public void Update(); // Methods - public void Draw();

  3. GameObject - Texture2D tex; // Attributes - Rectangle rect; - Vector2 pos, origin; - double rotation; - boolisAlive; - Game1 mainGame; - public void Update(); // Methods - public void Draw(); FlameBullet : GameObject - Texture2D tex; // Attributes - Rectangle rect; - Vector2 pos, origin; - double rotation; - boolisAlive; - Game1 mainGame; - int age; - Color color; - public void Update(); // Methods - public void Draw(); Player : GameObject - Texture2D tex; // Attributes - Rectangle rect; - Vector2 pos, origin; - double rotation; - boolisAlive; - Game1 mainGame; - Vector2 bulletVel; - double xPart, yPart; - public void Update(); // Methods - public void Draw();

  4. GameObject - Texture2D tex; // Attributes - Rectangle rect; - Vector2 pos, origin; - double rotation; - boolisAlive; - Game1 mainGame; - public void Update(); // Methods - public void Draw(); FlameBullet : GameObject - Texture2D tex; // Attributes - Rectangle rect; - Vector2 pos, origin; - double rotation; - boolisAlive; - Game1 mainGame; - int age; - Color color; - public void Update(); // Methods - public void Draw(); Player : GameObject - Texture2D tex; // Attributes - Rectangle rect; - Vector2 pos, origin; - double rotation; - boolisAlive; - Game1 mainGame; - Vector2 bulletVel; - double xPart, yPart; - public void Update(); // Methods - public void Draw();

  5. GameObject - Texture2D tex; // Attributes - Rectangle rect; - Vector2 pos, origin; - double rotation; - boolisAlive; - Game1 mainGame; - public void Update(); // Methods - public void Draw(); FlameBullet : GameObject - int age; // Attributes - Color color; - public void Update(); // Methods - public void Draw(); Player : GameObject - Vector2 bulletVel; // Attributes - double xPart, yPart; - public void Update(); // Methods - public void Draw(); This class has 8 attributes! - inherited 6 - added 2 more This class has 9 attributes! - inherited 6 - added 3 more

  6. GameObject - Texture2D tex; // Attributes - Rectangle rect; - Vector2 pos, origin; - double rotation; - boolisAlive; - Game1 mainGame; - public void Update(); // Methods - public void Draw(); FlameBullet : GameObject - int age; // Attributes - Color color; - public void Update(); // Methods - public void Draw(); Player : GameObject - Vector2 bulletVel; // Attributes - double xPart, yPart; - public void Update(); // Methods - public void Draw();

  7. GameObject - Texture2D tex; // Attributes - Rectangle rect; - Vector2 pos, origin; - double rotation; - boolisAlive; - Game1 mainGame; - public void Update(); // Methods - public void Draw(); FlameBullet : GameObject - int age; // Attributes - Color color; Player : GameObject - Vector2 bulletVel; // Attributes - double xPart, yPart; This class has 8 attributes and 2 methods This class has 9 attributes and 2 methods

  8. GameObject - Texture2D tex; // Attributes - Rectangle rect; - Vector2 pos, origin; - double rotation; - boolisAlive; - Game1 mainGame; - public void Update(); // Methods - public void Draw(); FlameBullet : GameObject - int age; // Attributes - Color color; Player : GameObject - Vector2 bulletVel; // Attributes - double xPart, yPart; • What if we don’t like the methods we inherited? • Game objects usually update differently • Fancier draw?

  9. GameObject - Texture2D tex; // Attributes - Rectangle rect; - Vector2 pos, origin; - double rotation; - boolisAlive; - Game1 mainGame; - public void Update(); // Methods - public void Draw(); FlameBullet : GameObject - int age; // Attributes - Color color; - public void Update(); // New code - public void Draw(); Player : GameObject - Vector2 bulletVel; // Attributes - double xPart, yPart; - public void Update(); // New code - public void Draw(); • We override those methods: • “Redefine” those methods • New (specific) code

  10. Inheritance • “Absorbing” the properties from another class • Benefits • Good design (organization) • Smaller code • Maintainable code! • To “override” a method is to “redefine” it

  11. Access Modifiers in C# • public – “everyone” can see it (i.e. access it) • private – only the class that defined it can see it • protected – can be seen only by the class that defined it or any child classes • internal – we won’t talk about this…

  12. Why not? GameObject Man : GameObject - string name; // Attributes - … - public void Update(); // Overridden - public void Draw(); - public void Run(); // new Wolf : GameObject - intnumTeeth; // Attributes - … - public void Update(); // Overridden - public void Draw(); - public void Run(); // new WolfMan : Man, Wolf - public void Run(); // ????

  13. “Diamond of Death” GameObject Man : GameObject - string name; // Attributes - … - public void Update(); // Overridden - public void Draw(); - public void Run(); // new Wolf : GameObject - intnumTeeth; // Attributes - … - public void Update(); // Overridden - public void Draw(); - public void Run(); // new WolfMan : Man, Wolf - public void Run(); // ????

  14. Inheritance • You inherit from your grandparent too! Object GameObject Weapon Enemy Bow Bow Magic Orc Poodle Professor

More Related