topical media & game development
game-xna-intro-XnaShooterUIProject-Game-Player.cs / cs
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using XnaGraphicEngine.GameScreens;
using Microsoft.Xna.Framework;
using XnaGraphicEngine.Helpers;
using Microsoft.Xna.Framework.Input;
using XnaGraphicEngine.Properties;
using XnaGraphicEngine.Graphics;
#endregion
namespace XnaGraphicEngine.Game
{
<summary>
Player helper class, holds all the current game properties:
Health, Weapon and
Score.
Note: This is a static class and holds always all player entries
for the current game. If we would have more than 1 player (e.g.
in multiplayer mode) this should not be a static class!
</summary>
static class Player
{
#region Variables
<summary>
Current game time in ms. Used for time display in game. Also used to
update the level position.
</summary>
public static float
gameTimeMs = 0;
<summary>
Won or lost?
</summary>
public static bool victory = false;
<summary>
Game over?
</summary>
private static bool
gameOver = false;
<summary>
Is game over?
</summary>
<returns>Bool
</returns>
public static bool GameOver
{
get
{
return
gameOver;
} // get
} // GameOver
<summary>
Remember if we already uploaded our highscore for this game.
Don't do this twice (e.g. when pressing esc).
</summary>
static bool alreadyUploadedHighscore = false;
<summary>
Set game over and upload highscore
</summary>
public static void SetGameOverAndUploadHighscore()
{
// Set lifes to 0 and set
gameOver to true to mark this game as ended.
gameOver = true;
// Upload highscore
if (alreadyUploadedHighscore == false)
{
alreadyUploadedHighscore = true;
Highscores.SubmitHighscore(score, Highscores.DefaultLevelName);
} // if (alreadyUploadedHighscore)
} // SetGameOverAndUploadHighscore()
#endregion
#region Current player values (health, weapon, etc.)
<summary>
Health, 1 means we have 100% health, everything below means we
are damaged. If we reach 0, we die!
</summary>
public static float health = 1.0f;
<summary>
Weapon types we can carry with our ship
</summary>
public enum WeaponTypes
{
MG,
Plasma,
Gattling,
Rockets,
} // enum WeaponTypes
<summary>
Weapon we currently have, each weapon is replaced by the
last collected one. No ammunition is used.
</summary>
public static WeaponTypes currentWeapon = WeaponTypes.MG;
<summary>
Do we have the EMP bomb? Press space to fire them.
</summary>
public static int empBombs = 0;
<summary>
Current score. Used as highscore if game is over.
</summary>
public static int score = 0;
#endregion
#region Reset everything for starting a new game
<summary>
Keys for moving around. Assigned from settings!
</summary>
static Keys moveLeftKey,
moveRightKey,
moveUpKey,
moveDownKey;
<summary>
Default to normal mouse sensibility, can be changed
from 0.5 to 2.0.
</summary>
static float mouseSensibility = 1.0f;
<summary>
Reset all player entries for restarting a game.
</summary>
public static void Reset()
{
gameOver = false;
alreadyUploadedHighscore = false;
gameTimeMs = 0;
health = 1.0f;
score = 0;
// Assign keys. Warning: This is VERY slow, never use it
// inside any render loop (getting Settings, etc.)!
moveLeftKey = GameSettings.Default.MoveLeftKey;
moveRightKey = GameSettings.Default.MoveRightKey;
moveUpKey = GameSettings.Default.MoveForwardKey;
moveDownKey = GameSettings.Default.MoveBackwardKey;
// Also assign mouse sensibility
mouseSensibility = 2.5f -
2.0f * GameSettings.Default.ControllerSensibility;
if (mouseSensibility < 0.5f)
mouseSensibility = 0.5f;
} // Reset(setLevelName)
#endregion
#region Handle game logic
<summary>
Handle game logic
</summary>
public static void HandleGameLogic(Mission mission)
{
//TODO
} // HandleGameLogic(asteroidManager)
#endregion
} // class Player
} // namespace XnaGraphicEngine
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2780434-1";
urchinTracker();
</script>