using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; /* * For any questions or help, contact me: * Zepharis Lubrano, 3861368 * zepharislubrano@hotmail.com */ class Player : SpriteGameObject //The cursor can be seen as a Sprite GameObject. { SoundEffect Gun; //Gunshot sound from http://www.freesound.org/people/wildweasel/sounds/39018/ int shotCount; bool doUpdate; bool playerShot; public Player(GameWorld gameWorld, string assetname, int layer = 0, string id = "") : base(gameWorld, assetname, layer, id) { visible = true; Gun = gameWorld.ResourceManager.getSound("Sounds/Gunshot"); Reset(); } public override void Reset() { shotCount = 0; } public override void HandleInput(InputHelper inputHelper, GameWorld gameWorld) { if (doUpdate) { position = inputHelper.MousePosition - Center; //Position of the sprite changes depending on the mouse position. Duck duck = gameWorld.Find("Duck") as Duck; if (duck.Shooting) if (inputHelper.MouseLeftButtonPressed()) //Gunshot will play whenever the left button is pressed. { playerShot = true; Gun.Play(); shotCount++; //integer that counts how many times have already been shot. } else playerShot = false; } } public int ShotCount //Property to know how many times the player has shot already. { get { return shotCount; } set { if (value > -1) shotCount = value; } } public bool DoUpdate { get { return doUpdate; } set { doUpdate = value; } } public SoundEffect GUN { get { return Gun; } set { Gun = value; } } public bool PlayerShot { get { return playerShot; } set { playerShot = value; } } }