From: Kyle Date: Mon, 26 Apr 2010 01:15:50 +0000 (+0000) Subject: Scoring implemented, melee attack implemented. X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=f67652c2fe85f9ba6c71dedbab26760775004e00;p=chaz%2Fcarfire Scoring implemented, melee attack implemented. git-svn-id: https://bd85.net/svn/cs3505_group@145 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- diff --git a/CarFire/CarFire/CarFire/Game.cs b/CarFire/CarFire/CarFire/Game.cs index f91882e..e42a827 100644 --- a/CarFire/CarFire/CarFire/Game.cs +++ b/CarFire/CarFire/CarFire/Game.cs @@ -15,6 +15,10 @@ namespace CarFire public class GameState { #region Public Properties + private const int hitMonsterScore = 20; + private const int killMonsterScore = 100; + public int HitMonsterScore { get { return hitMonsterScore; } } + public int KillMonsterScore { get { return killMonsterScore; } } public long FrameNumber { get { return mFrameNumber; } } @@ -27,7 +31,7 @@ namespace CarFire public List mProjectiles = new List(); public Player[] mCharacters; public Display mDisplay; - public AI AIData; + //public AI AIData; #endregion @@ -369,7 +373,7 @@ namespace CarFire State.Map.Tilemap = tilemap; State.Entities = State.Map.GetAllEntities(this); - State.AIData = new AI(this); + //State.AIData = new AI(this); /* mPlayers.Clear(); diff --git a/CarFire/CarFire/CarFire/GameLogic.cs b/CarFire/CarFire/CarFire/GameLogic.cs index 6f859d0..dce9fe3 100644 --- a/CarFire/CarFire/CarFire/GameLogic.cs +++ b/CarFire/CarFire/CarFire/GameLogic.cs @@ -11,20 +11,46 @@ namespace CarFire { class GameLogic { + Game mGame; public GameLogic(Game game) { mGame = game; } + /// + /// Update the game logic. + /// + /// timeslice + /// index of the player to center the screen around public void Update(TimeSpan timespan, int thisPlayer) { //Handle projectiles - update and check for wall collisions for (int i = 0; i < mGame.State.mProjectiles.Count; i++) { bool removed = false; - if (!mGame.State.Map.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y))) + //Check to see if there are any entities in the square with the projectile + if (!mGame.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y))) { - + //The projectile has hit something. + IEntity hitEntity = mGame.GetEntityAtCoordinates(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y)); + //If it is a monster than decrement monster health and increment the score of the player who shot it. + if (hitEntity is IMonster) + { + IMonster hitMonster = (IMonster)hitEntity; + hitMonster.causeDamageTo(mGame.State.mProjectiles[i].Damage); + if (hitMonster.Health > 0) + { + mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score += mGame.State.HitMonsterScore; + Console.WriteLine(mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score); + } + else + { + mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score += mGame.State.KillMonsterScore; + Console.WriteLine(mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score); + //Remove dead monsters + mGame.State.Entities.Remove(hitEntity); + } + } mGame.State.mProjectiles.RemoveAt(i); removed = true; i--; @@ -52,21 +78,8 @@ namespace CarFire //Update input for each player for (int i = 0; i < mGame.State.NumberOfPlayers; i++) { - //If player has not selected a player yet let them select one. - if (mGame.State.mCharacters[i] == null) - { - if (mGame.State.GetKeysDown(i).Contains(Keys.Enter)) - { - //mCharacters[i] = new Human(mGame, "", everything, projectile1, this, mGame.State.Map.GetStartingPositionForPlayer(i + 1)); - } - } - //Regular player input updates - else - { - + if(mGame.State.mCharacters[i] != null) mGame.State.mCharacters[i].UpdateInput(timespan, mGame.State.GetKeysDown(i)); - - } } if (mGame.State.mCharacters[thisPlayer] != null) { diff --git a/CarFire/CarFire/CarFire/Melee.cs b/CarFire/CarFire/CarFire/Melee.cs index f523012..38be303 100644 --- a/CarFire/CarFire/CarFire/Melee.cs +++ b/CarFire/CarFire/CarFire/Melee.cs @@ -59,33 +59,41 @@ namespace CarFire int startY = Coordinates.Y; if (Motion.Direction == Direction.Down || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.LowerRight) { - velocityY = 1; startY = Coordinates.Y + 1; } else if (Motion.Direction == Direction.Up || Motion.Direction == Direction.UpperLeft || Motion.Direction == Direction.UpperRight) { - velocityY = -1; startY = Coordinates.Y - 1; } if (Motion.Direction == Direction.Right || Motion.Direction == Direction.LowerRight || Motion.Direction == Direction.UpperRight) { - velocityX = 1; startX = Coordinates.X + 1; } else if (Motion.Direction == Direction.Left || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.UpperLeft) { - velocityX = -1; startX = Coordinates.X - 1; } //Attack a monster if (!Game.IsCellOpen(new Point(startX, startY))) { - foreach (IEntity entity in Game.State.Entities) + IEntity toKill = Game.GetEntityAtCoordinates(new Point(startX, startY)); + //See if it is a monster + if (toKill is IMonster) { - //See if it is a monster - - //Damage the monster - + IMonster hitMonster = (IMonster)toKill; + hitMonster.causeDamageTo(this.Damage); + if (hitMonster.Health > 0) + { + this.Score += Game.State.HitMonsterScore; + Console.WriteLine(this.Score); + } + else + { + this.Score += Game.State.KillMonsterScore; + Console.WriteLine(this.Score); + //Remove dead monsters + Game.State.Entities.Remove(toKill); + } } } } diff --git a/CarFire/CarFire/CarFire/Player.cs b/CarFire/CarFire/CarFire/Player.cs index da1af4e..02d6eec 100644 --- a/CarFire/CarFire/CarFire/Player.cs +++ b/CarFire/CarFire/CarFire/Player.cs @@ -28,7 +28,7 @@ namespace CarFire #region Public Properties public int Health { get { return playerHealth; } set{playerHealth = value;} } - public int Score { get { return score; } } + public int Score { get { return score; } set { score = value; } } public bool alive { get { return playerHealth > 0; } } public Game Game { get { return game; } } public MovementManager Motion { get { return mMotion; } } diff --git a/CarFire/CarFire/CarFire/Projectile.cs b/CarFire/CarFire/CarFire/Projectile.cs index 95d0d6e..611cc38 100644 --- a/CarFire/CarFire/CarFire/Projectile.cs +++ b/CarFire/CarFire/CarFire/Projectile.cs @@ -96,6 +96,7 @@ namespace CarFire public int PixelX { get { return pixelX; } set { pixelX = value; } } public int PixelY { get { return pixelY; } set { pixelY = value; } } public int Damage { get { return damage; } set { damage = value; } } + public int CharacterIndex { get { return mCharacterIndex; } } public Vector2 Position { get { return mMotion.Position; } } public Point Coordinates { get { return mMotion.Coordinates; } } } diff --git a/CarFire/CarFire/CarFire/SaberMonster.cs b/CarFire/CarFire/CarFire/SaberMonster.cs index ce59169..91d82a0 100644 --- a/CarFire/CarFire/CarFire/SaberMonster.cs +++ b/CarFire/CarFire/CarFire/SaberMonster.cs @@ -196,7 +196,9 @@ namespace CarFire /// public int Health { - get { throw new NotImplementedException(); } + //TODO do this right + get { return 0; } + //get { throw new NotImplementedException(); } } /// @@ -205,7 +207,8 @@ namespace CarFire /// public void causeDamageTo(int amount) { - throw new NotImplementedException(); + //TODO do this right + //throw new NotImplementedException(); } ///