Ejemplo 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();
            }
        }
Ejemplo n.º 2
0
        public override void Update()
        {
            // after the time of 1.5 seconds
            timer.UpdateTimer();

            // spawn an explosion and remove this object
            if (timer.Test())
            {
                Level.CurrentRoom.Add(new Explosion(Position));
                Level.CurrentRoom.Remove(this);
            }

            base.Update();
        }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
0
        public override void Update()
        {
            /*
             * Update(Level.CurrentRoom.Enemies);
             * base.Update();
             */
            timer.UpdateTimer();
            ChangePosition();
            if (timer.Test())
            {
                Level.CurrentRoom.Remove(this);
            }
            if (HitWall())
            {
                Level.CurrentRoom.Remove(this);
            }
            if (Collides(Level.Player) && (OwnerID == 2 || OwnerID == 0))
            {
                Level.Player.GetHit(HitValue);
                Level.CurrentRoom.Remove(this);
            }

            /*
             * for (int i = 0; i < Level.CurrentRoom.Enemies.Count; i++)
             * {
             *  if (Collides(Level.CurrentRoom.Enemies) && (OwnerID == 1 || OwnerID == 0))
             *  {
             *      Level.CurrentRoom.Enemies[i].GetHit(HitValue);
             *      //Level.CurrentRoom.Enemies.ElementAt<Enemy>(i).GetHit(HitValue);
             *      Level.CurrentRoom.Remove(this);
             *  }
             * }
             */
            if (Collides(Level.CurrentRoom.Enemies) && (OwnerID == 1 || OwnerID == 0))
            {
                bool isColliding = false;//NEW
                for (int i = 0; i < Level.CurrentRoom.Enemies.Count; i++)
                {
                    if (Collides(Level.CurrentRoom.Enemies[i]) &&//NEW
                        OwnerID == 1)
                    {
                        //enemies[i].GetHit(HitValue);
                        Level.CurrentRoom.Enemies[i].GetHit(HitValue);
                        /*Level.CurrentRoom.Remove(this);*/
                        isColliding = true;
                    }
                }
                //NEW
                if (isColliding)
                {
                    Level.CurrentRoom.Remove(this);
                }
            }
            if (Collides(Level.CurrentRoom.Entities))
            {
                for (int i = 0; i < Level.CurrentRoom.Entities.Count; i++)
                {
                    if (Collides(Level.CurrentRoom.Entities[i]) &&
                        (Level.CurrentRoom.Entities[i].GetType().Name == "Poop") ||
                        Level.CurrentRoom.Entities[i].GetType().Name == "Campfire")
                    {
                        Level.CurrentRoom.Entities[i].GetHit(HitValue);
                        Level.CurrentRoom.Remove(this);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public override void Update()
        {
            if (!SoundHasPlayed)
            {
                Globals.sounds.PlaySoundEffect("Sound6");
                SoundHasPlayed = true;
            }


            // Unlocking / opening doors.
            // Top.
            if ((Level.CurrentRoom.Doors[(byte)Directions.Up] != null &&
                 (Position - Level.CurrentRoom.Doors[(byte)Directions.Up].Position).Length() <= (BlastRadius * Tile.Size.X)))
            {
                // If the door is closed.
                if (Level.CurrentRoom.Doors[(byte)Directions.Up].State == DoorState.Closed)
                {
                    // Open the door.
                    Level.CurrentRoom.Doors[(byte)Directions.Up].Open();
                }
                // Else if the door is hidden and locked.
                else if (Level.CurrentRoom.Doors[(byte)Directions.Up].Kind == DoorKind.Hidden &&
                         Level.CurrentRoom.Doors[(byte)Directions.Up].State == DoorState.Locked)
                {
                    // Unlock the door.
                    Level.CurrentRoom.Doors[(byte)Directions.Up].Unlock(true);
                }
            }
            // Right.
            if ((Level.CurrentRoom.Doors[(byte)Directions.Right] != null &&
                 (Position - Level.CurrentRoom.Doors[(byte)Directions.Right].Position).Length() <= (BlastRadius * Tile.Size.X)))
            {
                // If the door is closed.
                if (Level.CurrentRoom.Doors[(byte)Directions.Right].State == DoorState.Closed)
                {
                    // Open the door.
                    Level.CurrentRoom.Doors[(byte)Directions.Right].Open();
                }
                // Else if the door is hidden and locked.
                else if (Level.CurrentRoom.Doors[(byte)Directions.Right].Kind == DoorKind.Hidden &&
                         Level.CurrentRoom.Doors[(byte)Directions.Right].State == DoorState.Locked)
                {
                    // Unlock the door.
                    Level.CurrentRoom.Doors[(byte)Directions.Right].Unlock(true);
                }
            }
            // Bottom.
            if ((Level.CurrentRoom.Doors[(byte)Directions.Down] != null &&
                 (Position - Level.CurrentRoom.Doors[(byte)Directions.Down].Position).Length() <= (BlastRadius * Tile.Size.X)))
            {
                // If the door is closed.
                if (Level.CurrentRoom.Doors[(byte)Directions.Down].State == DoorState.Closed)
                {
                    // Open the door.
                    Level.CurrentRoom.Doors[(byte)Directions.Down].Open();
                }
                // Else if the door is hidden and locked.
                else if (Level.CurrentRoom.Doors[(byte)Directions.Down].Kind == DoorKind.Hidden &&
                         Level.CurrentRoom.Doors[(byte)Directions.Down].State == DoorState.Locked)
                {
                    // Unlock the door.
                    Level.CurrentRoom.Doors[(byte)Directions.Down].Unlock(true);
                }
            }
            // Left.
            if ((Level.CurrentRoom.Doors[(byte)Directions.Left] != null &&
                 (Position - Level.CurrentRoom.Doors[(byte)Directions.Left].Position).Length() <= (BlastRadius * Tile.Size.X)))
            {
                // If the door is closed.
                if (Level.CurrentRoom.Doors[(byte)Directions.Left].State == DoorState.Closed)
                {
                    // Open the door.
                    Level.CurrentRoom.Doors[(byte)Directions.Left].Open();
                }
                // Else if the door is hidden and locked.
                else if (Level.CurrentRoom.Doors[(byte)Directions.Left].Kind == DoorKind.Hidden &&
                         Level.CurrentRoom.Doors[(byte)Directions.Left].State == DoorState.Locked)
                {
                    // Unlock the door.
                    Level.CurrentRoom.Doors[(byte)Directions.Left].Unlock(true);
                }
            }

            timer.UpdateTimer();


            // Deal Damage to any entity, that is not the player
            //if (Collides(Level.CurrentRoom.Entities) && (OwnerID == 1 || OwnerID == 0))
            //{
            //bool isColliding = false;//NEW
            for (int i = 0; i < Level.CurrentRoom.Entities.Count; i++)
            {
                //if (Collides(Level.CurrentRoom.Entities[i])//NEW
                if (Globals.GetDistance(this.Position, Level.CurrentRoom.Entities[i].Position) <= (BlastRadius * Tile.Size.X) &&
                    OwnerID == 0 &&
                    (Level.CurrentRoom.Entities[i].GetType().IsSubclassOf(typeof(Environment)) ||
                     Level.CurrentRoom.Entities[i].GetType().IsSubclassOf(typeof(Enemy)) ||
                     Level.CurrentRoom.Entities[i].GetType().Name == "Campfire") &&
                    Level.CurrentRoom.Entities[i].damageDealt == false)
                {
                    //enemies[i].GetHit(HitValue);
                    Level.CurrentRoom.Entities[i].damageDealt = false;
                    Level.CurrentRoom.Entities[i].GetHit(HitValue);
                    Level.CurrentRoom.Entities[i].damageDealt = true;
                    /*Level.CurrentRoom.Remove(this);*/
                    //isColliding = true;
                }
            }
            //NEW
            //if (isColliding)
            //{
            //    Level.CurrentRoom.Remove(this);
            //}
            //}


            // Deal damage to the player
            //if (Collides(Level.Player))
            if (Globals.GetDistance(this.Position, Level.Player.Position) <= (BlastRadius * Tile.Size.X))
            {
                Level.Player.GetHit(HitValue);
            }
            if (timer.Test())
            {
                Level.CurrentRoom.Remove(this);
            }
        }