]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/GameLogic.cs
Shouldn't be able to damage other characters now.
[chaz/carfire] / CarFire / CarFire / CarFire / GameLogic.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.Graphics;
8 using Microsoft.Xna.Framework.Input;
9
10 namespace CarFire
11 {
12 class GameLogic
13 {
14
15 Game mGame;
16 public GameLogic(Game game)
17 {
18 mGame = game;
19 }
20 /// <summary>
21 /// Update the game logic.
22 /// </summary>
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)
26 {
27 //TODO make a seperate one for battle
28 if (mGame.State.Map.Type == Map.Mode.Campaign || mGame.State.Map.Type == Map.Mode.Battle)
29 {
30 //Handle projectiles - update and check for wall collisions
31 for (int i = 0; i < mGame.State.mProjectiles.Count; i++)
32 {
33 bool removed = false;
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)))
36 {
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)
41 {
42 IMonster hitMonster = (IMonster)hitEntity;
43 hitMonster.causeDamageTo(mGame.State.mProjectiles[i].Damage);
44 if (hitMonster.Health > 0)
45 {
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);
48 }
49 else
50 {
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);
55 }
56 }
57 mGame.State.mProjectiles.RemoveAt(i);
58 removed = true;
59 i--;
60 }
61 if (!removed)
62 mGame.State.mProjectiles[i].Update(timespan);
63
64 }
65 //Check for collisons
66 /*
67
68 */
69 //Update input for each player
70 for (int i = 0; i < mGame.State.NumberOfPlayers; i++)
71 {
72 if (mGame.State.mCharacters[i] != null)
73 mGame.State.mCharacters[i].Update(timespan, mGame.State.GetKeysDown(i));
74 }
75 if (mGame.State.mCharacters[thisPlayer] != null)
76 {
77 mGame.State.Map.CenterCell = mGame.State.mCharacters[thisPlayer].Position;
78 }
79 //Handle wall collisions of projectiles again...
80 for (int i = 0; i < mGame.State.mProjectiles.Count; i++)
81 {
82 if (!mGame.State.Map.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y)))
83 {
84 mGame.State.mProjectiles.RemoveAt(i);
85 i--;
86 }
87
88 }
89 }
90 /*
91 else if (mGame.State.Map.Type == Map.Mode.Battle)
92 {
93 for (int j = 0; j < mGame.State.mCharacters.Length; j++)
94 {
95
96 if (mGame.State.mCharacters[j] != null)
97 for (int i = 0; i < mGame.State.mProjectiles.Count; i++)
98 {
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)
100 {
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);
104 i--;
105 }
106 }
107 }
108 }
109 */
110 }
111 }
112 }
This page took 0.032983 seconds and 4 git commands to generate.