private static Vector2 GetCenterOfRectangle(Creature creature)
        {
            float x = (creature.TopLeftX + creature.Image.Width) / 2;
            float y = (creature.TopLeftY + creature.Image.Height) / 2;

            return new Vector2(x, y);
        }
Exemplo n.º 2
0
        public virtual void Attack(Creature enemy)
        {
            enemy.CurrentFocus = Math.Max(0,enemy.CurrentFocus - this.CurrentFocus);
            enemy.CurrentEnergy = Math.Max(0,enemy.CurrentEnergy - this.CurrentEnergy);

            if (enemy.CurrentFocus <= 0 || enemy.CurrentEnergy <= 0)
            {
                enemy.IsAlive = false;
            }
        }
Exemplo n.º 3
0
        public static void DrawTarget(Creature creature, SpriteBatch spriteBatch, ContentManager content, Vector2 mapPosition)
        {
            const int targetImageWidth = 15;
            const int offsetY = 28;

            float topLeftX = creature.TopLeftX + mapPosition.X + (creature.Image.Width / 2 - targetImageWidth / 2 + 2);
            float topLeftY = creature.TopLeftY + mapPosition.Y - offsetY;

            spriteBatch.Draw(content.Load<Texture2D>("CharacterTextures/target"), new Vector2(topLeftX, topLeftY));
        }
        public static double GetDistanceBetweenObjects(Player player, Creature creature, Vector2 mapPosition)
        {
            Vector2 playerPoint = GetCenterOfRectangle(player);
            Vector2 creaturePoint = GetCenterOfRectangle(creature);

            double a = (double)((creaturePoint.X + mapPosition.X/2) - playerPoint.X);
            double b = (double)((creaturePoint.Y + mapPosition.Y/2) - playerPoint.Y);

            return Math.Sqrt(a * a + b * b);
        }
Exemplo n.º 5
0
        public override void Attack(Creature enemy)
        {
            base.Attack(enemy);

            this.Experience += enemy.ExperienceToGive;

            if (this.Experience >= this.levelUpExperience)
            {
                LevelUp();
            }
        }
Exemplo n.º 6
0
        public static void DrawFocusBar(Creature creature, int barOffSet, SpriteBatch spriteBatch, ContentManager content, Vector2 mapPosition)
        {
            spriteBatch.Draw(content.Load<Texture2D>("GUI/statbar"), new Vector2(creature.TopLeftX + mapPosition.X, creature.TopLeftY - barOffSet + mapPosition.Y));

            double percentageFull = ((double)creature.CurrentFocus / creature.TotalFocus) * FullBarWidth;

            for (int i = 0; i < percentageFull; i++)
            {
                spriteBatch.Draw(content.Load<Texture2D>("GUI/focus-filler"),
                    new Vector2((creature.TopLeftX + 1 + i) + mapPosition.X,
                                (creature.TopLeftY - (barOffSet - 1)) + mapPosition.Y));
            }
        }
Exemplo n.º 7
0
        private void CheckIfCreatureIsAlive(Creature creature)
        {
            if (!creature.IsAlive)
            {
                new Thread(() => killEnemy.Play()).Start();

                int hashcodeOfKilledCreature = creature.GetHashCode();
                this.map.RemoveMapCreatureByHashCode(hashcodeOfKilledCreature);
            }
        }
Exemplo n.º 8
0
        protected override void Update(GameTime gameTime)
        {
            if (this.isInMainMenu)
            {
                foreach (var button in mainMenu.Buttons)
                {
                    if (button.ButtonRect.Contains(new Point(Mouse.GetState().X, Mouse.GetState().Y)) &&
                        Mouse.GetState().LeftButton == ButtonState.Pressed)
                    {
                        button.FireClick();
                    }
                }

                if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                {
                    isKeyDownEscape = true;
                }

                if (Keyboard.GetState().IsKeyUp(Keys.Escape) && isKeyDownEscape)
                {
                    isInMainMenu = false;

                    isKeyDownEscape = false;
                }
            }
            else
            {
                if (player.IsAlive && map.MapCreatures.Any(cr => cr is ExamBoss))
                {
                    //TODO: Player gets stuck with objects in some pixels?
                    this.CheckForPlayerMovementInput();

                    #region CheckForCollisionWithItem

                    int hashcodeOfCollidedItem;
                    bool hasCollisionWithItem = CollisionDetector.HasCollisionWithItem(player, map, mapPosition,
                        out hashcodeOfCollidedItem);

                    if (hasCollisionWithItem)
                    {
                        Item collidedItem = map.MapItems.Single(x => x.GetHashCode() == hashcodeOfCollidedItem);
                        player.AddItemToInventory(collidedItem);

                        this.map.RemoveMapItemByHashCode(hashcodeOfCollidedItem);

                        new Thread(() => getItemSound.Play()).Start();
                    }

                    #endregion

                    this.closestCreature = DistanceCalculator.GetClosestCreature(map, player, mapPosition);

                    this.CheckForPlayerAttack();

                    this.CheckForItemShortcutPressed();
                }

                if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                {
                    this.isKeyDownEscape = true;
                }

                if (Keyboard.GetState().IsKeyUp(Keys.Escape) && isKeyDownEscape)
                {
                    this.isInMainMenu = true;

                    this.isKeyDownEscape = false;
                }
            }

            base.Update(gameTime);
        }
Exemplo n.º 9
0
 public void AddCreature(Creature creatureToAdd)
 {
     this.MapCreatures.Add(creatureToAdd);
 }