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