Example #1
0
        public override void HandleCollision(Sprite collidedWith, Rectangle overlap)
        {
            if (collidedWith.bbKey.Equals("playerPirate"))
            {
                playerNearItem = (PiratePlayer)collidedWith;
            }

            if (collidedWith.bbKey.Equals("pickaxe"))
            {
                if (collidedWith.GetBoundingBox().Top > (GetBoundingBox().Center.ToVector2().Y + GetBoundingBox().Height / 3)) // MOVE UP
                {
                    location.Y -= 10;
                }
                else if (collidedWith.GetBoundingBox().Left > (GetBoundingBox().Center.ToVector2().X + GetBoundingBox().Width / 3)) // move left
                {
                    location.X -= 10;
                }
                else if (collidedWith.GetBoundingBox().Right < (GetBoundingBox().Center.ToVector2().X - GetBoundingBox().Width / 3))
                {
                    location.X += 10;
                }
                else if (collidedWith.GetBoundingBox().Bottom < (GetBoundingBox().Center.ToVector2().Y - GetBoundingBox().Height / 3))
                {
                    location.Y += 10;
                }

                nTimesHit += 1;
                if (nTimesHit >= hitsToPickUp)
                {
                    canPickUp = true;
                }
            }
        }
Example #2
0
        public override void HandleCollision(Sprite collidedWith, Rectangle overlap)
        {
            collidedWith.colliding = false;

            if (collidedWith.bbKey.Equals("playerPirate"))
            {
                canPickUp      = true;
                playerNearItem = (PiratePlayer)collidedWith;
            }
        }
Example #3
0
        public PiratePlayer player; // only track the player because there are some special focuses around it.. obviously

        public GameState(ContentManager c, GraphicsDevice g)
        {
            savePath = @"C:\Users\GMON\Desktop\";
            gameName = "game1";

            _content    = c;
            _graphics   = g;
            UpdateOrder = new HashSet <Sprite>();

            player = new PiratePlayer(TeamType.Player, "GustoMap", new Vector2(-120, -550), _content, _graphics); // This is a default location (for new game) if there is a load it will be overwritten
        }
Example #4
0
        public static void DrawPlayer(SpriteBatch spriteBatchView, Camera camera, PiratePlayer pirate)
        {
            // wont draw if pirate not hurt
            pirate.DrawHealthBar(spriteBatchView, camera);

            if (pirate.inCombat && pirate.currRowFrame == 3) // draw sword before pirate when moving up
            {
                pirate.inHand.Draw(spriteBatchView, camera);
            }
            if (pirate.nearShip)
            {
                pirate.DrawEnterShip(spriteBatchView, camera);
            }
            else if (pirate.onShip)
            {
                pirate.DrawOnShip(spriteBatchView, camera);
            }


            if (pirate.swimming && !pirate.onShip)
            {
                pirate.DrawSwimming(spriteBatchView, camera);
            }
            else if (!pirate.onShip)
            {
                pirate.Draw(spriteBatchView, camera);
            }

            if (pirate.canBury)
            {
                pirate.DrawCanBury(spriteBatchView, camera);
            }

            if (pirate.inCombat && pirate.currRowFrame != 3)
            {
                pirate.inHand.Draw(spriteBatchView, camera);
            }

            foreach (var shot in pirate.inHand.Shots)
            {
                shot.Draw(spriteBatchView, camera);
            }
        }
Example #5
0
        public void Update(KeyboardState kstate, GameTime gameTime, Camera camera)
        {
            // Update the storage inventory for timedItems
            List <int>           removeExpiredItem = new List <int>();
            List <InventoryItem> addTimedItem      = new List <InventoryItem>();

            foreach (var item in inventory)
            {
                if (item == null)
                {
                    continue;
                }

                // for spoiled food
                if (item is ISpoiles)
                {
                    item.msSpoilTime += gameTime.ElapsedGameTime.Milliseconds;
                    Tuple <int, string> spoilDetails = ItemMappings.SpoilMappings[item.bbKey];

                    if (item.msSpoilTime > spoilDetails.Item1)
                    {
                        InventoryItem spoiled = ItemUtility.CreateInventoryItem(spoilDetails.Item2, item.teamType, regionKey, location, _content, _graphics);
                        item.msSpoilTime = 0;
                        if (item.amountStacked > 1)
                        {
                            item.amountStacked -= 1;
                        }
                        else
                        {
                            removeExpiredItem.Add(inventory.IndexOf(item));
                        }

                        addTimedItem.Add(spoiled);
                    }
                }
            }
            foreach (var remove in removeExpiredItem)
            {
                inventory[remove] = null;
            }
            foreach (var item in addTimedItem)
            {
                if (!AddInventoryItem(item))
                {
                    item.location = new Vector2(GetBoundingBox().Center.ToVector2().X, GetBoundingBox().Center.ToVector2().Y + 40);
                    item.onGround = true;

                    if (inInteriorId != Guid.Empty) // add drops to interior
                    {
                        BoundingBoxLocations.interiorMap[inInteriorId].interiorObjectsToAdd.Add(item);
                    }
                    else // add drops to world
                    {
                        ItemUtility.ItemsToUpdate.Add(item);
                    }
                }
            }



            if (canOpenStorage && !storageOpen && kstate.IsKeyDown(Keys.O))
            {
                storageOpen = true;
            }

            if (storageOpen)
            {
                if (kstate.IsKeyDown(Keys.Escape) || !canOpenStorage)
                {
                    storageOpen = false;
                }
            }


            if (canPickUp)
            {
                // pick up the item
                if (playerNearItem != null && kstate.IsKeyDown(Keys.P))
                {
                    // TODO: might need to switch different chest types here?
                    InventoryItem bci = new BaseChestItem(playerNearItem.teamType, regionKey, location, _content, _graphics);
                    if (playerNearItem.AddInventoryItem(bci))
                    {
                        bci.placeableVersion = this;
                        bci.inInventory      = true;
                        bci.onGround         = false;
                        bci.stackable        = false;
                        bci.amountStacked    = 1;
                        remove    = true;
                        canPickUp = false;
                    }
                }


                // there is a timer for how long you have to pick up item once you have the required number of hits
                msSinceStartPickupTimer += gameTime.ElapsedGameTime.Milliseconds;
                if (msSinceStartPickupTimer > msPickupTimer)
                {
                    msSinceStartPickupTimer = 0;
                    canPickUp = false;
                    nTimesHit = 0;
                }
            }

            if (inWater)
            {
                currRowFrame = 1;
                msThisFrame += gameTime.ElapsedGameTime.Milliseconds;
                if (msThisFrame > msPerFrame)
                {
                    currColumnFrame++;
                    if (currColumnFrame >= nColumns)
                    {
                        currColumnFrame = 0;
                    }
                    msThisFrame = 0;
                }
            }
            else
            {
                currRowFrame = 0;
            }


            inWater        = true;
            canOpenStorage = false;
            playerNearItem = null;
        }
Example #6
0
        public override void HandleCollision(Sprite collidedWith, Rectangle overlap)
        {
            // land tiles are only run through collision detection


            // shoveling && treasure
            if (collidedWith.bbKey.Equals("playerPirate"))
            {
                PiratePlayer p = (PiratePlayer)collidedWith;
                if (p.inHand != null && p.inHand.bbKey.Equals("shovel") && p.inHand.inCombat)
                {
                    Rectangle bottomOfShovel = new Rectangle(p.inHand.GetBoundingBox().Left, p.inHand.GetBoundingBox().Bottom - (p.inHand.GetBoundingBox().Height / 3),
                                                             p.inHand.GetBoundingBox().Width, p.inHand.GetBoundingBox().Height / 3);

                    if (bottomOfShovel.Intersects(GetBoundingBox()))
                    {
                        shoveled = true;
                    }
                }
                else if (shoveled)
                {
                    if (fill)
                    {
                        currColumnFrame--;
                        if (currColumnFrame <= 0)
                        {
                            currColumnFrame = 0;
                            fill            = false;
                        }
                        canFillHole = false;
                    }
                    else
                    {
                        currColumnFrame++;
                        if (currColumnFrame >= nColumns)
                        {
                            // Check for Treasure! Arrrg
                            foreach (var treasureMap in BoundingBoxLocations.treasureLocationsList)
                            {
                                Rectangle digLocRect = new Rectangle((int)treasureMap.digTileLoc.X, (int)treasureMap.digTileLoc.Y, GameOptions.tileWidth, GameOptions.tileHeight);
                                if (digLocRect.Intersects(this.GetBoundingBox()))
                                {
                                    // the contents of the treasure was set by player
                                    if (treasureMap.rewarded != null)
                                    {
                                        treasureMap.rewarded.remove   = false;
                                        treasureMap.rewarded.location = new Vector2(treasureMap.digTileLoc.X + RandomEvents.rand.Next(-5, 5), treasureMap.digTileLoc.Y + RandomEvents.rand.Next(-5, 5));
                                        ItemUtility.ItemsToUpdate.Add(treasureMap.rewarded);
                                        treasureMap.solved = true;
                                    }
                                    else
                                    {
                                        // TODO: use the map tier to tier the loot here
                                        if (!treasureMap.solved)
                                        {
                                            Storage reward = new BaseChest(TeamType.Player, regionKey, location, _content, _graphics);
                                            reward.remove = false;
                                            ItemUtility.ItemsToUpdate.Add(reward);
                                            treasureMap.solved = true;
                                        }
                                    }
                                    break;
                                }
                            }

                            canFillHole     = true;
                            currColumnFrame = nColumns - 1;
                            fill            = true;
                        }
                        else
                        {
                            canFillHole = false;
                        }
                    }

                    shoveled = false;
                }
            }
        }
Example #7
0
        public void Update(KeyboardState kstate, GameTime gameTime, Camera camera)
        {
            // start the fire
            if (playerNearItem != null && kstate.IsKeyDown(Keys.C)) // TODO: and keypress time
            {
                // Remove items from inv TODO: for now this just takes the first ore, grass, wood etc in inventory
                if (!cooking)
                {
                    int nWood  = 0;
                    int nGrass = 0;
                    // check for kindling
                    foreach (var item in playerNearItem.inventory)
                    {
                        if (item is IWood)
                        {
                            nWood += item.amountStacked;
                        }
                        if (item is IGrass)
                        {
                            nGrass += item.amountStacked;
                        }
                    }

                    if (nWood >= 2 && nGrass >= 2)
                    {
                        cooking = true;
                        RemoveKindlingConsumables();
                    }
                }
            }

            if (craftingQueue.Count > 0)
            {
                msCrafting += gameTime.ElapsedGameTime.Milliseconds;
            }

            // create and drop item when crafting
            if (craftingQueue.Count > 0 && msCrafting > craftingQueue.Peek().msCraftTime)
            {
                InventoryItem item    = craftingQueue.Dequeue();
                Vector2       dropLoc = new Vector2(GetBoundingBox().Center.ToVector2().X, GetBoundingBox().Center.ToVector2().Y + 40);

                item.location = dropLoc;
                item.onGround = true;

                if (inInteriorId != Guid.Empty) // add drops to interior
                {
                    BoundingBoxLocations.interiorMap[inInteriorId].interiorObjectsToAdd.Add(item);
                }
                else // add drops to world
                {
                    ItemUtility.ItemsToUpdate.Add(item);
                }

                msCrafting = 0;
                // reset smelting
                if (craftingQueue.Count <= 0)
                {
                    cooking           = false;
                    currColumnFrame   = 0;
                    emittingLight.lit = false;
                }
            }

            if (playerNearItem != null && kstate.IsKeyDown(Keys.C) && !drawCraftingMenu && cooking)
            {
                drawCraftingMenu = true;
            }

            if (drawCraftingMenu)
            {
                if (kstate.IsKeyDown(Keys.Escape) || playerNearItem == null)
                {
                    drawCraftingMenu = false;
                }
            }

            // lighting the furnace when running
            if (emittingLight.lit)
            {
                emittingLight.Update(kstate, gameTime, GetBoundingBox().Center.ToVector2());
            }

            if (cooking)
            {
                emittingLight.lit = true;
                // cooking so animate and being timer
                msCooking   += gameTime.ElapsedGameTime.Milliseconds;
                msThisFrame += gameTime.ElapsedGameTime.Milliseconds;
                if (msThisFrame > msPerFrame)
                {
                    currColumnFrame++;
                    msThisFrame = 0;
                    if (currColumnFrame == nColumns)
                    {
                        currColumnFrame = 1;
                    }
                }
            }


            if (canPickUp)
            {
                // pick up the item
                if (playerNearItem != null && kstate.IsKeyDown(Keys.P))
                {
                    InventoryItem cfi = new ClayFurnaceItem(playerNearItem.teamType, regionKey, location, _content, _graphics);
                    if (playerNearItem.AddInventoryItem(cfi))
                    {
                        cfi.placeableVersion = this;
                        cfi.inInventory      = true;
                        cfi.onGround         = false;
                        cfi.stackable        = false;
                        cfi.amountStacked    = 1;
                        remove = true;
                    }
                }


                // there is a timer for how long you have to pick up item once you have the required number of hits
                msSinceStartPickupTimer += gameTime.ElapsedGameTime.Milliseconds;
                if (msSinceStartPickupTimer > msPickupTimer)
                {
                    msSinceStartPickupTimer = 0;
                    canPickUp = false;
                    nTimesHit = 0;
                }
            }

            playerNearItem = null;
        }
Example #8
0
        public void Update(KeyboardState kstate, GameTime gameTime, Camera camera)
        {
            if (craftingQueue.Count > 0)
            {
                msCrafting += gameTime.ElapsedGameTime.Milliseconds;
            }
            // create and drop item when crafting
            if (craftingQueue.Count > 0 && msCrafting > craftingQueue.Peek().msCraftTime)
            {
                InventoryItem item    = craftingQueue.Dequeue();
                Vector2       dropLoc = new Vector2(GetBoundingBox().Center.ToVector2().X, GetBoundingBox().Center.ToVector2().Y + 40);

                item.location = dropLoc;
                item.onGround = true;

                if (inInteriorId != Guid.Empty) // add drops to interior
                {
                    BoundingBoxLocations.interiorMap[inInteriorId].interiorObjectsToAdd.Add(item);
                }
                else // add drops to world
                {
                    ItemUtility.ItemsToUpdate.Add(item);
                }

                msCrafting = 0;
            }

            if (playerNearItem != null && kstate.IsKeyDown(Keys.C) && !drawCraftingMenu)
            {
                drawCraftingMenu = true;
            }

            if (drawCraftingMenu)
            {
                if (kstate.IsKeyDown(Keys.Escape) || playerNearItem == null)
                {
                    drawCraftingMenu = false;
                }
            }

            if (canPickUp)
            {
                // pick up the item
                if (playerNearItem != null && kstate.IsKeyDown(Keys.P))
                {
                    InventoryItem ai = new AnvilItem(playerNearItem.teamType, regionKey, location, _content, _graphics);
                    if (playerNearItem.AddInventoryItem(ai))
                    {
                        ai.placeableVersion = this;
                        ai.inInventory      = true;
                        ai.onGround         = false;
                        ai.stackable        = false;
                        ai.amountStacked    = 1;
                        remove = true;
                    }
                }

                // there is a timer for how long you have to pick up item once you have the required number of hits
                msSinceStartPickupTimer += gameTime.ElapsedGameTime.Milliseconds;
                if (msSinceStartPickupTimer > msPickupTimer)
                {
                    msSinceStartPickupTimer = 0;
                    canPickUp = false;
                    nTimesHit = 0;
                }
            }

            playerNearItem = null;
        }