2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.Graphics;
8 using Microsoft.Xna.Framework.Input;
16 public GameLogic(Game game)
21 /// Update the game logic.
23 /// <param name="timespan">timeslice</param>
24 /// <param name="thisPlayer">index of the player to center the screen around</param>
25 public void Update(TimeSpan timespan, int thisPlayer)
27 //TODO make a seperate one for battle
28 if (mGame.State.Map.Type == Map.Mode.Campaign || mGame.State.Map.Type == Map.Mode.Battle)
30 //Handle projectiles - update and check for wall collisions
31 for (int i = 0; i < mGame.State.mProjectiles.Count; i++)
34 //Check to see if there are any entities in the square with the projectile
35 if (!mGame.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y)))
37 //The projectile has hit something.
38 IEntity hitEntity = mGame.GetEntityAtCoordinates(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y));
39 //If it is a monster than decrement monster health and increment the score of the player who shot it.
40 if (hitEntity is IMonster)
42 IMonster hitMonster = (IMonster)hitEntity;
43 hitMonster.causeDamageTo(mGame.State.mProjectiles[i].Damage);
44 if (hitMonster.Health > 0)
46 mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score += mGame.State.HitMonsterScore;
47 Console.WriteLine(mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score);
51 mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score += mGame.State.KillMonsterScore;
52 Console.WriteLine(mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score);
53 //Remove dead monsters
54 mGame.State.Entities.Remove(hitEntity);
57 mGame.State.mProjectiles.RemoveAt(i);
62 mGame.State.mProjectiles[i].Update(timespan);
69 //Update input for each player
70 for (int i = 0; i < mGame.State.NumberOfPlayers; i++)
72 if (mGame.State.mCharacters[i] != null)
73 mGame.State.mCharacters[i].Update(timespan, mGame.State.GetKeysDown(i));
75 if (mGame.State.mCharacters[thisPlayer] != null)
77 mGame.State.Map.CenterCell = mGame.State.mCharacters[thisPlayer].Position;
79 //Handle wall collisions of projectiles again...
80 for (int i = 0; i < mGame.State.mProjectiles.Count; i++)
82 if (!mGame.State.Map.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y)))
84 mGame.State.mProjectiles.RemoveAt(i);
91 else if (mGame.State.Map.Type == Map.Mode.Battle)
93 for (int j = 0; j < mGame.State.mCharacters.Length; j++)
96 if (mGame.State.mCharacters[j] != null)
97 for (int i = 0; i < mGame.State.mProjectiles.Count; i++)
99 if (mGame.State.mProjectiles[i].Coordinates.X == mGame.State.mCharacters[j].Coordinates.X && mGame.State.mProjectiles[i].Coordinates.Y == mGame.State.mCharacters[j].Coordinates.Y)
101 mGame.State.mCharacters[j].causeDamageTo(mGame.State.mProjectiles[i].Damage);
102 Console.WriteLine(mGame.State.mCharacters[j].Health);
103 mGame.State.mProjectiles.RemoveAt(i);