]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/Human.cs
removed more outdated code.
[chaz/carfire] / CarFire / CarFire / CarFire / Human.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 public class Human : IPlayer
13 {
14 //The number of frames between each projectile is spawned.
15 const int shootCoolDown = 10;
16 String CharName;
17 Game game;
18 Texture2D charModel;
19 Texture2D projectileModel;
20 int health;
21 int damage;
22 int range;
23 int score;
24
25 MovementManager mMotion;
26
27 bool visible;
28 Display theDisplay;
29
30 //Used to draw projectiles
31 int projectileSpeed;
32 int projectileCoolDown;
33
34
35 public Human(Game theGame, String Name, Texture2D model, Texture2D projectile, Display mDisplay, Point position)
36 {
37 game = theGame;
38 CharName = Name;
39 theDisplay = mDisplay;
40 health = 100;
41 score = 0;
42 visible = false;
43 charModel = model;
44 projectileModel = projectile;
45 projectileSpeed = 30;
46
47 // Speed is the number of grid cells you can move through per second.
48 mMotion = new MovementManager(position, 8.0f);
49 }
50
51 public void LoadContent(ContentManager contentManager)
52 {
53 charModel = contentManager.Load<Texture2D>("deselectBox"); //change to charModel when designed
54 projectileModel = contentManager.Load<Texture2D>("emptySelectBox"); //change to a projectile model later
55
56 }
57
58
59 public void Update(TimeSpan timeSpan)
60 {
61 }
62 /// <summary>
63 /// This method will draw a character to the screen.
64 /// </summary>
65 /// <param name="spriteBatch"></param>
66 public void Draw(SpriteBatch spriteBatch)
67 {
68 Rectangle position = game.State.Map.GetRectangleFromCoordinates(mMotion.Position);
69 spriteBatch.Draw(charModel, position, Color.White);
70 }
71
72 public int Health { get { return health; } }
73 public int Score { get { return score; } }
74 public bool alive { get { return health > 0; } }
75
76 public Vector2 Position { get { return mMotion.Position; } }
77 public Point Coordinates { get { return mMotion.Coordinates; } }
78
79 public void causeDamageTo(int amount)
80 {
81 health -= amount;
82 }
83
84 /// <summary>
85 /// Moves the current player being controlled based on a given set of key presses.
86 /// The player can only move one grid space per movePlayer call. Thus this method
87 /// is made to be called ever update. The player will only move if the grid space
88 /// that is being moved to is an open space.
89 /// </summary>
90 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
91 public void MovePlayer(TimeSpan timeSpan, List<Keys> keysPressed)
92 {
93 bool moveLeft = keysPressed.Contains(Keys.Left);
94 bool moveRight = keysPressed.Contains(Keys.Right);
95 bool moveUp = keysPressed.Contains(Keys.Up);
96 bool moveDown = keysPressed.Contains(Keys.Down);
97 Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
98 if (!keysPressed.Contains(Keys.LeftControl))
99 {
100 if (game.IsCellOpen(destination))
101 {
102 mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
103 }
104 else
105 {
106 mMotion.Update(timeSpan);
107 }
108 }
109 else
110 {
111 mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);
112 }
113
114
115 if (projectileCoolDown > 0)
116 projectileCoolDown--;
117 else if (projectileCoolDown == 0)
118 {
119 if (keysPressed.Contains<Keys>(Keys.Space))
120 {
121 float velocityX = 0;
122 float velocityY = 0;
123 int startX = Coordinates.X;
124 int startY = Coordinates.Y;
125 if (mMotion.Direction == Direction.Down || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.LowerRight)
126 {
127 velocityY = 1;
128 startY = Coordinates.Y + 1;
129 }
130 else if (mMotion.Direction == Direction.Up || mMotion.Direction == Direction.UpperLeft || mMotion.Direction == Direction.UpperRight)
131 {
132 velocityY = -1;
133 startY = Coordinates.Y - 1;
134 }
135 if (mMotion.Direction == Direction.Right || mMotion.Direction == Direction.LowerRight || mMotion.Direction == Direction.UpperRight)
136 {
137 velocityX = 1;
138 startX = Coordinates.X + 1;
139 }
140 else if (mMotion.Direction == Direction.Left || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.UpperLeft)
141 {
142 velocityX = -1;
143 startX = Coordinates.X - 1;
144 }
145 Vector2 toShoot = new Vector2(velocityX, velocityY);
146 toShoot.Normalize();
147 toShoot *= projectileSpeed;
148 projectileCoolDown = shootCoolDown;
149 theDisplay.AddProjectiles(new Projectile(game.State.Map, projectileModel,
150 toShoot, new Point(startX, startY)));
151
152
153 }
154 }
155 }
156
157
158 public void powerUp(int amount)
159 {
160 health += amount;
161 }
162
163 public void Spawn(Vector2 spawn)
164 {
165 //gridX = (int)spawn.X;
166 //gridY = (int)spawn.Y;
167 visible = true;
168 }
169
170
171 }
172 }
This page took 0.037243 seconds and 4 git commands to generate.