]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/GameLogic.cs
Seperated GameLogic from the Display
[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 Game mGame;
15 public GameLogic(Game game)
16 {
17 mGame = game;
18 }
19 public void Update(TimeSpan timespan, int thisPlayer)
20 {
21 //Handle projectiles - update and check for wall collisions
22 for (int i = 0; i < mGame.State.mProjectiles.Count; i++)
23 {
24 bool removed = false;
25 if (!mGame.State.Map.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y)))
26 {
27
28 mGame.State.mProjectiles.RemoveAt(i);
29 removed = true;
30 i--;
31 }
32 if (!removed)
33 mGame.State.mProjectiles[i].Update(timespan);
34
35 }
36 //Check for collisons
37 for (int j = 0; j < mGame.State.mCharacters.Length; j++)
38 {
39
40 if (mGame.State.mCharacters[j] != null)
41 for (int i = 0; i < mGame.State.mProjectiles.Count; i++)
42 {
43 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)
44 {
45 mGame.State.mCharacters[j].causeDamageTo(mGame.State.mProjectiles[i].Damage);
46 Console.WriteLine(mGame.State.mCharacters[j].Health);
47 mGame.State.mProjectiles.RemoveAt(i);
48 i--;
49 }
50 }
51 }
52 //Update input for each player
53 for (int i = 0; i < mGame.State.NumberOfPlayers; i++)
54 {
55 //If player has not selected a player yet let them select one.
56 if (mGame.State.mCharacters[i] == null)
57 {
58 if (mGame.State.GetKeysDown(i).Contains(Keys.Enter))
59 {
60 //mCharacters[i] = new Human(mGame, "", everything, projectile1, this, mGame.State.Map.GetStartingPositionForPlayer(i + 1));
61 }
62 }
63 //Regular player input updates
64 else
65 {
66
67 mGame.State.mCharacters[i].UpdateInput(timespan, mGame.State.GetKeysDown(i));
68
69 }
70 }
71 if (mGame.State.mCharacters[thisPlayer] != null)
72 {
73 mGame.State.Map.CenterCell = mGame.State.mCharacters[thisPlayer].Position;
74 }
75 //Handle wall collisions of projectiles again...
76 for (int i = 0; i < mGame.State.mProjectiles.Count; i++)
77 {
78 if (!mGame.State.Map.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y)))
79 {
80 mGame.State.mProjectiles.RemoveAt(i);
81 i--;
82 }
83
84 }
85 }
86 }
87 }
This page took 0.038142 seconds and 4 git commands to generate.