zombiepaladin/scrolling-shooter — pull request #63 by Versaiteis (2012-10-01 04:40:15+00:00)
Title: Added handling of player death as best as I can for now

Change Log:

Last Update - *Added*
======================
PlayerShip:
--------------
Life counter to track # of player lives
Invincibility flag to indicate whether player has just spawned
Constant indicating the total time the player will be invincible (for easy changing)
A timer to keep track of the invincibility and to toggle the flag when its over
Added handling for the invincibility timer in the Update class
Added a State machine for the player to track it's current state, haven't done anything with it yet

This Update - *Added*
======================
PlayerShip:
------------
Refactoring:
-------------
1. I've moved the logic in Update() to the NormalUpdate() method and replaced it with a switch
2. Placed all of the Powerup related methods in a region so they can be hidden
3. Placed all of the Update methods in a region so they can be hidden
4. Placed all of the Draw methods in a region so they can be hidden
5. Moved GetPosition() up to the top next to the property "Position", we have two of these for some reason.
6. Moved code in the Draw() method into AliveDraw() and replaced it with a switch
7. Attempted a fix for the player shadow, which was being statically drawn at (20,100)
8. Pulled out some "new Vector2()" statements from the draw statements and made them local variables
9. Added a transition to the 'Killed' state in NormalUpdate()

Global Variables:
------------------
1. Removed the Invincible flag, watching the state is adequate enough
2. KilledDelay
The time to wait before respawning the player
3. killedTimer
Keeps track of the time spent in the Killed State
4. FlashInterval
The time between switching of drawing and not drawing the player
5. flashTimer
Keeps track of the flash interval
6. isDrawn
A flag to determine whether or not the player is being drawn, used for flashing while Invincible
7. MaxHealth
A constant indicating the maximum health the player can have

Public Fields:
---------------
1. public PlayerState GetState
returns the current state of the player

Methods:
---------
1. public void NormalUpdate(float elapsedTime)
Handles updating for 'Alive' and 'Invincible' states
2. public void KilledUpdate(float elapsedTime)
Handles updating for 'Killed' state
3. public void AliveDraw(float elapsedTime, SpriteBatch spriteBatch)
Handles drawing while the player is alive
4. public void InvincibleDraw(float elapsedTime, SpriteBatch spriteBatch)
Handles drawing while the player is invincible (typical flashing effect on the player ship)
5. private void Respawn()
Does all the work of actually respawning the player
6. public void DoDamage(float amount)
Damages the player by the amount passed in

ScrollingShooterGame:
----------------------
Refactoring:
-------------
1. In ProcessCollisions(): changed the line that invokes player damage to player.DoDamage(amount)
2. In ProcessCollisions(): Changed the check for player death to check state instead of health
3. In ProcessCollisions(): During Gameplay, checks for player state, if player is dead then goes to initializing (may change to scoring for a final score or splash when it is finished)
4. In ProcessCollisions(): Implemented invincibility (projectiles pass through)
5. In ProcessCollisions(): Removed death handling from collision and into Game update method and handles as a special case of game ending

Methods:
---------
1. public void StartGame()
Moved the player initialization and the loading level logic from LoadContent() and into this method which is called from the 'Splash' state of the game (commented out the changes for now)