//Checks through collsions with pick up items
 public static void CheckItemCollisions(List<PickUpItem> Items, Character player, ContentManager Content, Queue<SoundEffect> curSounds) {
     for (int f = 0; f < Items.Count; f++) {
         if (Items[f].CheckCollide(player)) {
             if (Items[f].ItemType.Equals("health")) {
                 if (player.Health < player.MaxHealth && !SkillSystem.skills[0].Active) {
                     player.Health += 2;
                     curSounds.Enqueue(Content.Load<SoundEffect>("healthSound"));
                 } else {
                     return;
                 }
             } else if (Items[f].ItemType.Equals("pistolammo")) {
                 Shooting.weapons[1].Ammo.Add(9);
                 curSounds.Enqueue(Content.Load<SoundEffect>("ammoSound"));
             } else if (Items[f].ItemType.Equals("smgammo")) {
                 Shooting.weapons[2].Ammo.Add(15);
                 curSounds.Enqueue(Content.Load<SoundEffect>("ammoSound"));
             } else if (Items[f].ItemType.Equals("shotgunammo")) {
                 Shooting.weapons[3].Ammo.Add(5);
                 curSounds.Enqueue(Content.Load<SoundEffect>("ammoSound"));
             } else if (Items[f].ItemType.Equals("rifleammo")) {
                 Shooting.weapons[4].Ammo.Add(4);
                 curSounds.Enqueue(Content.Load<SoundEffect>("ammoSound"));
             }
             Items.RemoveAt(f);
         }
     }
 }
        //Creates a random item at a specified position
        public static void CreateRandomItem(Random rng, ContentManager Content, List<PickUpItem> Items, double x, double y, Character player) {
            //A one in four chance of enemies dropping some sort of item
            int dropRate = rng.Next(0, 5);

            //If the value equals zero then drops a random item
            if (dropRate == 0 || dropRate == 1) {
                int drop = rng.Next(0, 101);
                // health
                if (drop > 90 && Shooting.weapons[4].IsAcquired) {
                    CreateRifleAmmo(Content, Items, x, y);               
                }
                //Thirty percent chance for rifle ammo
                else if (drop > 70 && Shooting.weapons[3].IsAcquired) {
                    CreateShotgunAmmo(Content, Items, x, y);
                    //Fifteen percent chance for SMG ammo
                } else if (drop > 55 && Shooting.weapons[2].IsAcquired) {
                    CreateSMGAmmo(Content, Items, x, y);
                    //Twenty percent chance for shotgun ammo
                } else if (drop > 30) {
                    CreatePistolAmmo(Content, Items, x, y);
                    //Fifteen percent chance for rifle ammo
                } else {
                    CreateHealthKit(Content, Items, x, y);
                }
            }
        }
        //Creates the wepaons that are int the game
        public static void CreateSkills(ContentManager Content, Character p) {
            //Adds the Overcharged skill
            skills[0] = new OverCharged(Content, p);
            //Adds the Perseverance skill
            skills[1] = new Perseverance(Content, p);
            //Adds the Rhinoceros skill
            skills[2] = new Rhinoceros(Content);

            //Sets all the skills to obtained
            skills[0].Obtained = true;
            skills[1].Obtained = true;
            skills[2].Obtained = true;
        }
Exemple #4
0
 public void UpdateSprint(KeyboardState state, KeyboardState oldState, int tileSize, Character player) {
     if (state.IsKeyDown(Keys.LeftShift)) {
         if (player.CheckStamina()) {
             maxVelocity = sprintVelocity;
             player.IsSprinting = true;
         } else {
             maxVelocity = normVelocity;
         }
     } else if (state.IsKeyUp(Keys.LeftShift) && oldState.IsKeyDown(Keys.LeftShift)) {
         maxVelocity = normVelocity;
         player.IsSprinting = false;
     }
 }
 public static Entity ToEntity(Character c, ContentManager content) {
     Entity newEnt;
     try {
         newEnt = new Entity(content, c.Loc.X, c.Loc.Y, c.Direction, c.EntTexture.ToString(), false, c.rectangle);
         return newEnt;
     }catch(NullReferenceException) {
         try {
             newEnt = new Entity(content, c.Loc.X, c.Loc.Y, c.Direction, content.Load<Texture2D>("NoTexture").ToString(), false, c.rectangle);
             return newEnt;
         }catch(NullReferenceException e) {
             Console.WriteLine(e.ToString());
             return null;
         }
     }
 }
 //Uses the player's skill
 public static void UseSkill(Character player, KeyboardState state, KeyboardState oldState, int time) {
     //Checks to see if the key is pressed
     if (state.IsKeyDown(Keys.D1) && oldState.IsKeyUp(Keys.D1) && !CheckActiveSkills() && skills[0].Obtained) {
         //Activate the skill and sets the timers
         skills[0].ActivateSkill();
     } else if (state.IsKeyDown(Keys.D2) && oldState.IsKeyUp(Keys.D2) && !CheckActiveSkills() && skills[1].Obtained) {
         //Activate the skill and sets the timers
         skills[1].ActivateSkill();
     } else if (state.IsKeyDown(Keys.D3) && oldState.IsKeyUp(Keys.D3) && !CheckActiveSkills() && skills[2].Obtained) {
         //Activate the skill and sets the timers
         skills[2].ActivateSkill();
     }
     foreach (Skill s in skills) {
         s.Status(time);
     }
 }
 //Constructor that takes the player object, and passes up static names for this skill
 public OverCharged(ContentManager content, Character p) : base(content, "NoTexture", "Overcharged", 6000, 3300) {
     player = p;
 }
        //method for mouse on main menu
        public Rectangle MouseClicked(int x, int y, Game1 game, ref int currentLevel, ref List<Enemy> enemies, ref List<PickUpItem> Items, ref List<Projectile> projectiles, ref int timer, ContentManager Content, ref Character player, ref string wepUnl, ref bool songPlaying, ref SoundEffectInstance song) {
            Rectangle mouseClickRect = new Rectangle(x, y, 1, 1);
            Rectangle startbuttonRect = new Rectangle((int)startButtonPosition.X, (int)startButtonPosition.Y, 300, 108);
            Rectangle exitbuttonRect = new Rectangle((int)exitButtonPosition.X, (int)exitButtonPosition.Y, 600, 192);

            if (gameState == "StartMenu") {
                //player clicks start
                if (mouseClickRect.Intersects(startbuttonRect)) {
                    try {
                        gameState = "Case";
                        CheckGameState();
                    } catch (GameStateNotFoundException) {
                        
                        gameState = "Case";
                    }

                }
                //player exits game
                else if (mouseClickRect.Intersects(exitbuttonRect)) {
                    game.Exit();
                }
                // player clicked on options
                else if (mouseClickRect.Intersects(optionsButtonPosition)) {
                    try {
                        gameState = "OptionsMenu";
                        lastState = "StartMenu";
                        CheckGameState();
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                } else if (mouseClickRect.Intersects(levelSelectButtonPosition)) {
                    try {
                        gameState = "LevelSelect";
                        lastState = "StartMenu";
                        CheckGameState();
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                }
            }
            //level select menu
            else if (gameState == "LevelSelect") {
                // back button clicked
                if (mouseClickRect.Intersects(backButtonPosition)) {
                    try {
                        gameState = lastState;
                        CheckGameState();
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                        lastState = "";
                    }
                } else if (mouseClickRect.Intersects(levelRect[0]) || mouseClickRect.Intersects(levelRect[1]) || mouseClickRect.Intersects(levelRect[2]) || mouseClickRect.Intersects(levelRect[3]) || mouseClickRect.Intersects(levelRect[4]) || mouseClickRect.Intersects(levelRect[5]) || mouseClickRect.Intersects(levelRect[6]) || mouseClickRect.Intersects(levelRect[7])) {
                    Shooting.CreateWeapons(Content);
                    if (mouseClickRect.Intersects(levelRect[0]) && levelClears[0] != 0) {
                        currentLevel = 1;
                        SkillSystem.CreateSkills(Content, player);
                        player.Health = player.MaxHealth;
                        player.Stamina = 100;
                        wepUnl = "";
                        player.Weapon = Shooting.weapons[1];
                        player.FrameLevel = 1;
                        enemies.Clear();
                        Items.Clear();
                        projectiles.Clear();
                        timer = 0;
                        gameState = "LevelSwitch";
                        CheckGameState();
                    } else if (mouseClickRect.Intersects(levelRect[1]) && levelClears[1] != 0) {
                        currentLevel = 2;
                        Shooting.weapons[2].IsAcquired = true;
                        SkillSystem.CreateSkills(Content, player);
                        player.Health = player.MaxHealth;
                        player.Stamina = 100;
                        wepUnl = "";
                        player.Weapon = Shooting.weapons[1];
                        player.FrameLevel = 1;
                        enemies.Clear();
                        Items.Clear();
                        projectiles.Clear();
                        timer = 0;
                        gameState = "LevelSwitch";
                        CheckGameState();
                    } else if (mouseClickRect.Intersects(levelRect[2]) && levelClears[2] != 0) {
                        currentLevel = 3;
                        Shooting.weapons[2].IsAcquired = true;
                        SkillSystem.CreateSkills(Content, player);
                        player.Health = player.MaxHealth;
                        player.Stamina = 100;
                        wepUnl = "";
                        player.Weapon = Shooting.weapons[1];
                        player.FrameLevel = 1;
                        enemies.Clear();
                        Items.Clear();
                        projectiles.Clear();
                        timer = 0;
                        gameState = "LevelSwitch";
                        CheckGameState();
                    } else if (mouseClickRect.Intersects(levelRect[3]) && levelClears[3] != 0) {
                        currentLevel = 4;
                        Shooting.weapons[2].IsAcquired = true;
                        Shooting.weapons[3].IsAcquired = true;
                        SkillSystem.CreateSkills(Content, player);
                        player.Health = player.MaxHealth;
                        player.Stamina = 100;
                        wepUnl = "";
                        player.Weapon = Shooting.weapons[1];
                        player.FrameLevel = 1;
                        enemies.Clear();
                        Items.Clear();
                        projectiles.Clear();
                        timer = 0;
                        gameState = "LevelSwitch";
                        CheckGameState();
                    } else if (mouseClickRect.Intersects(levelRect[4]) && levelClears[4] != 0) {
                        currentLevel = 5;
                        Shooting.weapons[2].IsAcquired = true;
                        Shooting.weapons[3].IsAcquired = true;
                        SkillSystem.CreateSkills(Content, player);
                        player.Health = player.MaxHealth;
                        player.Stamina = 100;
                        wepUnl = "";
                        player.Weapon = Shooting.weapons[1];
                        player.FrameLevel = 1;
                        enemies.Clear();
                        Items.Clear();
                        projectiles.Clear();
                        timer = 0;
                        gameState = "LevelSwitch";
                        CheckGameState();
                    }
                    else if (mouseClickRect.Intersects(levelRect[5]) && levelClears[5] != 0)
                    {
                        currentLevel = 6;
                        Shooting.weapons[2].IsAcquired = true;
                        Shooting.weapons[3].IsAcquired = true;
                        Shooting.weapons[4].IsAcquired = true;
                        SkillSystem.CreateSkills(Content, player);
                        player.Health = player.MaxHealth;
                        player.Stamina = 100;
                        wepUnl = "";
                        player.Weapon = Shooting.weapons[1];
                        player.FrameLevel = 1;
                        enemies.Clear();
                        Items.Clear();
                        projectiles.Clear();
                        timer = 0;
                        gameState = "LevelSwitch";
                        CheckGameState();
                    }
                    else if (mouseClickRect.Intersects(levelRect[6]) && levelClears[6] != 0)
                    {
                        currentLevel = 7;
                        Shooting.weapons[2].IsAcquired = true;
                        Shooting.weapons[3].IsAcquired = true;
                        Shooting.weapons[4].IsAcquired = true;
                        SkillSystem.CreateSkills(Content, player);
                        player.Health = player.MaxHealth;
                        player.Stamina = 100;
                        wepUnl = "";
                        player.Weapon = Shooting.weapons[1];
                        player.FrameLevel = 1;
                        enemies.Clear();
                        Items.Clear();
                        projectiles.Clear();
                        timer = 0;
                        gameState = "LevelSwitch";
                        CheckGameState();
                    }
                    else if (mouseClickRect.Intersects(levelRect[7]) && levelClears[7] != 0)
                    {
                        currentLevel = 8;
                        Shooting.weapons[2].IsAcquired = true;
                        Shooting.weapons[3].IsAcquired = true;
                        Shooting.weapons[4].IsAcquired = true;
                        SkillSystem.CreateSkills(Content, player);
                        player.Health = player.MaxHealth;
                        player.Stamina = 100;
                        wepUnl = "";
                        player.Weapon = Shooting.weapons[1];
                        player.FrameLevel = 1;
                        enemies.Clear();
                        Items.Clear();
                        projectiles.Clear();
                        timer = 0;
                        gameState = "LevelSwitch";
                        CheckGameState();
                    }

                }
            }
            //Death screen 
            else if (gameState == "Death") {
                if (mouseClickRect.Intersects(exitbuttonRect)) {
                    gameState = "StartMenu";
                    CheckGameState();
                }
            }//Victory state for beating the game
            else if (gameState == "Victory") {
                if (mouseClickRect.Intersects(rightStartButton)) {
                    gameState = "StartMenu";
                    CheckGameState();
                }
            }//Page for the Case story 
            else if (gameState == "Case") {
                if (mouseClickRect.Intersects(rightStartButton)) {
                    SkillSystem.CreateSkills(Content, player);
                    Shooting.CreateWeapons(Content);
                    player.Health = player.MaxHealth;
                    player.Stamina = 100;
                    wepUnl = "";
                    player.Weapon = Shooting.weapons[1];
                    player.FrameLevel = 1;
                    currentLevel = 1;
                    enemies.Clear();
                    Items.Clear();
                    projectiles.Clear();
                    timer = 0;
                    gameState = "LevelSwitch";
                    CheckGameState();
                }
            }
               //puased screen
               else if (gameState == "Paused") {
                if (mouseClickRect.Intersects(exitbuttonRect)) {
                    saveLevelClears();
                    song.Stop();
                    songPlaying = false;
                    gameState = "StartMenu";
                    CheckGameState();
                } else if (mouseClickRect.Intersects(optionsButtonPosition)) {
                    try {
                        gameState = "OptionsMenu";
                        lastState = "Paused";
                        CheckGameState();
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                } else if (mouseClickRect.Intersects(resumeButtonPosition)) {
                    try {
                        song.Resume();
                        gameState = "Playing";
                        CheckGameState();
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                }
            }

            //options screen method
            else if (gameState == "OptionsMenu") {
                // back button clicked
                if (mouseClickRect.Intersects(backButtonPosition)) {
                    try {
                        gameState = lastState;
                        CheckGameState();
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                        lastState = "";
                    }
                }
                // sounds button clicked
                else if (mouseClickRect.Intersects(soundsButtonPosition)) {
                    try {
                        gameState = "SoundsMenu";
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                }
                // graphics button clicked
                else if (mouseClickRect.Intersects(graphicsButtonPosition)) {
                    try {
                        gameState = "GraphicsMenu";
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                }
                // controls button clicked
                else if (mouseClickRect.Intersects(controlButtonPosition)) {
                    try {
                        gameState = "Controls";
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                }
            }

            // Sounds menu
            else if (gameState == "SoundsMenu") {
                if (mouseClickRect.Intersects(backButtonPosition)) {
                    try {
                        gameState = "OptionsMenu";
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                }
            }


            // Controls menu
            else if (gameState == "Controls") {
                if (mouseClickRect.Intersects(controlBackButtonPosition)) {
                    try {
                        gameState = "OptionsMenu";
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                }
            }
            // graphics menu
            else if (gameState == "GraphicsMenu") {
                if (mouseClickRect.Intersects(backButtonPosition)) {
                    try {
                        gameState = "OptionsMenu";
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                }
            }
            return mouseClickRect;
        }
Exemple #9
0
 //Overrrides the shoot method to create a more accurate short range projectile
 public override Projectile Shoot(ContentManager content, Character p, Camera c, int tileSize, Character e) {
     return new Projectile(content, p.Loc.X, p.Loc.Y, p.Direction + GetSpread() * (Math.PI / 180.0), 5, "EmptyTile", true,
                                         new Rectangle((int)((c.camPos.X + p.Loc.X) * tileSize), (int)((c.camPos.Y + p.Loc.Y) * tileSize), tileSize, tileSize), 1, false, e.IsPlayer);
 }
Exemple #10
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;
     }
 }
 //Constructor that takes the player object, and passes up static names for this skill
 public Perseverance(ContentManager content, Character p) : base(content, "NoTexture", "Perseverance", 6000, 3500) {
     player = p;
 }
Exemple #12
0
        public bool CheckHit(Character e, Weapon w) {
            //Converts the direction from radians to degrees
            double directionDegrees = this.direction * 57.2958;

            //Checks collision based on the direction the projectile is rotated to
            //Checks angles in the fourth quadrant
            if (directionDegrees > 270 && directionDegrees <= 360) {
                if (this.loc.X + 1 < e.Loc.X + 0.5 && this.loc.X + 1 > e.Loc.X - 0.5 && this.loc.Y + 1 < e.Loc.Y + 0.5 && this.loc.Y + 1 > e.Loc.Y - 0.5) {
                    //Decrements the character's health
                    if (e.IsPlayer && !playerShot) {
                        e.Health -= w.Damage;
                        return true;
                    } else if (!e.IsPlayer && playerShot) {
                        e.Health -= w.Damage;
                        return true;
                    }
                }
            }
            //Checks angles in the third quadrant
            else if (directionDegrees > 180 && directionDegrees <= 270) {
                if (this.loc.X < e.Loc.X + 0.5 && this.loc.X > e.Loc.X - 0.5 && this.loc.Y + 1 < e.Loc.Y + 0.5 && this.loc.Y + 1 > e.Loc.Y - 0.5) {
                    //Decrements the character's health
                    if (e.IsPlayer && !playerShot) {
                        e.Health -= w.Damage;
                        return true;
                    } else if (!e.IsPlayer && playerShot) {
                        e.Health -= w.Damage;
                        return true;
                    }
                }
            }
            //Checks angles in the second quadrant
            else if (directionDegrees > 90 && directionDegrees <= 180) {
                if (this.loc.X < e.Loc.X + 0.5 && this.loc.X > e.Loc.X - 0.5 && this.loc.Y < e.Loc.Y + 0.5 && this.loc.Y > e.Loc.Y - 0.5) {
                    //Decrements the character's health
                    if (e.IsPlayer && !playerShot) {
                        e.Health -= w.Damage;
                        return true;
                    } else if (!e.IsPlayer && playerShot) {
                        e.Health -= w.Damage;
                        return true;
                    }
                }
            }
            //Checks angles in the first quadrant
            else {
                if (this.loc.X < e.Loc.X + 0.5 && this.loc.X > e.Loc.X - 0.5 && this.loc.Y < e.Loc.Y + 0.5 && this.loc.Y > e.Loc.Y - 0.5) {
                    //Decrements the character's health
                    if (e.IsPlayer && !playerShot) {
                        e.Health -= w.Damage;
                        return true;
                    } else if (!e.IsPlayer && playerShot) {
                        e.Health -= w.Damage;
                        return true;
                    }
                }
            }

            //Else returns false if no collision occurs
            return false;
        }
Exemple #13
0
        public static void DrawHUD(Character player, ref SpriteBatch spriteBatch, int screenHeight, int screenWidth, SpriteFont arial, Texture2D health, Texture2D healthBar, Texture2D stamina, Texture2D[] skillIcon) {
            //Draws HUD___________________________________________________________________________________________
            //weapon indicator at bottom right
            spriteBatch.Draw(player.Weapon.Texture, new Rectangle(screenWidth - player.Weapon.Texture.Width * 1 / 2,
                                                                    screenHeight - player.Weapon.Texture.Height * 1 / 2,
                                                                    player.Weapon.Texture.Width / 3,
                                                                    player.Weapon.Texture.Height / 3), Color.White);
            //Weapon name
            spriteBatch.DrawString(arial, player.Weapon.Name, new Vector2(screenWidth - player.Weapon.Texture.Width * 1 / 3,
                                                                            screenHeight - player.Weapon.Texture.Height * 1 / 2 - arial.MeasureString(player.Weapon.Name).Y), Color.Red);
            //health bar background
            spriteBatch.Draw(health, new Rectangle(screenWidth / 20 + (screenWidth / 100),
                                                    screenHeight / 20 + (int)(screenHeight / 52),
                                                    screenWidth / 4 - (screenWidth / 50),
                                                    screenHeight / 15 - (int)(screenHeight / 30)), Color.Black);
            //health
            if (SkillSystem.skills[1].Active) {
                spriteBatch.Draw(health, new Rectangle(screenWidth / 20 + (screenWidth / 100),
                                                        screenHeight / 20 + (int)(screenHeight / 52),
                                                        (int)((screenWidth / 4 - (screenWidth / 50)) * (player.Health / (player.MaxHealth * 2 + 0.0))),
                                                        screenHeight / 15 - (int)(screenHeight / 30)), Color.RoyalBlue);
            } else {
                spriteBatch.Draw(health, new Rectangle(screenWidth / 20 + (screenWidth / 100),
                                                        screenHeight / 20 + (int)(screenHeight / 52),
                                                        (int)((screenWidth / 4 - (screenWidth / 50)) * (player.Health / (player.MaxHealth + 0.0))),
                                                        screenHeight / 15 - (int)(screenHeight / 30)), Color.Magenta);
            }
            //Draws background for stamina
            spriteBatch.Draw(health, new Rectangle(screenWidth / 20 + (screenWidth / 100),
                                                    screenHeight / 10 + (int)(screenHeight / 52),
                                                    screenWidth / 4 - (screenWidth / 50),
                                                    screenHeight / 15 - (int)(screenHeight / 30)), Color.Black);
            //Draws stamina bar
            spriteBatch.Draw(stamina, new Rectangle(screenWidth / 20 + (screenWidth / 100),
                                                        screenHeight / 10 + (int)(screenHeight / 52),
                                                        (int)((screenWidth / 4 - (screenWidth / 50)) * (player.Stamina / (100.0))),
                                                        screenHeight / 15 - (int)(screenHeight / 30)), Color.White);
            //stamina bar
            spriteBatch.Draw(healthBar, new Rectangle(screenWidth / 20, (int)(screenHeight / 8.5), screenWidth / 4, screenHeight / 25), Color.White);
            //health bar
            spriteBatch.Draw(healthBar, new Rectangle(screenWidth / 20, screenHeight / 20, screenWidth / 4, screenHeight / 15), Color.White);

            //Skill Icons
            spriteBatch.Draw(health, new Rectangle(screenWidth / 20 + (screenWidth / 100),
                                                    (int)(screenHeight / 6.3),
                                                    (screenWidth / 28) * 3,
                                                    (int)(screenHeight / 14.5) - (int)(screenHeight / 30)), Color.SlateGray);
            //If no skills are active then draw them gray
            if (!SkillSystem.CheckActiveSkills()) {
                spriteBatch.Draw(skillIcon[0], new Rectangle((screenWidth / 20 + (screenWidth / 100)) + 3, (int)(screenHeight / 6.3), screenWidth / 30, screenHeight / 30), Color.White);
                spriteBatch.Draw(skillIcon[1], new Rectangle((screenWidth / 20 + (screenWidth / 100) + (screenWidth / 30)) + 4, (int)(screenHeight / 6.3), screenWidth / 30, screenHeight / 30), Color.White);
                spriteBatch.Draw(skillIcon[2], new Rectangle((screenWidth / 20 + (screenWidth / 100) + (screenWidth / 30) * 2) + 5, (int)(screenHeight / 6.3), screenWidth / 30, screenHeight / 30), Color.White);
            } else {
                //If the first one is active then draw it green and the others red
                if (SkillSystem.skills[0].Active) {
                    spriteBatch.Draw(skillIcon[0], new Rectangle((screenWidth / 20 + (screenWidth / 100)) + 3, (int)(screenHeight / 6.3), screenWidth / 30, screenHeight / 30), Color.Green);
                    spriteBatch.Draw(skillIcon[1], new Rectangle((screenWidth / 20 + (screenWidth / 100) + (screenWidth / 30)) + 4, (int)(screenHeight / 6.3), screenWidth / 30, screenHeight / 30), Color.Red);
                    spriteBatch.Draw(skillIcon[2], new Rectangle((screenWidth / 20 + (screenWidth / 100) + (screenWidth / 30) * 2) + 5, (int)(screenHeight / 6.3), screenWidth / 30, screenHeight / 30), Color.Red);
                    //If the second one is active then draw it green and the others red
                } else if (SkillSystem.skills[1].Active) {
                    spriteBatch.Draw(skillIcon[0], new Rectangle((screenWidth / 20 + (screenWidth / 100)) + 3, (int)(screenHeight / 6.3), screenWidth / 30, screenHeight / 30), Color.Red);
                    spriteBatch.Draw(skillIcon[1], new Rectangle((screenWidth / 20 + (screenWidth / 100) + (screenWidth / 30)) + 4, (int)(screenHeight / 6.3), screenWidth / 30, screenHeight / 30), Color.Green);
                    spriteBatch.Draw(skillIcon[2], new Rectangle((screenWidth / 20 + (screenWidth / 100) + (screenWidth / 30) * 2) + 5, (int)(screenHeight / 6.3), screenWidth / 30, screenHeight / 30), Color.Red);
                    //If the third one is active then draw it green and the others red
                } else if (SkillSystem.skills[2].Active) {
                    spriteBatch.Draw(skillIcon[0], new Rectangle((screenWidth / 20 + (screenWidth / 100)) + 3, (int)(screenHeight / 6.3), screenWidth / 30, screenHeight / 30), Color.Red);
                    spriteBatch.Draw(skillIcon[1], new Rectangle((screenWidth / 20 + (screenWidth / 100) + (screenWidth / 30)) + 4, (int)(screenHeight / 6.3), screenWidth / 30, screenHeight / 30), Color.Red);
                    spriteBatch.Draw(skillIcon[2], new Rectangle((screenWidth / 20 + (screenWidth / 100) + (screenWidth / 30) * 2) + 5, (int)(screenHeight / 6.3), screenWidth / 30, screenHeight / 30), Color.Green);
                    //If none are able to be used then draw them red
                } else {
                    spriteBatch.Draw(skillIcon[0], new Rectangle((screenWidth / 20 + (screenWidth / 100)) + 3, (int)(screenHeight / 6.3), screenWidth / 30, screenHeight / 30), Color.Red);
                    spriteBatch.Draw(skillIcon[1], new Rectangle((screenWidth / 20 + (screenWidth / 100) + (screenWidth / 30)) + 4, (int)(screenHeight / 6.3), screenWidth / 30, screenHeight / 30), Color.Red);
                    spriteBatch.Draw(skillIcon[2], new Rectangle((screenWidth / 20 + (screenWidth / 100) + (screenWidth / 30) * 2) + 5, (int)(screenHeight / 6.3), screenWidth / 30, screenHeight / 30), Color.Red);
                }
            }


            //ammo
            for (int i = 0; i < player.Weapon.Ammo.Count && i < 8; i++) {
                spriteBatch.Draw(health, new Rectangle(screenWidth * 6 / 7 - 2,
                                                        (screenHeight / 18) + (i * 35) - 2,
                                                        player.Weapon.maxAmmo * 18 + 2,
                                                        31), Color.DarkGray);
                for (int j = 0; j < player.Weapon.Ammo[i]; j++) {
                    spriteBatch.Draw(player.Weapon.AmmoTexture,
                                    new Rectangle(screenWidth * 6 / 7 + (j * 17),
                                                    (screenHeight / 18) + (i * 35) - 2,
                                                    19, 31), Color.White);
                }
            }
            spriteBatch.DrawString(arial, "Ammo Left: " + player.Weapon.TotalAmmo() + " / " + player.Weapon.Ammo.Count, new Vector2((int)(screenWidth * 5.3 / 7 - 2),
                                                                                                (screenHeight / 18) - arial.MeasureString(" ").Y - 10), Color.Red);
        }
Exemple #14
0
        //Switches the player's weapon
        public static void SwitchWeapon(Character player, KeyboardState state, KeyboardState oldState) {
            if (!player.IsMeleeing && !(SkillSystem.skills[2].Active && player.IsSprinting)) {
                //Press E to switch the player's weapon
                if (state.IsKeyDown(Keys.E) && oldState.IsKeyUp(Keys.E)) {
                    //Gets the index of the player's current weapon
                    int index = 0;
                    for (int i = 0; i < weapons.Length; i++) {
                        if (weapons[i].Name.Equals(player.Weapon.Name)) {
                            //Sets the new index to the old one plus one and breaks the loop
                            index = i + 1;
                            break;
                        }
                    }

                    //Makes sure there is a weapon in the next slot or sets it to the first slot
                    if (index == weapons.Length) {
                        index = 1;
                    }

                    //Changes the weapon
                    if (weapons[index].IsAcquired) {
                        player.Weapon = weapons[index];
                        player.FrameLevel = index;
                        player.Frame = 0;
                    } else
                    {
                        player.Weapon = weapons[1];
                        player.FrameLevel = 1;
                        player.Frame = 0;
                    }
                } else if (state.IsKeyDown(Keys.Q) && oldState.IsKeyUp(Keys.Q)) {
                    //Gets the index of the player's current weapon
                    int index = 0;
                    for (int i = 0; i < weapons.Length; i++) {
                        if (weapons[i].Name.Equals(player.Weapon.Name)) {
                            //Sets the new index to the old one plus one and breaks the loop
                            index = i - 1;
                            break;
                        }
                    }
                    if (index < 1) {
                        index = weapons.Length - 1;
                    }
                    //Changes the weapon
                    for (int i = index; i > 0; i--)
                    {
                        if (weapons[i].IsAcquired)
                        {
                            player.Weapon = weapons[i];
                            player.FrameLevel = i;
                            player.Frame = 0;
                            break;
                        }
                    }
                }
            }

        }
Exemple #15
0
        // constructor that reads fro a file map.cs
        public Map(ContentManager content, string filename, Camera c, Character player, List<Enemy> enemies, int screenWidth) {
            Texture2D empTexture = content.Load<Texture2D>("EmptyTile");
            tileSize = screenWidth / 20;

            BinaryReader input = new BinaryReader(File.OpenRead("Content/" + filename));
            int mapWidth = input.ReadInt32();
            int mapHeight = input.ReadInt32();

            tileMap = new Texture2D[mapWidth, mapHeight];
            objectMap = new MapObject[mapWidth, mapHeight];
            tileRot = new int[tileMap.GetLength(0), tileMap.GetLength(1)];
            objRot = new int[tileMap.GetLength(0), tileMap.GetLength(1)];


            for (int i = 0; i < tileMap.GetLength(0); i++) {
                for (int j = 0; j < tileMap.GetLength(1); j++) {
                    string txtrString = input.ReadString();
                    if (!txtrString.Equals("null")) {
                        Texture2D texture = content.Load<Texture2D>(txtrString);
                        tileMap[i, j] = texture;
                    } else {
                        tileMap[i, j] = empTexture;
                    }
                }
            }

            for (int i = 0; i < tileMap.GetLength(0); i++) {
                for (int j = 0; j < tileMap.GetLength(1); j++) {
                    tileRot[i, j] = input.ReadInt32();
                }
            }

            for (int i = 0; i < objectMap.GetLength(0); i++) {
                for (int j = 0; j < objectMap.GetLength(1); j++) {
                    string txtrString = input.ReadString();
                    if (!txtrString.Equals("null")) {
                        objectMap[i, j] = new MapObject(content, true, txtrString, i, j);
                    } else {
                        objectMap[i, j] = null;
                    }
                }
            }

            for (int i = 0; i < objectMap.GetLength(0); i++) {
                for (int j = 0; j < objectMap.GetLength(1); j++) {
                    objRot[i, j] = input.ReadInt32();
                }
            }

            int entWidth = input.ReadInt32();
            int entHieght = input.ReadInt32();
            int[,] entRot = new int[entWidth, entHieght];

            for (int i = 0; i < entRot.GetLength(0); i++) {
                for (int j = 0; j < entRot.GetLength(1); j++) {
                    entRot[i, j] = input.ReadInt32();
                }
            }
            
            for (int x = 0; x < entWidth; x++) {
                for (int y = 0; y < entHieght; y++) {
                    string txtrString = input.ReadString();
                    if (txtrString.Equals("null")) {
                        continue;
                    } else if (txtrString.Equals("Enemy")) {
                        CreateEnemy.CreateNormalEnemy(ref enemies, content, c, this, x, y, entRot[x,y] * -1.5708f);
                    } else if (txtrString.Equals("RiotEnemy")) {
                        CreateEnemy.CreateRiotEnemy(ref enemies, content, c, this, x, y, entRot[x, y] * -1.5708f);
                    }
                }
            }

            string playerPos = input.ReadString();
            string[] playerParts = playerPos.Split(',');
            double distX = player.Loc.X - double.Parse(playerParts[1]);
            double distY = player.Loc.Y - double.Parse(playerParts[2]);
            
            player.Loc.X -= distX;
            player.Loc.Y -= distY;
            c.camPos.X += distX;
            c.camPos.Y += distY;
            
            input.Close();
        }
Exemple #16
0
 //Shoots the player's current gun
 public static void ShootWeapon(Character player, MouseState mState, MouseState oldMState, List<Projectile> projectiles, bool temp, Camera c, ContentManager Content, Queue<SoundEffect> curSounds, Dictionary<string, SoundEffect> soundEffects, ref Map m) {
     if (!player.IsMeleeing && !(SkillSystem.skills[2].Active && player.IsSprinting)) {
         if (player.Weapon.Auto) {
             if (oldMState.LeftButton == ButtonState.Pressed) {
                 if (temp) {
                     SoundEffect TempSound;
                     //enqueue gunshot sound
                     //only shoot if not a null projectile
                     Projectile p = player.Weapon.Shoot(Content, player, c, m.TileSize, player);
                     if (p != null) {
                         //create new projectile
                         projectiles.Add(p);
                         //load and enqueue sound
                         soundEffects.TryGetValue("gunshot", out TempSound);
                         curSounds.Enqueue(player.Weapon.ShootSound);
                         m.sounds.Add(player.Loc);
                         //add the player's sound to the map's sound queue for AI to detect
                         m.sounds.Add(player.Loc);
                         c.screenShake = true;
                     } else {
                         player.Weapon.Shoot(Content, player, c, m.TileSize, player);
                         //enqueue gun click sound if empty
                         soundEffects.TryGetValue("emptyClick", out TempSound);
                         curSounds.Enqueue(TempSound);
                     }
                 }
             }
         } else {
             if (oldMState.LeftButton == ButtonState.Pressed && mState.LeftButton != ButtonState.Pressed) {
                 if (temp) {
                     if (player.Weapon.Name.Equals("Shotgun")) {
                         SoundEffect TempSound;
                         //enqueue gunshot sound
                         //only shoot if not a null projectile
                         Projectile p = player.Weapon.Shoot(Content, player, c, m.TileSize, player);
                         if (p != null) {
                             player.Weapon.Ammo[0] += 2;
                             Projectile p2 = player.Weapon.Shoot(Content, player, c, m.TileSize, player);
                             Projectile p3 = player.Weapon.Shoot(Content, player, c, m.TileSize, player);
                             projectiles.Add(p);
                             projectiles.Add(p2);
                             projectiles.Add(p3);
                             soundEffects.TryGetValue("shotgunSound.wav", out TempSound);
                             curSounds.Enqueue(player.Weapon.ShootSound);
                             m.sounds.Add(player.Loc);
                             c.screenShake = true;
                         } else {
                             player.Weapon.Shoot(Content, player, c, m.TileSize, player);
                             //enqueue gun click sound if empty
                             soundEffects.TryGetValue("emptyClick", out TempSound);
                             curSounds.Enqueue(TempSound);
                         }
                     } else {
                         SoundEffect TempSound;
                         //enqueue gunshot sound
                         //only shoot if not a null projectile
                         Projectile p = player.Weapon.Shoot(Content, player, c, m.TileSize, player);
                         if (p != null) {
                             projectiles.Add(p);
                             soundEffects.TryGetValue("gunshot", out TempSound);
                             curSounds.Enqueue(player.Weapon.ShootSound);
                             m.sounds.Add(player.Loc);
                             c.screenShake = true;
                         } else {
                             player.Weapon.Shoot(Content, player, c, m.TileSize, player);
                             //enqueue gun click sound if empty
                             soundEffects.TryGetValue("emptyClick", out TempSound);
                             curSounds.Enqueue(TempSound);
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #17
0
 //Method to use the player's knife
 public static void Stab(Character player, KeyboardState state, KeyboardState oldState, ContentManager content, Camera c, int tileSize, List<Projectile> projectiles, Queue<SoundEffect> curSounds) {
     //If the player presses 'V' then does a melee attack
     if (state.IsKeyDown(Keys.Space) && oldState.IsKeyUp(Keys.Space) && (!SkillSystem.skills[2].Active && !player.IsSprinting) && !player.Weapon.isReloading) {
         projectiles.Add(weapons[0].Shoot(content, player, c, tileSize, player));
         curSounds.Enqueue(weapons[0].ShootSound);
         //Sets the player to a melee state
         player.IsMeleeing = true;
         //Sets animation values
         player.NumOfFrames = 9;
         player.Frame = 0;
         player.FrameLevel = 0;
         player.TimePerFrame = 100;
     }
 }