]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/Human.cs
acb0d3b8cd92cca04d68ca30fe11027aecbc3e44
[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 //Member Variables
15 String CharName;
16 Map theMap;
17 int movementSpeed;
18 int gridX;
19 int gridY;
20 Texture2D charModel;
21 int health;
22 int damage;
23 int range;
24 int score;
25 bool isMoving;
26 int pixelX;
27 int pixelY;
28 bool visible;
29
30 public Human(Map _theMap, String Name)
31 {
32 theMap = _theMap;
33 CharName = Name;
34
35 movementSpeed = 20; // randomly set now
36 health = 100;
37 score = 0;
38 visible = false;
39 }
40
41 public void LoadContent(ContentManager contentManager)
42 {
43 charModel = contentManager.Load<Texture2D>("deselectBox"); //change to charModel when designed
44 }
45
46 public void UnloadContent()
47 {
48
49 }
50
51 public long Update(GameTime gameTime, NetworkManager networkGame)
52 {
53 return 0;
54
55 }
56
57 public long Draw(SpriteBatch spriteBatch)
58 {
59 spriteBatch.Draw(charModel, theMap.GetRectangleFromCoordinates(gridX, gridY), Color.White);
60 return 0;
61 }
62
63 public int GridX { get { return gridX; } set { gridX = value; } }
64 public int GridY { get { return gridY; } set { gridY = value; } }
65 public int Health { get { return health; } }
66 public int Score { get { return score; } }
67 public bool alive { get { return health > 0; } }
68
69 public void causeDamageTo(int amount)
70 {
71 health -= amount;
72 }
73
74 /// <summary>
75 /// Moves the current player being controlled based on a given set of key presses.
76 /// The player can only move one grid space per movePlayer call. Thus this method
77 /// is made to be called ever update. The player will only move if the grid space
78 /// that is being moved to is an open space.
79 /// </summary>
80 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
81 public void MovePlayer(List<Keys> keysPressed)
82 {
83 // move upleft
84 keysPressed.Contains<Keys>(Keys.Left);
85 if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY - 1))
86 {
87 gridX -= 1;
88 gridY -= 1;
89 }
90 // move upright
91 else if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY - 1))
92 {
93 gridX += 1;
94 gridY -= 1;
95 }
96 // move downleft
97 else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY + 1))
98 {
99 gridX -= 1;
100 gridY += 1;
101 }
102 // move downright
103 else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY + 1))
104 {
105 gridX += 1;
106 gridY += 1;
107 }
108 // move up
109 else if (keysPressed.Contains<Keys>(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1))
110 {
111 gridY -= 1;
112 }
113 // move down
114 else if (keysPressed.Contains<Keys>(Keys.Down) && theMap.IsCellOpen(gridX, gridY + 1))
115 {
116 gridY += 1;
117 }
118 // move left
119 else if (keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY))
120 {
121 gridX -= 1;
122 }
123 // move right
124 else if (keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY))
125 {
126 gridX += 1;
127 }
128 }
129
130
131 public void powerUp(int amount)
132 {
133 health += amount;
134 }
135
136 public void Spawn(Vector2 spawn)
137 {
138 gridX = (int)spawn.X;
139 gridY = (int)spawn.Y;
140 visible = true;
141 }
142
143
144 }
145 }
This page took 0.042353 seconds and 3 git commands to generate.