Example #1
0
 public static void DrawSpotLighting(SpriteBatch sb, Camera cam, RenderTarget2D lightsTarget, List <Sprite> drawOrder)
 {
     // draw lights (render target should already be set to lightsTarget for lights)
     foreach (var obj in drawOrder)
     {
         if (obj is IPlayer) // check the player's handheld
         {
             PlayerPirate p = (PlayerPirate)obj;
             Light        l = p.inHand.GetEmittingLight();
             if (l != null && l.lit)
             {
                 l.Draw(sb, cam);
             }
         }
         else if (obj is ILight)
         {
             ILight l  = (ILight)obj;
             Light  lt = l.GetEmittingLight();
             if (l != null && lt != null && lt.lit)
             {
                 lt.Draw(sb, cam);
             }
         }
     }
 }
Example #2
0
        public CraftingMenu(Vector2 location, ContentManager content, GraphicsDevice graphics, PlayerPirate invOfPlayer) : base(graphics)
        {
            _graphics = graphics;
            _content  = content;
            font      = _content.Load <SpriteFont>("helperFont");
            cursor    = _content.Load <Texture2D>("pointer");

            inventoryOfPlayer = invOfPlayer;

            itemDisplaySizePix = 60;

            craftableItemsChecked        = new List <InventoryItem>();
            slotLocations                = new Dictionary <int, Rectangle>();
            itemMenuButtonLocations      = new Dictionary <string, Rectangle>();
            saveItemSpriteScale          = new Dictionary <InventoryItem, float>();
            ingredientsAmountDifferences = new Dictionary <string, Dictionary <string, int> >();
            playerInvCanStackItem        = new Dictionary <string, bool>();

            Texture2D textureInventory = new Texture2D(graphics, 440, 400);

            Color[] data = new Color[440 * 400];
            for (int i = 0; i < data.Length; ++i)
            {
                data[i] = Color.DimGray;
            }
            textureInventory.SetData(data);
            Asset invetoryAsset = new Asset(textureInventory, null, 1, 1, 1.0f, null, null);

            SetSpriteAsset(invetoryAsset, location);

            itemDrawLocStart = new Vector2(location.X - _texture.Width / 2 + 50, location.Y - _texture.Height / 2 + 100);

            // just used to display the crafting textures in the menu. Not used in game.
            IconTextures = new Dictionary <string, InventoryItem>
            {
                { "anvilItem", new AnvilItem(TeamType.Player, "GustoGame", Vector2.Zero, _content, _graphics) },
                { "baseSword", new BaseSword(TeamType.Player, "GustoGame", Vector2.Zero, _content, _graphics) },
                { "nails", new Nails(TeamType.Player, "GustoGame", Vector2.Zero, _content, _graphics) },
                { "ironBar", new IronBar(TeamType.Player, "GustoGame", Vector2.Zero, _content, _graphics) },
                { "cookedMeat", new CookedMeat(TeamType.Player, "GustoGame", Vector2.Zero, _content, _graphics) },
                { "cookedFish", new CookedFish(TeamType.Player, "GustoGame", Vector2.Zero, _content, _graphics) },
                { "chiliFish", new ChiliFish(TeamType.Player, "GustoGame", Vector2.Zero, _content, _graphics) },
            };
        }
Example #3
0
        public Inventory(Vector2 location, ContentManager content, GraphicsDevice graphics, PlayerPirate invOfPlayer) : base(graphics)
        {
            _graphics = graphics;
            _content  = content;
            font      = _content.Load <SpriteFont>("helperFont");
            cursor    = _content.Load <Texture2D>("pointer");

            inventoryOfPlayer = invOfPlayer;

            itemDisplaySizePix = 60;
            maxInventorySlots  = inventoryOfPlayer.maxInventorySlots;
            shipInventorySlots = 0;
            storageInvSlots    = 0;
            selectedIndex      = 0;
            dropDragIndex      = -1;
            selectDragIndex    = -1;
            itemMenuIndex      = -1;
            tempInventory      = Enumerable.Repeat <InventoryItem>(null, maxInventorySlots + shipInventorySlots).ToList();

            slotLocations           = new Dictionary <int, Rectangle>();
            itemMenuButtonLocations = new Dictionary <string, Rectangle>();
            saveItemSpriteScale     = new Dictionary <InventoryItem, float>();

            Texture2D textureInventory = new Texture2D(graphics, 440, 275);

            Color[] data = new Color[440 * 275];
            for (int i = 0; i < data.Length; ++i)
            {
                data[i] = Color.DimGray;
            }
            textureInventory.SetData(data);
            Asset invetoryAsset = new Asset(textureInventory, null, 1, 1, 1.0f, null, null);

            SetSpriteAsset(invetoryAsset, location);

            itemDrawLocStart = new Vector2(location.X - _texture.Width / 2 + 50, location.Y - _texture.Height / 2 + 100);
        }
Example #4
0
        public static bool CheckCollidable(Sprite a, Sprite b)
        {
            if (a.inInteriorId != Guid.Empty)
            {
                if (b.inInteriorId == Guid.Empty)
                {
                    return(false);
                }

                if (b.inInteriorId != a.inInteriorId)
                {
                    return(false);
                }
            }

            if (a is IShip)
            {
                Ship ship = (Ship)a;
                // a ship doesn't collide with its any ship's sails
                if (b.GetType().BaseType == typeof(Gusto.Models.Animated.Sail))
                {
                    return(false);
                }

                if (b is ILand)
                {
                    TilePiece t = (TilePiece)b;
                    if (!(t.shorePiece))
                    {
                        return(false);
                    }
                }

                // ship doesn't collide with interior tiles
                if (b is IInteriorTile)
                {
                    return(false);
                }

                // ship doesn't collide with its own cannon balls
                if (b.GetType().BaseType == typeof(Gusto.Models.Animated.Ammo))
                {
                    Ammo ball = (Ammo)b;
                    if (ball.teamType == ship.teamType)
                    {
                        return(false);
                    }
                }
            }

            else if (a is IPlayer)
            {
                PlayerPirate pirate = (PlayerPirate)a;
                // a player doesn't collide with its own shots
                if (b is IAmmo)
                {
                    Ammo ball = (Ammo)b;
                    if (ball.teamType == pirate.teamType)
                    {
                        return(false);
                    }
                }
                else if (b.GetType().BaseType == typeof(Gusto.Models.Animated.Tree))
                {
                    return(false);
                }
            }

            else if (a.GetType().BaseType == typeof(Gusto.Models.Animated.Tower))
            {
                BaseTower tower = (BaseTower)a;
                // a tower doesn't collide with its own shots
                if (b is IAmmo)
                {
                    Ammo ball = (Ammo)b;
                    if (ball.teamType == tower.teamType)
                    {
                        return(false);
                    }
                }
            }

            // hand items only collide when they are being used
            else if (a is IHandHeld)
            {
                HandHeld inHand = (HandHeld)a;
                if (!inHand.usingItem && !inHand.onGround)
                {
                    return(false);
                }
            }

            else if (a is IAmmo)
            {
                if (b.GetType().BaseType == typeof(Gusto.Models.TilePiece))
                {
                    return(false);
                }
                if (b.GetType().BaseType == typeof(Gusto.Models.Animated.Grass))
                {
                    return(false);
                }
            }

            else if (a is IGroundObject)
            {
                if (b is IGroundObject)
                {
                    return(false);
                }
                if (b.GetType().BaseType == typeof(Gusto.Models.TilePiece))
                {
                    return(false);
                }
                if (b is IShip)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #5
0
        // collision handling beef
        private void SpatialCollision()
        {
            foreach (var team in BoundingBoxLocations.BoundingBoxLocationMap.Keys)
            {
                BoundingBoxLocations.BoundingBoxLocationMap[team].Clear();
            }

            foreach (var spriteA in Collidable)
            {
                // set the current region
                foreach (var region in BoundingBoxLocations.RegionMap)
                {
                    if (spriteA.regionKey != region.Key && region.Value.Bounds.Intersects(spriteA.GetBoundingBox()))
                    {
                        spriteA.regionKey = region.Key;
                    }
                }

                Polygon polyA = null;

                Target targetEntry = new Target();
                targetEntry.interiorId = spriteA.inInteriorId;
                targetEntry.targetLoc  = spriteA.GetBoundingBox().Center.ToVector2();
                if (spriteA.mapCordPoint != null)
                {
                    targetEntry.mapCordPoint = spriteA.mapCordPoint.Value;
                }
                // BoundBoxLocationMap update - this structure is used for AI locating targets. Set all needed target values
                // pathType denotes what pathType ai will move to. ( i.e. Ships won't move to targets with Land pathType because it wouldn't find a path there and would waste time)
                if (spriteA.GetType().BaseType == typeof(Gusto.Models.Animated.Ship))
                {
                    Ship ship = (Ship)spriteA;
                    targetEntry.pathType = PathType.Ocean;
                    BoundingBoxLocations.BoundingBoxLocationMap[ship.teamType].Add(targetEntry);
                }
                else if (spriteA.GetType().BaseType == typeof(Gusto.Models.Animated.Tower))
                {
                    Tower tower = (Tower)spriteA;
                    targetEntry.pathType = PathType.Land;
                    BoundingBoxLocations.BoundingBoxLocationMap[tower.teamType].Add(targetEntry);
                }
                else if (spriteA.GetType().BaseType == typeof(Gusto.Models.Animated.PlayerPirate))
                {
                    PlayerPirate player = (PlayerPirate)spriteA;
                    targetEntry.pathType = PathType.Land;
                    BoundingBoxLocations.BoundingBoxLocationMap[player.teamType].Add(targetEntry);
                }
                else if (spriteA.GetType().BaseType == typeof(Gusto.Models.Animated.Npc))
                {
                    Npc npc = (Npc)spriteA;
                    targetEntry.pathType = PathType.Land;
                    BoundingBoxLocations.BoundingBoxLocationMap[npc.teamType].Add(targetEntry);
                }

                Rectangle bbA = spriteA.GetBoundingBox();
                if (BoundingBoxTextures.DynamicBoundingPolygons.ContainsKey(spriteA.bbKey))
                {
                    polyA = spriteA.GetBoundingPolygon();
                }

                HashSet <string> quadKeys = collision.GetQuadKey(bbA);
                HashSet <Sprite> possible = new HashSet <Sprite>();
                foreach (var key in quadKeys)
                {
                    possible.UnionWith(collision.GetSpatialBoundingMap()[key]);
                }

                foreach (var spriteB in possible)
                {
                    var bbB = spriteB.GetBoundingBox();

                    if (Object.ReferenceEquals(spriteA, spriteB))
                    {
                        continue;
                    }

                    Polygon polyB = null;
                    if (BoundingBoxTextures.DynamicBoundingPolygons.ContainsKey(spriteB.bbKey))
                    {
                        polyB = spriteB.GetBoundingPolygon();
                    }

                    // pass collision game logic - this filters out some collisions that are colliding but we don't want to handle a collision (trees colliding with other trees)
                    if (CollisionGameLogic.CheckCollidable(spriteA, spriteB) && CollisionGameLogic.CheckCollidable(spriteB, spriteA))
                    {
                        // spatial intersection for rect, poly
                        if (polyA != null || polyB != null)
                        {
                            // poly vs rect
                            if (polyA != null && polyB == null)
                            {
                                if (polyA.IntersectsRect(bbB))
                                {
                                    MarkCollision(spriteA, spriteB);
                                }
                            }
                            else if (polyB != null && polyA == null)
                            {
                                if (polyB.IntersectsRect(bbA))
                                {
                                    MarkCollision(spriteA, spriteB);
                                }
                            }
                            else
                            {
                                // poly vs poly
                                if (polyA.IntersectsPoly(polyB))
                                {
                                    MarkCollision(spriteA, spriteB);
                                }
                            }
                        }
                        else
                        {
                            // rect vs rects
                            if (bbA.Intersects(bbB))
                            {
                                MarkCollision(spriteA, spriteB);
                            }
                        }
                    }
                }
            }
            collision.Clear();
        }