Esempio n. 1
0
        public virtual void Attack()
        {
            // FLYSPAWN LOOP
            SpawnTimer.UpdateTimer();
            // Every X seconds, spawn some enemies.
            if (SpawnTimer.Test())
            {
                // Spawn 3 flies
                for (int i = 0; i < 3; i++)
                {
                    Level.CurrentRoom.Add(new Fly(new Vector2(Position.X - 25 + (25 * i), Position.Y)));
                }
                // Restart the thing.
                SpawnTimer.ResetToZero();
            }

            // ATTACK LOOP
            AttackTimer.UpdateTimer();
            // Every X seconds, attack the player
            if (AttackTimer.Test())
            {
                // Spawn 3 projectiles
                for (int i = 0; i < 3; i++)
                {
                    Globals.sounds.PlaySoundEffectOnce("EnemyAttack");
                    Level.CurrentRoom.Add(new EnemyAttack(Globals.Vector2ToDegrees(Level.Player.Position - Position) - 25 + (i * 25), Position));
                }
                // Restart the thing.
                AttackTimer.ResetToZero();
            }
        }
Esempio n. 2
0
        public override void Update()
        {
            base.Update();

            timer.UpdateTimer();

            // if your attackcooldown is over, shoot towards the player
            if (timer.Test())
            {
                Globals.sounds.PlaySoundEffectOnce("EnemyAttack");
                Level.CurrentRoom.Add(new EnemyAttack(Globals.Vector2ToDegrees(Level.Player.Position - Position), Position, null, Globals.Vector2ToDegrees(Level.Player.Position - Position), SpriteEffects.None));
                timer.ResetToZero();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// The Update method of a Player. Handles input and "stuff".
        /// </summary>
        public override void Update()
        {
            // if the players HP is 0, thus is dead, change the gamestate to dead
            if (Health <= 0)
            {
                Globals.gamestate = Gamestate.Dead;
            }

            // pressing the P key will pause the game and thus stop updating the game (unpausing in Game1.Update())
            if (Globals.GetKeyUp(Microsoft.Xna.Framework.Input.Keys.P))
            {
                Globals.gamestate = Gamestate.Paused;
            }

            //activating itemeffects on buttonpress for testing
            if (Globals.GetKeyDown(Microsoft.Xna.Framework.Input.Keys.K))
            {
                poopsicle = true;
            }

            //just boomer things
            if (Globals.GetKeyDown(Microsoft.Xna.Framework.Input.Keys.Space) && Level.Player.Bombs > 0)
            {
                //Level.CurrentRoom.Add(new Explosion(Position));
                Level.CurrentRoom.Add(new Bomb(Position));
                Level.Player.Bombs--;

                Globals.sounds.PlaySoundEffect("Sound8");
            }

            //testing items and such
            if (Globals.GetKeyUp(Microsoft.Xna.Framework.Input.Keys.J))
            {
                //Level.CurrentRoom.Add(new Itemstone(new Syringe(Level.CurrentRoom.Position + (Room.Dimensions / 5) * Tile.Size * Globals.Scale),
                //                                               Level.CurrentRoom.Position + (Room.Dimensions / 5) * Tile.Size * Globals.Scale));

                Level.CurrentRoom.Add(new Pot(Level.CurrentRoom.Position + (Room.Dimensions / 5) * Tile.Size * Globals.Scale));
                //Level.Player.Keys += 1;
            }

            //testing environment and enemies
            if (Globals.GetKeyUp(Microsoft.Xna.Framework.Input.Keys.L))
            {
                Level.CurrentRoom.Add(new Flyboss(Level.CurrentRoom.Position + (Room.Dimensions / 3) * Tile.Size * Globals.Scale));
                //Level.CurrentRoom.Add(new Itemstone(new Heart(Level.CurrentRoom.Position + (Room.Dimensions / 3) * Tile.Size * Globals.Scale),
                //                                               Level.CurrentRoom.Position + (Room.Dimensions / 3) * Tile.Size * Globals.Scale));
            }



            // effect used, when the player picks up the Poopsicle item. Spawn 3 flies, that are orbiting around you.
            if (poopsicle)
            {
                Companions.Add(new Flybuddy(new Vector2(Position.X, Position.Y + 55), 0));
                Companions.Add(new Flybuddy(new Vector2(Position.X + 40, Position.Y - 40)));
                Companions.Add(new Flybuddy(new Vector2(Position.X - 40, Position.Y - 40)));
                poopsicle = false;
            }

            // Handle movement input.
            // The movement speed.
            //ushort speed = 350;
            // The velocity.
            _velocity = Vector2.Zero;
            // Up.
            if (Globals.GetKey(Microsoft.Xna.Framework.Input.Keys.W))
            {
                // Play the movement sound.
                //Globals.sounds.PlaySoundEffectOnce("Sound3");
                // Move it up.
                _velocity += -Vector2.UnitY * speed;

                // If there's a top door.
                if (Level.CurrentRoom.Doors[(byte)Directions.Up] != null)
                {
                    // If it touches the top door, it's hidden and the player has more than 0 keys.
                    if (!(Level.CurrentRoom.Doors[(byte)Directions.Up].Kind == DoorKind.Hidden) &&
                        (BumpsInto(Level.CurrentRoom.Doors[(byte)Directions.Up]) &&
                         Math.Abs(Level.CurrentRoom.Doors[(byte)Directions.Up].Position.X - Position.X) <= Door.Width * Scale.X) &&
                        Level.CurrentRoom.Doors[(byte)Directions.Up].State == DoorState.Locked &&
                        Keys > 0)
                    {
                        // The player uses a key.
                        Keys--;
                        // Unlock the door.
                        Level.CurrentRoom.Doors[(byte)Directions.Up].Unlock(true);
                    }
                }
            }
            // Right.
            if (Globals.GetKey(Microsoft.Xna.Framework.Input.Keys.D))
            {
                // Play the movement sound.
                //Globals.sounds.PlaySoundEffectOnce("Sound2");
                // Move it right.
                _velocity += Vector2.UnitX * speed;

                // If there's a right door.
                if (Level.CurrentRoom.Doors[(byte)Directions.Right] != null)
                {
                    // If it touches the right door, it's hidden and the player has more than 0 keys.
                    if (!(Level.CurrentRoom.Doors[(byte)Directions.Right].Kind == DoorKind.Hidden) &&
                        (BumpsInto(Level.CurrentRoom.Doors[(byte)Directions.Right]) &&
                         Math.Abs(Level.CurrentRoom.Doors[(byte)Directions.Right].Position.Y - Position.Y) <= Door.Width * Scale.Y) &&
                        Level.CurrentRoom.Doors[(byte)Directions.Right].State == DoorState.Locked &&
                        Keys > 0)
                    {
                        // The player uses a key.
                        Keys--;
                        // Unlock the door.
                        Level.CurrentRoom.Doors[(byte)Directions.Right].Unlock(true);
                    }
                }
            }
            // Down.
            if (Globals.GetKey(Microsoft.Xna.Framework.Input.Keys.S))
            {
                // Play the movement sound.
                //Globals.sounds.PlaySoundEffectOnce("Sound4");
                // Move it down.
                _velocity += Vector2.UnitY * speed;

                // If there's a bottom door.
                if (Level.CurrentRoom.Doors[(byte)Directions.Down] != null)
                {
                    // If it touches the bottom door, it's hidden and the player has more than 0 keys.
                    if (!(Level.CurrentRoom.Doors[(byte)Directions.Down].Kind == DoorKind.Hidden) &&
                        (BumpsInto(Level.CurrentRoom.Doors[(byte)Directions.Down]) &&
                         Math.Abs(Level.CurrentRoom.Doors[(byte)Directions.Down].Position.X - Position.X) <= Door.Width * Scale.X) &&
                        Level.CurrentRoom.Doors[(byte)Directions.Down].State == DoorState.Locked &&
                        Keys > 0)
                    {
                        // The player uses a key.
                        Keys--;
                        // Unlock the door.
                        Level.CurrentRoom.Doors[(byte)Directions.Down].Unlock(true);
                    }
                }
            }
            // Left.
            if (Globals.GetKey(Microsoft.Xna.Framework.Input.Keys.A))
            {
                // Play the movement sound.
                //Globals.sounds.PlaySoundEffectOnce("Sound1");
                // Move it left.
                _velocity += -Vector2.UnitX * speed;

                // If there's a left door.
                if (Level.CurrentRoom.Doors[(byte)Directions.Left] != null)
                {
                    // If it touches the left door, it's hidden and the player has more than 0 keys.
                    if (!(Level.CurrentRoom.Doors[(byte)Directions.Left].Kind == DoorKind.Hidden) &&
                        (BumpsInto(Level.CurrentRoom.Doors[(byte)Directions.Left]) &&
                         Math.Abs(Level.CurrentRoom.Doors[(byte)Directions.Left].Position.Y - Position.Y) <= Door.Width * Scale.Y) &&
                        Level.CurrentRoom.Doors[(byte)Directions.Left].State == DoorState.Locked &&
                        Keys > 0)
                    {
                        // The player uses a key.
                        Keys--;
                        // Unlock the door.
                        Level.CurrentRoom.Doors[(byte)Directions.Left].Unlock(true);
                    }
                }
            }
            // Choose the proper animation.
            if (Math.Abs(_velocity.X) > Math.Abs(_velocity.Y))
            {
                // If it moves left.
                if (_velocity.X < 0)
                {
                    CurrentAnimation = _walkingAnimations[3];
                }
                // Else it moves right.
                else
                {
                    CurrentAnimation = _walkingAnimations[1];
                }
            }
            // Else it moves up, down or diagonally.
            else
            {
                // If it moves up.
                if (_velocity.Y < 0)
                {
                    CurrentAnimation = _walkingAnimations[0];
                }
                // Else it moves down.
                else if (_velocity.Y > 0)
                {
                    CurrentAnimation = _walkingAnimations[2];
                }
            }
            // Move it.
            if (_velocity != Vector2.Zero)
            {
                //Globals.sounds.PlaySoundEffectOnce("Sound4");
                // Play the walking sound effect.
                if (_walkingSound.State != SoundState.Playing)
                {
                    _walkingSound.Play();
                }
                CurrentAnimation.Resume();
                _velocity = Globals.DegreesToVector2(Globals.Vector2ToDegrees(_velocity)) * speed;
                Move(_velocity);
            }
            else
            {
                CurrentAnimation.Pause();
                CurrentAnimation.SelectFrame(0);
            }


            // handle combat inputs

            damageImunity.UpdateTimer();
            timer.UpdateTimer();
            // up
            if (Globals.GetKey(Microsoft.Xna.Framework.Input.Keys.Up) && timer.Test())
            {
                Globals.sounds.PlaySoundEffect("Attack1");
                Level.CurrentRoom.Add(new BasicAttack(0 - 90, Position));
                timer.ResetToZero();
            }
            // right
            if (Globals.GetKey(Microsoft.Xna.Framework.Input.Keys.Right) && timer.Test())
            {
                Globals.sounds.PlaySoundEffect("Attack1");
                Level.CurrentRoom.Add(new BasicAttack(90 - 90, Position));
                timer.ResetToZero();
            }
            // down
            if (Globals.GetKey(Microsoft.Xna.Framework.Input.Keys.Down) && timer.Test())
            {
                Globals.sounds.PlaySoundEffect("Attack1");
                Level.CurrentRoom.Add(new BasicAttack(180 - 90, Position));
                timer.ResetToZero();
            }
            // left
            if (Globals.GetKey(Microsoft.Xna.Framework.Input.Keys.Left) && timer.Test())
            {
                Globals.sounds.PlaySoundEffect("Attack1");
                Level.CurrentRoom.Add(new BasicAttack(270 - 90, Position));
                timer.ResetToZero();
            }

            // Draw the list of companions
            for (int i = 0; i < Companions.Count; i++)
            {
                Companions[i].Update();
                if (Companions[i].isDestroyed)
                {
                    Companions.RemoveAt(i);
                }
            }

            // Update the Player's layer and stuff.
            base.Update();
        }