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