public static Entity ToEntity(Projectile p, ContentManager content) {
     Entity newEnt;
     try {
         newEnt = new Entity(content, p.Loc.X, p.Loc.Y,p.Direction, p.EntTexture.ToString(), true, p.rectangle);
         return newEnt;
     } catch (NullReferenceException) {
         try {
             newEnt = new Entity(content, p.Loc.X, p.Loc.Y,p.Direction, content.Load<Texture2D>("NoTexture").ToString(), true, p.rectangle);
             return newEnt;
         } catch (NullReferenceException e) {
             Console.WriteLine(e.ToString());
             return null;
         }
     }
 }
Example #2
0
 public virtual Projectile Shoot(ContentManager content, Character p, Camera c, int tileSize, Character e) {
     timeSinceLastShot = 0;
     if (CheckAmmo()) {
         Projectile proj = null;
         if (name.Equals("Rifle")) {
             proj = new Projectile(content, p.Loc.X, p.Loc.Y, p.Direction + GetSpread() * (Math.PI / 180.0), 3, "BulletTwo", true,
                                            new Rectangle((int)((c.camPos.X + p.Loc.X) * tileSize), (int)((c.camPos.Y + p.Loc.Y) * tileSize), tileSize, tileSize), range, true, e.IsPlayer);
         } else if (name.Equals("Pistol")) {
             proj = new Projectile(content, p.Loc.X, p.Loc.Y, p.Direction + GetSpread() * (Math.PI / 180.0), 3, "Bullet", true,
                                            new Rectangle((int)((c.camPos.X + p.Loc.X) * tileSize), (int)((c.camPos.Y + p.Loc.Y) * tileSize), tileSize, tileSize), range, false, e.IsPlayer);
         } else {
             proj = new Projectile(content, p.Loc.X, p.Loc.Y, p.Direction + GetSpread() * (Math.PI / 180.0), 3, "BulletTwo", true,
                                             new Rectangle((int)((c.camPos.X + p.Loc.X) * tileSize), (int)((c.camPos.Y + p.Loc.Y) * tileSize), tileSize, tileSize), range, false, e.IsPlayer);
         }
         ammo[0]--;
         return proj;
     } else {
         return null;
     }
 }