| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- //---------------------------------------------------------------------------------
- // Ported to the Atomic Game Engine
- // Originally written for XNA by Michael Hoffman
- // Find the full tutorial at: http://gamedev.tutsplus.com/series/vector-shooter-xna/
- //----------------------------------------------------------------------------------
- using AtomicEngine;
- using System.IO;
- namespace AtomicBlaster
- {
- static class PlayerStatus
- {
- // amount of time it takes, in seconds, for a multiplier to expire.
- private const float multiplierExpiryTime = 0.8f;
- private const int maxMultiplier = 20;
- public static int Lives { get; private set; }
- public static int Score { get; private set; }
- public static int Multiplier { get; private set; }
- public static bool IsGameOver { get { return Lives == 0; } }
- private static float multiplierTimeLeft; // time until the current multiplier expires
- private static int scoreForExtraLife; // score required to gain an extra life
- // Static constructor
- static PlayerStatus()
- {
- Reset();
- }
- public static void Reset()
- {
- Score = 0;
- Multiplier = 1;
- Lives = 4;
- scoreForExtraLife = 2000;
- multiplierTimeLeft = 0;
- }
- public static void Update()
- {
- if (Multiplier > 1)
- {
- // update the multiplier timer
- if ((multiplierTimeLeft -= (float)GameRoot.ElapsedTime) <= 0)
- {
- multiplierTimeLeft = multiplierExpiryTime;
- ResetMultiplier();
- }
- }
- }
- public static void AddPoints(int basePoints)
- {
- if (PlayerShip.Instance.IsDead)
- return;
- Score += basePoints * Multiplier;
- while (Score >= scoreForExtraLife)
- {
- scoreForExtraLife += 2000;
- Lives++;
- }
- }
- public static void IncreaseMultiplier()
- {
- if (PlayerShip.Instance.IsDead)
- return;
- multiplierTimeLeft = multiplierExpiryTime;
- if (Multiplier < maxMultiplier)
- Multiplier++;
- }
- public static void ResetMultiplier()
- {
- Multiplier = 1;
- }
- public static void RemoveLife()
- {
- Lives--;
- }
- }
- }
|