b1203dda96619505ed3e9757d0d8e46bcebe48ff
[chaz/carfire] / CarFire / CarFire / CarFire / Ranged.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 Ranged : Player
13 {
14 #region Member Variables
15 //The number of frames between each projectile is spawned.
16 const int shootCoolDown = 18;
17 const int baseHealth = 100;
18 const int baseDamage = 20;
19 Texture2D charModel;
20 Texture2D projectileModel;
21
22 //Used to draw projectiles
23 int projectileSpeed;
24 int projectileCoolDown;
25 #endregion
26
27 #region Public Methods
28 public Ranged(Game theGame, String Name, Point position, int playerIndex)
29 : base(theGame, Name, position, playerIndex, baseHealth, baseDamage)
30 {
31 projectileSpeed = 8;
32 }
33 #endregion
34
35 #region Overridden Methods From Player
36 public override void LoadContent(ContentManager contentManager)
37 {
38 charModel = contentManager.Load<Texture2D>("cs"); //change to charModel when designed
39 projectileModel = contentManager.Load<Texture2D>("projectile"); //change to a projectile model later
40
41 }
42 /// <summary>
43 /// This method will draw a character to the screen.
44 /// </summary>
45 /// <param name="spriteBatch"></param>
46 public override void Draw(SpriteBatch spriteBatch)
47 {
48 Rectangle position = Game.State.Map.GetRectangleFromCoordinates(Motion.Position);
49 spriteBatch.Draw(charModel, position, Color.White);
50 }
51
52 public override void Attack(List<Keys> keysPressed)
53 {
54 if (projectileCoolDown > 0)
55 projectileCoolDown--;
56 else if (projectileCoolDown == 0)
57 {
58 if (keysPressed.Contains<Keys>(Keys.Space))
59 {
60 float velocityX = 0;
61 float velocityY = 0;
62 int startX = Coordinates.X;
63 int startY = Coordinates.Y;
64 if (Motion.Direction == Direction.Down || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.LowerRight)
65 {
66 velocityY = 1;
67 startY = Coordinates.Y + 1;
68 }
69 else if (Motion.Direction == Direction.Up || Motion.Direction == Direction.UpperLeft || Motion.Direction == Direction.UpperRight)
70 {
71 velocityY = -1;
72 startY = Coordinates.Y - 1;
73 }
74 if (Motion.Direction == Direction.Right || Motion.Direction == Direction.LowerRight || Motion.Direction == Direction.UpperRight)
75 {
76 velocityX = 1;
77 startX = Coordinates.X + 1;
78 }
79 else if (Motion.Direction == Direction.Left || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.UpperLeft)
80 {
81 velocityX = -1;
82 startX = Coordinates.X - 1;
83 }
84 Vector2 toShoot = new Vector2(velocityX, velocityY);
85 toShoot.Normalize();
86 toShoot *= projectileSpeed;
87 projectileCoolDown = shootCoolDown;
88 Game.State.mProjectiles.Add(new Projectile(Game, projectileModel,
89 toShoot, new Point(startX, startY), PlayerIndex, Damage));
90 }
91 }
92
93
94 }
95 public override void PlayAttackSound()
96 {
97
98 }
99 public override void PlayDieSound()
100 {
101
102 }
103 #endregion
104
105
106 }
107 }
This page took 0.047575 seconds and 3 git commands to generate.