Esempio n. 1
0
        public void ThrowObject()
        {
            Sprite originalSprite = HoldedSprite;

            Rectangle originalSpriteCore = originalSprite.core;
            Vector2   newPosition        = MovementManager.GetRectNextTo(originalSpriteCore, bounds, direction);

            originalSpriteCore.X = (int)newPosition.X;
            originalSpriteCore.Y = (int)newPosition.Y;

            newPosition               = MovementManager.MoveVector(new Vector2(originalSpriteCore.X, originalSpriteCore.Y), Tile.size, direction);
            originalSpriteCore.X      = (int)newPosition.X;
            originalSpriteCore.Y      = (int)newPosition.Y;
            originalSprite.canCollide = true;
            HoldedSprite.MapDepth     = Game.MapDepth.player;
            bool passable = originalSprite.passable;

            originalSprite.passable = false;
            if (!movementManager.CollisionCheck(originalSprite, originalSpriteCore) && movementManager.InsideMap(originalSprite, originalSpriteCore))
            {
                DiscardObject();

                originalSprite.position.X = originalSpriteCore.X;
                originalSprite.position.Y = originalSpriteCore.Y;
                map.AddObject(originalSprite);
            }
            originalSprite.passable = passable;
        }
Esempio n. 2
0
 private void Jump()
 {
     if (!jumping)
     {
         int VectorMoveTo = 0;
         if (direction == MovementManager.Direction.down || direction == MovementManager.Direction.up)
         {
             VectorMoveTo = maxJumpingHeight;
         }
         if (direction == MovementManager.Direction.right || direction == MovementManager.Direction.left)
         {
             VectorMoveTo = maxJumpingWidth;
         }
         Rectangle collisionRect   = core;
         Vector2   collisionVector = MovementManager.MoveVector(position, VectorMoveTo, direction); //TODO: something is wrong here. i can smell it
         collisionRect.X = (int)collisionVector.X;
         collisionRect.Y = (int)collisionVector.Y;
         if (!movementManager.CollisionCheck(this, collisionRect))
         {
             Game.content.Load <SoundEffect>("Audio\\Waves\\fart").Play();
             originalJumpingPosition = position;
             canCollide = false;
             passable   = true;
             jumping    = true;
             return;
         }
     }
 }
Esempio n. 3
0
        public Map(TileMap tileMap, string name)
        {
            this.tileMap = tileMap;
            this.name    = name;

            movementManager = new MovementManager(this);

            //add collision objects in tileMap
            tileMap.AddCollisionObjects(this);
        }
Esempio n. 4
0
        public Mine(Player source, int strength, Sprite sprite)
            : base(sprite.texture, sprite.position, sprite.drawingCoordinates)
        {
            this.source   = source;
            this.strength = strength;

            MapDepth = Game.MapDepth.below;

            collisionFunction = Mine.UpdateMineCollision;
            canCollide        = false;
            position          = MovementManager.GetRectNextTo(bounds, source.bounds, source.direction);
            //position = MovementManager.MoveVector(position, Tile.size * 2, source.direction);
        }
Esempio n. 5
0
 private void NpcInteraction(Player player, GameObject interactedWith)
 {
     if (player.canInteract())
     {
         if (player.Shop(npc))
         {
             movementManager.TurnSpritesheet(npc, MovementManager.OppositeDirection(player.direction));
             //movementManager.Knockback(player, MovementManager.Direction.left, 100);
             //player.MessageWindow(npc2.bounds, new List<string> {"the great king wants to see you. \n no, he dosent.", "asd"}, true);
             //player.MessageWindow(npc2.bounds, "the king wants to see you. \n no, he dosent.", true);
         }
     }
 }
Esempio n. 6
0
        public Projectile(Texture2D texture, float speed, Player source, int pathDestination, int strength, SoundEffect launchSound, SoundEffect hitSound)
            : base(texture, new Vector2())
        {
            this.source          = source;
            this.pathDestination = pathDestination;
            this.launchSound     = launchSound;
            this.hitSound        = hitSound;
            this.speed           = speed;
            this.strength        = strength;
            this.direction       = source.direction;

            Vector2 result = MovementManager.GetRectNextTo(bounds, source.bounds, source.direction);

            position = result;

            if (launchSound != null)
            {
                launchSound.Play();
            }
        }
Esempio n. 7
0
        private bool Interact()
        {
            Rectangle interactRect = new Rectangle(0, 0, Tile.size, Tile.size);
            Vector2   result       = MovementManager.GetRectNextTo(interactRect, bounds, direction);

            interactRect.X = (int)result.X;
            interactRect.Y = (int)result.Y;

            foreach (GameObject gameObject in map.gameObjectList)
            {
                if (camera.InCamera(gameObject))
                {
                    if (interactRect.Intersects(gameObject.core) && gameObject.interactFunction != null)
                    {
                        gameObject.interactFunction(this, gameObject);
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 8
0
        public override void Attack(Map map, Player player)
        {
            base.Attack(map, player);

            //attack
            Rectangle rangeRect     = new Rectangle(0, 0, (int)(Tile.size * range), (int)(Tile.size * range));
            Vector2   rangePosition = MovementManager.GetRectNextTo(rangeRect, player.bounds, player.direction);

            rangeRect.X = (int)rangePosition.X;
            rangeRect.Y = (int)rangePosition.Y;

            bool hit = false;

            foreach (GameObject gameObject in player.map.gameObjectList)
            {
                if (player.camera.InCamera(gameObject))
                {
                    Enemy enemy = gameObject as Enemy;
                    if (enemy != null)
                    {
                        if (rangeRect.Intersects(enemy.core))
                        {
                            enemy.DealDamage(player);
                            hit = true;
                        }
                    }
                }
            }

            if (hit)
            {
                attackSound.Play();
            }
            else
            {
                swingSound.Play();
            }
        }
Esempio n. 9
0
        public void DealDamage(Hostile source, bool sourceDamage = true, int damage = 0, bool showDamage = true)
        {
            if (cooldownTimer.result || cooldownTimer.counter == 0)
            {
                //set new health
                bool   noDamage     = false;
                bool   defending    = false;
                int    oldHealth    = stats.health;
                int    newHealth    = stats.health;
                Player thisAsPlayer = this as Player;
                if (thisAsPlayer != null)
                {
                    if (thisAsPlayer.defendingTimer.Counting)
                    {
                        defending = true;
                    }
                    else
                    {
                        if (damage == 0) // new health by stats
                        {
                            newHealth += stats.defence - source.stats.strength;
                        }
                        if (!sourceDamage) //new health by number
                        {
                            newHealth += stats.defence - damage;
                        }
                    }
                }
                else
                {
                    if (damage == 0) // new health by stats
                    {
                        newHealth += stats.defence - source.stats.strength;
                    }
                    if (!sourceDamage) //new health by number
                    {
                        newHealth += stats.defence - damage;
                    }
                }

                //limit damage to more than zero
                if (oldHealth - newHealth > -1)
                {
                    // limit health to zero
                    if (newHealth > 0)
                    {
                        stats.health = newHealth;
                    }
                    else
                    {
                        stats.health = 0;
                        Player sourceAsPlayer = source as Player;
                        if (sourceAsPlayer != null)
                        {
                            sourceAsPlayer.AddExp(stats.exp);
                        }
                        fade = true;
                        Kill();
                    }
                }
                else
                {
                    noDamage = true;
                }

                //knockback
                MovementManager.Knockback(this, source.direction, source.stats.knockback);

                //durability
                for (int counter = 0; counter < equipmentList.Count; counter++)
                {
                    Armor armor = equipmentList[counter];
                    if (armor.armorType != Armor.ArmorType.oneHanded && armor.armorType != Armor.ArmorType.twoHanded)
                    {
                        armor.Durability--;
                    }
                }

                //update player hud and menu
                if (thisAsPlayer != null)
                {
                    thisAsPlayer.HandleHit(oldHealth - newHealth);
                }

                //timer
                cooldownTimer.Reset();

                //show damage
                if (showDamage)
                {
                    string text;
                    Color  color;
                    if (defending)
                    {
                        text  = "Defending";
                        color = Color.DimGray;
                    }
                    else if (noDamage)
                    {
                        text  = "0";
                        color = Color.DimGray;
                    }
                    else
                    {
                        text  = "" + (oldHealth - newHealth);
                        color = Color.Red;
                    }
                    dmgText = new Text(Game.content.Load <SpriteFont>("Fonts\\medival1"), Vector2.Zero, color, text, null, new Vector2(10, 10));

                    dmgText.position    = position;
                    dmgText.position.X += bounds.Width / 2 - dmgText.bounds.Width / 2;
                    dmgText.position.Y -= dmgText.bounds.Height - 20;

                    dmgTextTimer.Active();
                }
            }
        }
Esempio n. 10
0
        public ObjectCollection1(Map map)
            : base(map)
        {
            movementManager = new MovementManager(map);

            wolf                 = new Enemy(Content.Load <Texture2D>("Textures\\Spritesheets\\wolf"), new Vector2(25 * 32, 16 * 32));
            wolf.speed           = 2;
            wolf.stats.maxHealth = 16;
            wolf.stats.health    = 16;
            wolf.stats.maxMana   = 16;
            wolf.stats.mana      = 16;
            wolf.stats.strength  = 4;
            wolf.stats.knockback = 30;
            wolf.stats.defence   = 2;
            wolf.stats.agility   = 1;
            wolf.stats.exp       = 5;
            wolf.Cooldown        = 750f;
            wolf.core            = new Rectangle(7, 30, 18, 16);

            wolf2                 = new Enemy(Content.Load <Texture2D>("Textures\\Spritesheets\\wolf"), new Vector2(30 * 32, 16 * 32));
            wolf2.speed           = 2;
            wolf2.stats.maxHealth = 16;
            wolf2.stats.health    = 16;
            wolf2.stats.maxMana   = 16;
            wolf2.stats.mana      = 16;
            wolf2.stats.strength  = 4;
            wolf2.stats.knockback = 30;
            wolf2.stats.defence   = 2;
            wolf2.stats.agility   = 1;
            wolf2.stats.exp       = 7;
            wolf2.Cooldown        = 750f;
            wolf2.core            = new Rectangle(7, 30, 18, 16);

            npc      = new Actor(Content.Load <Texture2D>("Textures\\Spritesheets\\mage"), new Vector2(22 * 32, 18 * 32));
            npc.pack = new Pack(npc);
            npc.pack.AddItem(ItemCollection.ironChestArmor);
            npc.pack.AddItem(ItemCollection.bread);
            npc.pack.AddItem(ItemCollection.bread);
            npc.interactFunction = NpcInteraction;
            npc.core             = new Rectangle(7, 30, 18, 16);

            block = new Sprite(Content.Load <Texture2D>("Textures\\Sprites\\box1"), new Vector2(30 * 32, 30 * 32));

            boatCollision = new GameObject(new Vector2(33 * 32, 29 * 32));
            boatCollision.collisionFunction = BoatcollisionCollision;

            boat = new Vehicle(Content.Load <Texture2D>("Textures\\Spritesheets\\boat"), new Vector2(33.5f * 32, 30 * 32), new List <string>()
            {
                "water"
            }, new List <string>()
            {
                "grass"
            });
            boat.ShowAnimation = true;
            movementManager.TurnSpritesheet(boat, MovementManager.Direction.left);

            holdBox = new Sprite(Content.Load <Texture2D>("Textures\\Sprites\\box1"), new Vector2(20 * 32, 30 * 32));
            holdBox.collisionFunction = HoldBoxCollision;

            pickUpBread = new Pickup(pickUpBread, ItemCollection.bread, new Vector2(11 * 32, 34 * 32));

            groundSwitch                   = new Sprite(Content.Load <Texture2D>("Textures\\Sprites\\brick1"), new Vector2(36 * 32, 25 * 32));
            groundSwitch.MapDepth          = Game.MapDepth.below;
            groundSwitch.passable          = true;
            groundSwitch.collisionFunction = GroundSwitchCollision;

            box1 = new Sprite(Content.Load <Texture2D>("Textures\\Sprites\\box1"), new Vector2(27 * 32, 25 * 32));
            box1.tags.Add("box");

            box2 = new Sprite(Content.Load <Texture2D>("Textures\\Sprites\\box1"), new Vector2(30 * 32, 25 * 32));
            box2.tags.Add("box");

            runningSwitch                   = new Sprite(Content.Load <Texture2D>("Textures\\Sprites\\brick1"), new Vector2(27 * 32, 18 * 32));
            runningSwitch.MapDepth          = Game.MapDepth.below;
            runningSwitch.passable          = true;
            runningSwitch.collisionFunction = RunningSwitchCollision;

            portal                   = new GameObject(new Vector2(34 * 32, 22 * 32));
            portal.passable          = true;
            portal.collisionFunction = PortalCollision;

            gameObjectList.Add(runningSwitch);
            gameObjectList.Add(groundSwitch);
            gameObjectList.Add(npc);
            gameObjectList.Add(boat);
            gameObjectList.Add(boatCollision);
            gameObjectList.Add(portal);
            gameObjectList.Add(wolf);
            gameObjectList.Add(wolf2);
            gameObjectList.Add(block);
            gameObjectList.Add(holdBox);
            gameObjectList.Add(pickUpBread);
            gameObjectList.Add(box1);
            gameObjectList.Add(box2);
        }