Ejemplo n.º 1
0
 public void Update(KeyboardState state, Tile[][] tiles)
 {
     if (pickUpCounter > 0)
     {
         pickUpCounter--;
         if (pickUpCounter == 0)
         {
             CanBePickedUp = true;
         }
     }
     if (isFalling)
     {
         newLocation.Y += verticalVelocity;
         newLocation.X += horizontalVelocity;
         verticalVelocity++;
         Collisions.CollideWithTiles(tiles, this);
         location = newLocation;
         hitBox   = new Rectangle((int)location.X, (int)location.Y, width, height);
     }
     else
     {
         yOffsetCounter++;
         if (yOffsetCounter > 5)
         {
             yOffsetCounter  = 0;
             currentYOffset += yOffsetDirection;
             if (currentYOffset > 1 || currentYOffset < -5)
             {
                 yOffsetDirection *= -1;
             }
         }
     }
 }
Ejemplo n.º 2
0
 public void Update(Tile[][] tiles)
 {
     newLocation    = location;
     newLocation.X += horizontalVelocity;
     if (Collisions.CollideWithTiles(tiles, this))
     {
         owner.RemoveProjectile(this);
     }
     location = newLocation;
     hitBox   = new Rectangle((int)location.X, (int)location.Y, width, height);
 }
Ejemplo n.º 3
0
        virtual public void Update(Player player, Tile[][] tiles)
        {
            Collisions.CollideWithTiles(tiles, this);
            location = newLocation;
            hitBox   = new Rectangle((int)location.X, (int)location.Y, width, height);

            if (state == "hurt")
            {
                hurtCounter--;
                if (hurtCounter <= 0)
                {
                    hurtCounter = 0;
                    state       = "normal";
                }
            }
            else if (player.swordIsActive && Collisions.EntityCollisions(player.swordHitBox, hitBox))
            {
                GetHit(player, player.swingFacing);
                player.swordIsActive = false;
            }
            else
            {
                foreach (Projectile projectile in player.Projectiles)
                {
                    if (Collisions.EntityCollisions(projectile.hitBox, hitBox))
                    {
                        string direction = "left";
                        if (projectile.horizontalVelocity > 0)
                        {
                            direction = "right";
                        }
                        GetHit(player, direction);
                        player.RemoveProjectile(projectile);
                        break;
                    }
                }
            }

            if (!player.invulnerable && Collisions.EntityCollisions(player.hitBox, hitBox))
            {
                player.GetHit("left", GetDamage());
            }
        }
Ejemplo n.º 4
0
        public void Update(KeyboardState keyboardState, Tile[][] tiles, MouseState mouseState)
        {
            newLocation = location;

            if (invulnerableTimer > 0)
            {
                invulnerableTimer--;
                if (this.state == "hurt" && invulnerableTimer < 80)
                {
                    this.state = "invulnerable";
                }
                if (invulnerableTimer == 0)
                {
                    invulnerable = false;
                    this.state   = "normal";
                }
            }

            if (!previousKeyboardState.IsKeyDown(Keys.OemComma) && keyboardState.IsKeyDown(Keys.OemComma))
            {
                if (inventory.RemoveFromInventory(new InventoryItem(new Items.HealthPotion(1), new Vector2(0, 0))))
                {
                    health += 50;
                    if (health > maxHealth)
                    {
                        health = maxHealth;
                    }
                }
            }
            if (!previousKeyboardState.IsKeyDown(Keys.OemPeriod) && keyboardState.IsKeyDown(Keys.OemPeriod))
            {
                if (inventory.RemoveFromInventory(new InventoryItem(new Items.ManaPotion(1), new Vector2(0, 0))))
                {
                    mana = maxMana;
                }
            }
            if (!previousKeyboardState.IsKeyDown(Keys.I) && keyboardState.IsKeyDown(Keys.I))
            {
                Game1.ToggleMenu(inventory);
            }
            if (!previousKeyboardState.IsKeyDown(Keys.O) && keyboardState.IsKeyDown(Keys.O))
            {
                Game1.ToggleMenu(equipmentMenu);
            }
            if (!(keyboardState.IsKeyDown(Keys.A) ^ keyboardState.IsKeyDown(Keys.D))) // if both or neither are pressed
            {
                textureChangeCounter = 5;
                currentTextureState  = 1;
            }
            else
            {
                if (textureChangeCounter <= 0)
                {
                    currentTextureState++;
                    if (currentTextureState > 2)
                    {
                        currentTextureState = 0;
                    }
                    textureChangeCounter = 5;
                }
                if (keyboardState.IsKeyDown(Keys.A))
                {
                    if (previousKeyboardState.IsKeyDown(Keys.A) && !isFalling)
                    {
                        textureChangeCounter--;
                    }
                    newLocation.X -= 4;
                    facing         = "left";
                }
                if (keyboardState.IsKeyDown(Keys.D))
                {
                    if (previousKeyboardState.IsKeyDown(Keys.D) && !isFalling)
                    {
                        textureChangeCounter--;
                    }
                    newLocation.X += 4;
                    facing         = "right";
                }
            }

            if (keyboardState.IsKeyDown(Keys.LeftControl))
            {
                Console.WriteLine(location.X + ", " + location.Y);
            }
            if (keyboardState.IsKeyDown(Keys.Space) && !isFalling)
            {
                isFalling        = true;
                verticalVelocity = -20;
            }

            if (projectileCooldown > 0)
            {
                projectileCooldown--;
            }
            if (keyboardState.IsKeyDown(Keys.J) && projectileCooldown == 0 && mana >= 25)
            {
                if (swingFacing == "right")
                {
                    Projectiles.Add(new Projectile(new Vector2(location.X + (width / 2) - (30 / 2), location.Y + (height / 2) - (30 / 2)),
                                                   projectileTexture, 10, currentLocation, this));
                }
                else if (swingFacing == "left")
                {
                    Projectiles.Add(new Projectile(new Vector2(location.X + (width / 2) - (30 / 2), location.Y + (height / 2) - (30 / 2)),
                                                   projectileTexture, -10, currentLocation, this));
                }
                projectileCooldown = 60;
                mana -= 25;
            }
            if (keyboardState.IsKeyDown(Keys.F) && !previousKeyboardState.IsKeyDown(Keys.F) && equipmentMenu.GetEquippedItem() != null && swinging == false)
            {
                if (equipmentMenu.GetEquippedItem().GetItem().GetType() == typeof(Items.SwordItem))
                {
                    swinging      = true;
                    swingFacing   = facing;
                    swordIsActive = true;
                }
                else if (equipmentMenu.GetEquippedItem().GetItem().GetType() == typeof(Items.ScytheItem))
                {
                    swinging       = true;
                    swingFacing    = facing;
                    scytheIsActive = true;
                }
            }


            if (!swinging)
            {
                swingFacing = facing;
            }
            if (swinging)
            {
                swordTextureChangeCounter--;
                if (swordTextureChangeCounter < 0)
                {
                    swordTextureChangeCounter = 5;
                    currentSwordTextureState++;
                    if (currentSwordTextureState >= 2)
                    {
                        swinging                 = false;
                        scytheIsActive           = false;
                        swordIsActive            = false;
                        currentSwordTextureState = 0;
                    }
                }
            }

            if (isFalling)
            {
                newLocation.Y += verticalVelocity;
                verticalVelocity++;
            }

            newHitBox = new Rectangle((int)newLocation.X, (int)newLocation.Y, width, height);
            Collisions.CollideWithTiles(tiles, this);
            location = newLocation;
            hitBox   = newHitBox;
            if (facing == "left")
            {
                swordHitBox = new Rectangle((int)location.X - swordOffset, (int)location.Y, swordOffset, height);
            }
            else if (facing == "right")
            {
                swordHitBox = new Rectangle((int)location.X + width, (int)location.Y, swordOffset, height);
            }

            if (keyboardState.IsKeyDown(Keys.E) && !previousKeyboardState.IsKeyDown(Keys.E))
            {
                foreach (Portal portal in currentLocation.GetPortals())
                {
                    if (Collisions.EntityCollisions(hitBox, portal.hitBox))
                    {
                        Travel(portal.GetDestination(), portal.GetPositionDestination());
                    }
                }
            }

            if (manaRegenCooldown > 0)
            {
                manaRegenCooldown--;
            }
            if (manaRegenCooldown == 0 && (mana < maxMana))
            {
                mana++;
                manaRegenCooldown = 10;
            }

            for (int i = Projectiles.Count - 1; i >= 0; i--) // some elements may be removed, so iterate backwards.
            {
                Projectiles[i].Update(tiles);
            }

            previousKeyboardState = keyboardState;
        }