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