03f5a65bcf27be1879abf276cc1454ad75f9bef2
[chaz/carfire] / CarFire / CarFire / CarFire / Melee.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 Melee : Player
13 {
14 #region Member Variables
15 const int hitCoolDown = 18;
16 const int baseHealth = 200;
17 const int baseDamage = 30;
18 int coolDown;
19 Texture2D charModel;
20 Texture2D projectileModel;
21 bool isAttacking;
22 int velocityX;
23 int velocityY;
24 #endregion
25
26 //zac variable
27 AnimateMelee animateMelee;
28
29 #region Public Methods
30 public Melee(Game theGame, String Name, Point position, int playerIndex)
31 : base(theGame, Name, position, playerIndex, baseHealth, baseDamage)
32 {
33 coolDown = hitCoolDown;
34 }
35 #endregion
36
37 #region Overridden Methods From Player
38 public override void LoadContent(ContentManager contentManager)
39 {
40 charModel = contentManager.Load<Texture2D>("cs"); //change to charModel when designed
41 projectileModel = contentManager.Load<Texture2D>("projectile"); //change to a projectile model later
42
43 /*Zac
44 */
45
46 animateMelee = new AnimateMelee(contentManager, this);
47
48 }
49 /// <summary>
50 /// This method will draw a character to the screen.
51 /// </summary>
52 /// <param name="spriteBatch"></param>
53 public override void Draw(SpriteBatch spriteBatch)
54 {
55 Rectangle position = Game.State.Map.GetRectangleFromCoordinates(Motion.Position);
56 Point aPosition = Game.State.Map.GetPointFromCoordinates(Motion.Position);
57 Vector2 drawPosition = new Vector2(aPosition.X, aPosition.Y);
58 //spriteBatch.Draw(charModel, position, Color.White);
59 if (isAttacking)
60 animateMelee.AttackLeft(spriteBatch, drawPosition);
61
62 }
63 public override void UpdateFrame(TimeSpan timeSpan)
64 {
65 animateMelee.Update(timeSpan);
66 }
67 public override void Attack(List<Keys> keysPressed)
68 {
69 if (coolDown > 0)
70 coolDown--;
71 else if (coolDown == 0)
72 {
73 isAttacking = false;
74 if (keysPressed.Contains<Keys>(Keys.Space))
75 {
76 isAttacking = true;
77 coolDown = hitCoolDown;
78 int startX = Coordinates.X;
79 int startY = Coordinates.Y;
80 if (Motion.Direction == Direction.Down || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.LowerRight)
81 {
82 startY = Coordinates.Y + 1;
83 }
84 else if (Motion.Direction == Direction.Up || Motion.Direction == Direction.UpperLeft || Motion.Direction == Direction.UpperRight)
85 {
86 startY = Coordinates.Y - 1;
87 }
88 if (Motion.Direction == Direction.Right || Motion.Direction == Direction.LowerRight || Motion.Direction == Direction.UpperRight)
89 {
90 startX = Coordinates.X + 1;
91 }
92 else if (Motion.Direction == Direction.Left || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.UpperLeft)
93 {
94 startX = Coordinates.X - 1;
95 }
96 //Attack a monster
97 if (!Game.IsCellOpen(new Point(startX, startY)))
98 {
99 IEntity toKill = Game.GetEntityAtCoordinates(new Point(startX, startY));
100 //See if it is a monster
101 if (toKill is IMonster)
102 {
103 IMonster hitMonster = (IMonster)toKill;
104 hitMonster.causeDamageTo(this.Damage);
105 if (hitMonster.Health > 0)
106 {
107 this.Score += Game.State.HitMonsterScore;
108 Console.WriteLine(this.Score);
109 }
110 else
111 {
112 this.Score += Game.State.KillMonsterScore;
113 Console.WriteLine(this.Score);
114 //Remove dead monsters
115 Game.State.Entities.Remove(toKill);
116 }
117 }
118 }
119 }
120 }
121
122
123 }
124 public override void PlayAttackSound()
125 {
126
127 }
128 public override void PlayDieSound()
129 {
130
131 }
132 #endregion
133 }
134 }
This page took 0.046197 seconds and 3 git commands to generate.