Exemple #1
0
 public Player(Texture2D texture, Texture2D heartTexture, Vector2 position, float speed, int textureRows, int textureColumns
     , int totalFrames, int animationSpeed, Weapon weapon)
     : base(texture, position, textureRows, textureColumns, totalFrames, animationSpeed) {
     this.speed = speed;
     storedAnimationSpeed = animationSpeed;
     Health = 10;
     Heart = heartTexture;
     Weapon = weapon;
 }
Exemple #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime) {
            // Allows the game to exit
            if (Keyboard.GetState().IsKeyDown(Keys.Escape) && !(menu.menuType == MenuType.CreditMenu)) {
                this.Exit();
            }
            

            ms = Mouse.GetState();
            menu.Update(ms, msOld);

            if (menu.menuType == MenuType.CreditMenu && (Keyboard.GetState().GetPressedKeys().Length > 0)) {
                    menu.menuType = MenuType.StartMenu;
            }
            if (menu.menuType == MenuType.WinMenu) {
                winElapsed += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                if (winElapsed > 400) {
                    if (winAni) {
                        winElapsed -= 400;
                        winAni = false;
                    }
                    else {
                        winElapsed -= 400;
                        winAni = true;
                    }
                }
            }

            #region game
            if (menu.menuType == MenuType.InGame) {
                if (musicGameInstance.State == SoundState.Stopped)
                {
                    musicMenuInstance.Stop();
                    musicFinalInstance.Stop();
                    musicGameInstance.Play();
                }

                float elapsed = (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                if (!p.Dead) {
                    p.Update(elapsed, Keyboard.GetState(), oldState, Mouse.GetState(), msOld);
                    if (Mouse.GetState().LeftButton == ButtonState.Pressed && msOld.LeftButton == ButtonState.Released && p.Weapon.weaponType == WeaponType.Drumsticks)
                        CurrentRoom.Animations.Add(new TempObject(Content.Load<Texture2D>("Rings"), p.Position, 1, 4, 4, 100, 0));
                }
                p.Position = p.Position.X < 50 ? p.OldPos : p.Position;
                p.Position = p.Position.X > World.RoomWidth - 50 ? p.OldPos : p.Position;
                p.Position = p.Position.Y < 60 ? p.OldPos : p.Position;
                p.Position = p.Position.Y > World.RoomHeight - 60 ? p.OldPos : p.Position;

                if (Keyboard.GetState().IsKeyDown(Keys.X) && oldState.IsKeyUp(Keys.X) && CurrentRoom.WOP != null && CurrentRoom.Monsters.Count == 0) {
                    if (Vector2.Distance(p.Position, CurrentRoom.WOP.Position) < 100) {
                        tmpWeapon = CurrentRoom.WOP.ContainedWeapon;
                        CurrentRoom.WOP = new WeaponOnGround(p.Weapon.weaponTexture, weaponOnGroundPosition, p.Weapon);


                        if (p.Weapon.weaponType == WeaponType.Drumsticks) {
                            CurrentRoom.WOP.Texture = drumsticksOnGround;
                        }
                        else if (p.Weapon.weaponType == WeaponType.ElectricGuitar) {
                            CurrentRoom.WOP.Texture = electricGuitarOnGround;
                        }
                        else if (p.Weapon.weaponType == WeaponType.Guitar) {
                            CurrentRoom.WOP.Texture = guitarOnGround;
                        }
                        else if (p.Weapon.weaponType == WeaponType.Triangle) {
                            CurrentRoom.WOP.Texture = triangleOnGround;
                        }
                        p.Weapon = tmpWeapon;
                    }
                }

                #region Collision

                
                if (!p.Dead) {
                    foreach (Zombie z in CurrentRoom.Monsters.Where(x => x is Zombie)) {
                    z.Update(elapsed, p.Position);
                        if (z.CollisionBox.Intersects(p.CollisionBox) && p.invTmr <= 0) {
                        p.Health -= 1;
                        p.invTmr = 1.5f;
                    }
                }
                    foreach (Charger c in CurrentRoom.Monsters.Where(x => x is Charger)) {
                    c.Update(elapsed, p.Position);
                        if (c.CollisionBox.Intersects(p.CollisionBox) && p.invTmr <= 0) {
                        p.Health -= 1;
                        p.invTmr = 1.5f;
                    }
                }
                    foreach (SpitZombie sZ in CurrentRoom.Monsters.Where(x => x is SpitZombie)) {
                    sZ.Update(elapsed, p.Position, CurrentRoom.Props);
                        for (int i = 0; i < sZ.SpitList.Count; i++) {
                            if (sZ.SpitList[i].CollisionBox.Intersects(p.CollisionBox) && p.invTmr <= 0) {
                            p.Health--;
                            p.invTmr = 1.5f;
                            sZ.SpitList[i].Collectable = true;
                        }
                            else if (sZ.SpitList[i].CollisionBox.Intersects(p.CollisionBox)) {
                            sZ.SpitList[i].Collectable = true;
                        }
                            for (int q = 0; q < p.Weapon.hit.Count; q++) {
                                if (sZ.SpitList[i].CollisionBox.Intersects(p.Weapon.hit[q].CollisionBox)) {
                                sZ.SpitList[i].Collectable = true;
                            }
                        }
                    }

                }
                }
                if (!(World.CurrentRoomLocationCode[0] == World.LastRoom[0] && World.CurrentRoomLocationCode[1] == World.LastRoom[1])) {
                    foreach (var item in CurrentRoom.Props) {
                        if (item.CollisionBox.Intersects(p.CollisionBox)) {
                            p.Position = p.OldPos;
                        }
                        foreach (Zombie z in CurrentRoom.Monsters.Where(x => x is Zombie)) {
                            if (z.CollisionBox.Intersects(item.CollisionBox)) {
                                z.Position = z.OldPos;
                            }
                        }
                        foreach (Charger c in CurrentRoom.Monsters.Where(x => x is Charger)) {
                            if (c.CollisionBox.Intersects(item.CollisionBox)) {
                                c.Position = c.OldPos;
                                c.charging = false;
                                c.wait = 0;
                            }
                        }
                        foreach (SpitZombie sZ in CurrentRoom.Monsters.Where(x => x is SpitZombie)) {
                            if (sZ.CollisionBox.Intersects(item.CollisionBox)) {
                                sZ.Position = sZ.OldPos;
                                sZ.facingTowards = true;
                            }
                        }
                        for (int i = 0; i < p.Weapon.projectile.Count; i++) {
                            if (
                                p.Weapon.projectile[i].HitCollisionBox.Intersects(item.CollisionBox)) {
                                p.Weapon.projectile[i].Collectable = true;
                            }
                        }
                    }
                }
                for (int i = 0; i < CurrentRoom.Monsters.Count; i++) {
                    for (int q = 0; q < p.Weapon.hit.Count; q++) {
                        if (CurrentRoom.Monsters[i].CollisionBox.Intersects(p.Weapon.hit[q].HitCollisionBox)) {
                            CurrentRoom.Monsters[i].Health -= p.Weapon.damage;
                            if (CurrentRoom.Monsters[i].Health <= 0) {
                                if (CurrentRoom.Monsters[i] is Zombie) {
                                    CurrentRoom.Animations.Add(new TempObject(Content.Load<Texture2D>("Zombie_death_sprite"), CurrentRoom.Monsters[i].Position
                                        , 1, 15, 15, 200, CurrentRoom.Monsters[i].Rotation));
                                }
                                CurrentRoom.Monsters[i].Collectable = true;
                            }
                        }

                    }
                    for (int q = 0; q < p.Weapon.projectile.Count; q++) {
                        if (CurrentRoom.Monsters[i].CollisionBox.Intersects(p.Weapon.projectile[q].HitCollisionBox)) {
                            CurrentRoom.Monsters[i].Health -= p.Weapon.damage;
                            if (CurrentRoom.Monsters[i].Health <= 0) {
                                if (CurrentRoom.Monsters[i] is Zombie) {
                                    CurrentRoom.Animations.Add(new TempObject(Content.Load<Texture2D>("Zombie_death_sprite"), CurrentRoom.Monsters[i].Position
                                        , 1, 15, 15, 200, CurrentRoom.Monsters[i].Rotation));
                                }
                                CurrentRoom.Monsters[i].Collectable = true;
                            }
                            if (p.Weapon.weaponType == WeaponType.ElectricGuitar)
                                p.Weapon.projectile[q].Collectable = true;
                        }

                    }
                }
                #endregion
                #region A
                #endregion
                CurrentRoom.Animations.ForEach(x => x.Update(elapsed));
                #region Garbage
                foreach (SpitZombie sZ in CurrentRoom.Monsters.Where(x => x is SpitZombie)) {
                    for (int i = 0; i < sZ.SpitList.Count; i++) {
                        if (sZ.SpitList[i].Collectable) {
                            sZ.SpitList.RemoveAt(i);
                            i--;
                        }
                    }
                }
                if (p.Weapon.weaponType == WeaponType.Drumsticks) {
                    for (int i = 0; i < p.Weapon.projectile.Count; i++) {
                        if (Vector2.Distance(p.Weapon.projectile[i].Position, p.Position) > 100) {
                            p.Weapon.projectile[i].Collectable = true;
                        }
                    }
                }
                for (int i = 0; i < CurrentRoom.Animations.Count; i++) {
                    if (CurrentRoom.Animations[i].Collectable) {
                        CurrentRoom.Animations.RemoveAt(i);
                        i--;
                    }
                }
                for (int i = 0; i < CurrentRoom.Monsters.Count; i++) {
                    if (CurrentRoom.Monsters[i].Collectable) {
                        CurrentRoom.Monsters.RemoveAt(i);
                        i--;
                    }
                }
                for (int i = 0; i < p.Weapon.projectile.Count; i++) {
                    if (p.Weapon.projectile[i].Collectable) {
                        p.Weapon.projectile.RemoveAt(i);
                        i--;
                    }
                }
                #endregion

                if (CurrentRoom.Monsters.Count == 0 && monsterCountOld != 0 && CurrentRoom.WOP == null)//NEED TO CHANGE DAMAGE RANGE ETC!!!//NEED TO CHANGE DAMAGE RANGE ETC!!!
                {
                    if (Static.GetNumber(100) < 101)//NEED TO CHANGE DAMAGE RANGE ETC!!!//NEED TO CHANGE DAMAGE RANGE ETC!!!//NEED TO CHANGE DAMAGE RANGE ETC!!!
                    {
                        int tmp = Static.GetNumber(4);//NEED TO CHANGE DAMAGE RANGE ETC!!!//NEED TO CHANGE DAMAGE RANGE ETC!!!//NEED TO CHANGE DAMAGE RANGE ETC!!!
                        if (tmp == 0)       //NEED TO CHANGE DAMAGE RANGE ETC!!!//NEED TO CHANGE DAMAGE RANGE ETC!!!//NEED TO CHANGE DAMAGE RANGE ETC!!!
                        {
                            CurrentRoom.WOP = new WeaponOnGround(drumsticksOnGround, weaponOnGroundPosition, new Weapon(Static.GetNumber(100) / 1000 * World.CurrentLevel + 0.001f + 0.002f * World.CurrentLevel, 2f, WeaponType.Drumsticks, note));
                        }
                        if (tmp == 1)
                        {
                            CurrentRoom.WOP = new WeaponOnGround(electricGuitarOnGround, weaponOnGroundPosition, new Weapon(Static.GetNumber(100) / 1000 * World.CurrentLevel + 0.2f + 0.1f * World.CurrentLevel, 3f, WeaponType.ElectricGuitar, note));
                        }
                        if (tmp == 2)
                        {
                            CurrentRoom.WOP = new WeaponOnGround(guitarOnGround, weaponOnGroundPosition, new Weapon(Static.GetNumber(100) / 1000 * World.CurrentLevel + 0.3f + 0.2f * World.CurrentLevel, 1f, WeaponType.Guitar, guitar));
                        }
                        if (tmp == 3)
                        {
                            CurrentRoom.WOP = new WeaponOnGround(triangleOnGround, weaponOnGroundPosition, new Weapon(Static.GetNumber(100) / 1000 * World.CurrentLevel + 0.02f + 0.01f * World.CurrentLevel, 1f, WeaponType.Triangle, null));
                        }
                    }
                }
                monsterCountOld = CurrentRoom.Monsters.Count;
                Vector2 tempPos = p.Position;
                CurrentRoom.Doors.ForEach(d => p.Position = d.Update(elapsed, p.CollisionBox, p.Position, CurrentRoom.Monsters.Count));
                if (tempPos != p.Position) {
                    p.Weapon.hit.ForEach(x => x.Collectable = true);
                    p.Weapon.projectile.ForEach(x => x.Collectable = true);
                }

                if (World.CurrentRoomLocationCode[0] == World.LastRoom[0] && World.CurrentRoomLocationCode[1] == World.LastRoom[1]) {
                    if (p.CollisionBox.Intersects(CurrentRoom.Props[0].CollisionBox)) {
                        if (World.CurrentLevel == 10) {
                            menu.menuType = MenuType.WinMenu;
                        }
                        else {
                            World.CurrentLevel += 1;
                            World.GenerateFloor();
                            World.GenerateRooms(roomGraphic, objects, monsters, Content.Load<Texture2D>("health"), stairway);
                            p.Position = new Vector2(544, 306 + 150);
                        }
                    }
                }

                if (Keyboard.GetState().IsKeyDown(Keys.Y) && p.Dead == true) {
                p.Health = 10;
                World.CurrentLevel = 1;
                World.GenerateFloor();
                World.GenerateRooms(roomGraphic, objects, monsters, Content.Load<Texture2D>("health"), stairway);
                p.Position = new Vector2(544, 306 + 150);
                CurrentRoom.Animations.Add(new TempObject(Content.Load<Texture2D>("SATAN"), p.Position, 1, 5, 5, 200, MathHelper.ToRadians(90)));
                p.Dead = false;
                }
                else if (Keyboard.GetState().IsKeyDown(Keys.N) && p.Dead == true) {
                    p.Health = 10;
                    World.CurrentLevel = 1;
                    World.GenerateFloor();
                    World.GenerateRooms(roomGraphic, objects, monsters, Content.Load<Texture2D>("health"), stairway);
                    p.Position = new Vector2(544, 306 + 150);
                    p.Dead = false;
                    menu.menuType = MenuType.StartMenu;

            }

            msOld = Mouse.GetState();
            oldState = Keyboard.GetState();
                if (p.Health <= 0) {
                p.Dead = true;
                    CurrentRoom.Monsters.Clear();
                }
            }
            else if (menu.menuType == MenuType.WinMenu)
            {
                
                if (musicFinalInstance.State == SoundState.Stopped)
                {
                    musicGameInstance.Stop();
                    musicMenuInstance.Stop();
                    musicFinalInstance.Play();
                }
            }
            else
            {
                if (musicMenuInstance.State == SoundState.Stopped)
                {
                    musicFinalInstance.Stop();
                    musicGameInstance.Stop();
                    musicMenuInstance.Play();
                }
            }
#endregion

            base.Update(gameTime);
        }
Exemple #3
0
        public WeaponOnGround(Texture2D texture, Vector2 position, Weapon containedWeapon) : base(texture, position)
        {

            ContainedWeapon = containedWeapon;
            existing = true;
        }