vrijdag 18 januari 2013

Homework: Inheritance

Like we discussed in the les, the homework is to make the following inheritance structure:


The Game1 contains 2 objects:

  • Player (which is derived from Sprite)
  • Enemy (which is derived from Sprite)


Sprite has a method called 'Update()' this method moves the sprite to the right.


Player also has a method called 'Update()' When this function is called let the player move-up, but also keep the original functionality from the sprite:Update() intact.

The same goes for the Enemy but the enemy should move-down.


In all the update() methods don't let the image move out of the screen, create code that when this occurs the image is teleported back to the other side of the screen (Like we did in the les)

The result should do the following:
Also write your code readable, use const for the right vars, or den your methodes etc.


Some additional challanges:
  1. Add GameTime as a parameter to the Update()-method ( 'Update(GameTime gameTime)' ) and use gameTime to let the images move at the same speed regardless if the the game has a frame drop.
  2. Create an additional class named 'Boss' this class derives from 'Enemy'. The 'boss' moves more quickly as the Enemy.
  3. Save all objects in Game1 as Sprite - objects and see if this still works. Also experiment with this.
  4. Give the player a new variable named: HitPoints. If the player hits a Enemy/Boss: subtract 1 hitpoint and make the player immune for upcomming damage for 2 seconds. If hitpoints is <0 delete the player object.


Geen opmerkingen:

Een reactie posten