示例#1
0
        public override void DrawUI(SpriteBatch spriteBatch, CityUIBlackboard blackboard)
        {
            if (signature != null)
            {
                Vector2 signatureSize = new Vector2(signature.width * 8, signature.height * 8);

                string  text     = "" + amount;
                Vector2 textSize = Game1.font.MeasureString(text);

                Vector2 signaturePos = new Vector2(
                    bounds.X + (bounds.Width - (signatureSize.X + textSize.X)) * 0.5f,
                    bounds.Y + 32 + (textSize.Y - signatureSize.Y) * 0.5f - textSize.Y
                    );

                Vector2 textPos = new Vector2(
                    signaturePos.X + signatureSize.X + 2,
                    bounds.Y + 32 - textSize.Y
                    );

                float     labelHeight = Math.Max(signatureSize.Y, textSize.Y);
                Vectangle labelRect   = new Vectangle(signaturePos.X, signaturePos.Y + (signatureSize.Y - labelHeight) * 0.5f, signatureSize.X + textSize.X, Math.Max(signatureSize.Y, textSize.Y));
                spriteBatch.Draw(TextureCache.white, labelRect.Bloat(5, 2), new Color(0, 0, 0, 0.5f));

                signature.Draw(spriteBatch, signaturePos, true);
                spriteBatch.DrawString(Game1.font, text, textPos, Color.LightGray);
            }
        }
示例#2
0
        public override void DrawUI(SpriteBatch spriteBatch, CityUIBlackboard blackboard)
        {
            Vector2 pos           = new Vector2(bounds.X, bounds.Y + 32);
            Vector2 signatureSize = new Vector2(signature.width * 8, signature.height * 8);

            string  text     = numCrystals > 1? " +" + numCrystals + " bubbles": " +1 bubble";
            Vector2 textSize = Game1.font.MeasureString(text);

            Vector2 signaturePos = new Vector2(
                pos.X + (bounds.Width - (signatureSize.X + textSize.X)) * 0.5f,
                pos.Y + (textSize.Y - signatureSize.Y) * 0.5f
                );

            Vector2 textPos = new Vector2(
                signaturePos.X + signatureSize.X,
                pos.Y
                );

            Vectangle labelRect = new Vectangle(signaturePos.X, signaturePos.Y + (signatureSize.Y - textSize.Y) * 0.5f, signatureSize.X + textSize.X, Math.Max(signatureSize.Y, textSize.Y));

            spriteBatch.Draw(TextureCache.white, labelRect.Bloat(5, 2), new Color(0, 0, 0, 0.5f));
            signature.Draw(spriteBatch, signaturePos, true);

            spriteBatch.DrawString(Game1.font, text, textPos, Color.Yellow);
        }
示例#3
0
        public override void Update(InputState input, List <PlatformObject> allObjects, List <Projectile> projectiles)
        {
            Vectangle myBounds = bounds;

            foreach (PlatformObject obj in allObjects)
            {
                if (obj is ChemBlock && !obj.destroyed && myBounds.Intersects(obj.bounds))
                {
                    ChemBlock block = obj as ChemBlock;

                    /*if (!block.chemGrid.IsInside(myBounds))
                     *  continue;
                     */

                    if (signature != block.chemGrid.GetSignature())
                    {
                        continue;
                    }

                    Game1.instance.platformLevel.Record(sellAction, sellPrice);
                    block.chemGrid.DestroyAll();
                    Game1.instance.platformLevel.UpdateAnyBlocksLeft();
                }
            }
        }
示例#4
0
        public override void Draw(SpriteBatch spriteBatch, CityUIBlackboard blackboard)
        {
            base.Draw(spriteBatch, blackboard);
            Vector2 pos           = new Vector2(bounds.X, bounds.Y + bounds.Height);
            Vector2 signatureSize = new Vector2(signature.width * 8, signature.height * 8);

            string  text     = "$" + price;
            Vector2 textSize = Game1.font.MeasureString(text);

            Vector2 signaturePos = new Vector2(
                pos.X + (bounds.Width - (signatureSize.X + textSize.X)) * 0.5f,
                pos.Y + (textSize.Y - signatureSize.Y) * 0.5f
                );

            Vector2 textPos = new Vector2(
                signaturePos.X + signatureSize.X,
                pos.Y
                );

            float     labelHeight = Math.Max(signatureSize.Y, textSize.Y);
            Vectangle labelRect   = new Vectangle(signaturePos.X, signaturePos.Y + (signatureSize.Y - labelHeight) * 0.5f, signatureSize.X + textSize.X, Math.Max(signatureSize.Y, textSize.Y));

            spriteBatch.Draw(TextureCache.white, labelRect.Bloat(5, 2), new Color(0, 0, 0, 0.5f));

            signature.Draw(spriteBatch, signaturePos, true);

            spriteBatch.DrawString(Game1.font, "$" + price, textPos, Color.Yellow);
        }
示例#5
0
 public CityObject(CityLevel cityLevel, Texture2D texture, Vector2 pos, Vector2 size)
 {
     this.cityLevel    = cityLevel;
     this.bounds       = new Vectangle(ClampToShelf(pos), size);
     this.sprite       = new SpriteObject(texture, bounds.Origin, size);
     sprite.layerDepth = 0.0f;
 }
示例#6
0
 public Command_Spawn(Vectangle bounds, ChemicalFactory factory, int inputIndex)
 {
     triggered       = false;
     this.bounds     = bounds;
     this.factory    = factory;
     this.inputIndex = inputIndex;
 }
示例#7
0
        public void Update(MouseButtonState buttonState, Vector2 mousePos, PlatformCharacter shooter, List <PlatformObject> allObjects, List <Projectile> projectiles)
        {
            if (buttonState == null)
            {
                return;
            }

            showGhost = false;
            if (buttonState.isDown)
            {
                Game1.instance.platformLevel.PauseFrame();
            }

            if (buttonState.isDown || buttonState.justReleased)
            {
                Vectangle targetBounds       = new Vectangle(mousePos - shooter.size / 2, shooter.size);
                bool      targetBoundsFailed = false;
                Vectangle altBounds          = new Vectangle(mousePos - new Vector2(shooter.size.X / 2, shooter.size.Y), shooter.size);
                bool      altBoundsFailed    = false;
                foreach (PlatformObject p in allObjects)
                {
                    if (!targetBoundsFailed && p.bounds.Intersects(targetBounds))
                    {
                        targetBoundsFailed = true;
                        if (altBoundsFailed)
                        {
                            break;
                        }
                    }
                    if (!altBoundsFailed && p.bounds.Intersects(altBounds))
                    {
                        altBoundsFailed = true;
                        if (targetBoundsFailed)
                        {
                            break;
                        }
                    }
                }

                if (!targetBoundsFailed)
                {
                    ghostPos  = targetBounds.XY;
                    showGhost = true;
                }
                else if (!altBoundsFailed)
                {
                    ghostPos  = altBounds.XY;
                    showGhost = true;
                }
            }

            if (buttonState.justReleased && showGhost)
            {
                shooter.pos = ghostPos;
                showGhost   = false;
            }
        }
示例#8
0
 public bool IsInside(Vectangle targetArea)
 {
     foreach (KeyValuePair <ChemBlock, Point> kv in blocks)
     {
         if (!targetArea.Contains(kv.Key.bounds))
         {
             return(false);
         }
     }
     return(true);
 }
示例#9
0
        public override void Update(InputState input, List <PlatformObject> allObjects, List <Projectile> projectiles)
        {
            bool wasPushed = isPushed;

            isPushed = false;
            Vectangle myBounds = bounds;

            foreach (PlatformObject obj in allObjects)
            {
                if (obj is RigidBody)
                {
                    if (obj.bounds.Intersects(myBounds))
                    {
                        isPushed = true;
                        break;
                    }
                }
            }

            if (!isPushed)
            {
                const int EXPAND         = 8;
                Vectangle expandedBounds = myBounds;
                expandedBounds.X      -= EXPAND;
                expandedBounds.Y      -= EXPAND;
                expandedBounds.Width  += EXPAND * 2;
                expandedBounds.Height += EXPAND * 2;
                foreach (Projectile p in projectiles)
                {
                    if (expandedBounds.Contains(p.pos))
                    {
                        isPushed = true;
                        break;
                    }
                }
            }

            if (isPushed)
            {
                texture = pushedTexture;
                if (!wasPushed)
                {
                    target.Run();
                }
            }
            else
            {
                texture = unpushedTexture;
            }
        }
示例#10
0
        public void Cut(Vectangle area, List <PlatformObject> objects)
        {
            HashSet <ChemGrid> gridsChecked = new HashSet <ChemGrid>();

            foreach (PlatformObject obj in objects)
            {
                ChemBlock block = obj as ChemBlock;
                if (block != null && !gridsChecked.Contains(block.chemGrid) && block.bounds.Intersects(area))
                {
                    gridsChecked.Add(block.chemGrid);

                    block.chemGrid.Split(area);
                }
            }
        }
示例#11
0
        public void Split(Vectangle cuttingArea)
        {
            Vector2 origin = GetOrigin();
            bool    cutAny = false;

            if (cuttingArea.Height > 0)
            {
                HashSet <Point> newHBonds = new HashSet <Point>();
                foreach (Point curPos in horizontalBonds)
                {
                    Vectangle bondArea = new Vectangle(origin.X + curPos.X * Game1.BLOCKSIZE + 25, origin.Y + curPos.Y * Game1.BLOCKSIZE + 15, 15, 3);
                    if (cuttingArea.Intersects(bondArea))
                    {
                        cutAny = true;
                    }
                    else
                    {
                        newHBonds.Add(curPos);
                    }
                }
                horizontalBonds = newHBonds;
            }

            if (cuttingArea.Width > 0)
            {
                HashSet <Point> newVBonds = new HashSet <Point>();
                foreach (Point curPos in verticalBonds)
                {
                    Vectangle bondArea = new Vectangle(origin.X + curPos.X * Game1.BLOCKSIZE + 15, origin.Y + curPos.Y * Game1.BLOCKSIZE + 25, 3, 15);
                    if (cuttingArea.Intersects(bondArea))
                    {
                        cutAny = true;
                    }
                    else
                    {
                        newVBonds.Add(curPos);
                    }
                }
                verticalBonds = newVBonds;
            }

            if (cutAny)
            {
                UpdateConnectivity();
            }
        }
示例#12
0
        public override void Update(InputState input, List <PlatformObject> allObjects, List <Projectile> projectiles)
        {
            Vectangle myBounds = bounds;

            foreach (PlatformObject obj in allObjects)
            {
                if (obj is ChemBlock && obj.bounds.Intersects(myBounds) && !obj.destroyed)
                {
                    ChemBlock block = (ChemBlock)obj;
                    block.chemGrid.DoOutput();

                    if (signature != null && block.chemGrid.GetSignature() != signature && (signature2 == null || block.chemGrid.GetSignature() != signature2))
                    {
                        Game1.instance.splashes.Add(new Splash("WRONG OUTPUT!", TextAlignment.CENTER, Game1.font, Color.Orange, new Vector2(300, 350), new Vector2(0, -5), 0.96f, 0, 3));
                    }
                }
            }
        }
示例#13
0
        public override void DrawUI(SpriteBatch spriteBatch, CityUIBlackboard blackboard)
        {
            if (anyThreadStalled && warningTriangleMessage != "")
            {
                Vectangle warningRect = GetWarningRect();
                spriteBatch.Draw(TextureCache.warning, warningRect, Color.White);

                if (showErrorMessage)
                {
                    Vector2 messageSize = Game1.font.MeasureString(warningTriangleMessage);
                    if (messageSize.X > warningRect.Left)
                    {
                        spriteBatch.Draw(TextureCache.white, Game1.font.GetStringBounds(warningTriangleMessage, warningRect.TopRight, TextAlignment.LEFT).Bloat(2), new Color(0.25f, 0, 0, 0.5f));
                        spriteBatch.DrawString(Game1.font, warningTriangleMessage, warningRect.TopRight, Color.Yellow);
                    }
                    else
                    {
                        spriteBatch.Draw(TextureCache.white, Game1.font.GetStringBounds(warningTriangleMessage, warningRect.TopLeft, TextAlignment.RIGHT).Bloat(2), new Color(0.25f, 0, 0, 0.5f));
                        spriteBatch.DrawString(Game1.font, warningTriangleMessage, warningRect.TopLeft, TextAlignment.RIGHT, Color.Yellow);
                    }
                }
            }

            if (selected)
            {
                ui.Draw(spriteBatch);

                Rectangle dragBoxRect = GetDragBox();

                if (commands.Count > 0)
                {
                    int     recordingDurationFrames = commands.Last().time;
                    string  durationStr             = "(" + PlatformLevel.TimeToString(recordingDurationFrames) + " secs)";
                    Vector2 textPos = new Vector2((int)bounds.CenterX, (int)(bounds.Top) - 15);
                    spriteBatch.DrawString(Game1.font, durationStr, textPos, TextAlignment.CENTER, Color.White);
                }

/*                string text = "" + numCores;
 *              Vector2 textSize = Game1.font.MeasureString(text);
 *              spriteBatch.Draw(TextureCache.outlined_square, dragBoxRect, numCores > DEFAULT_NUM_CORES? Color.Orange: Color.Gray);
 *              spriteBatch.DrawString(Game1.font, text, new Vector2((int)(dragBoxRect.Center.X - textSize.X / 2), (int)(dragBoxRect.Center.Y - textSize.Y / 2)), Color.Black);*/
            }
        }
示例#14
0
        void SpawnBubble(PlatformObject objectHit, Vector2 pos, Vector2 direction, List <PlatformObject> allObjects)
        {
            Vectangle objectBounds = objectHit.bounds;

            if (objectHit is ChemBlock)
            {
                pos = objectBounds.Center + direction * 16;
            }

            while (objectBounds.Contains(pos))
            {
                pos += direction;
            }

            pos += direction * 17;
            Vectangle bubbleBounds = new Vectangle(pos - new Vector2(16, 16), new Vector2(32, 32));

            bool failed = false;

            foreach (PlatformObject obj in allObjects)
            {
                if (obj.bounds.Intersects(bubbleBounds))
                {
                    failed = true;
                    break;
                }
            }

            if (!failed)
            {
                Game1.instance.platformLevel.Record(FactoryCommandType.SPENDCRYSTAL);

                ChemicalElement c        = ChemicalElement.WHITE;
                ChemBlock       newBlock = new ChemBlock(c, c.ToTexture(false), bubbleBounds.TopLeft, bubbleBounds.Size, c.ToColor());
                if (objectHit is ChemBlock)
                {
                    newBlock.NailOnto((ChemBlock)objectHit);
                }
                allObjects.Add(newBlock);
            }
        }
示例#15
0
        Vector2 GetCollisionNormal(Vectangle bounds, Vector2 oldPos, Vector2 newPos)
        {
            Vectangle boundingBox = Vectangle.BoundingBox(oldPos, newPos);

            if (bounds.LeftSide.Intersects(boundingBox))
            {
                return(new Vector2(-1, 0));
            }
            if (bounds.RightSide.Intersects(boundingBox))
            {
                return(new Vector2(1, 0));
            }
            if (bounds.TopSide.Intersects(boundingBox))
            {
                return(new Vector2(0, -1));
            }
            if (bounds.BottomSide.Intersects(boundingBox))
            {
                return(new Vector2(0, 1));
            }
            return(new Vector2(1, 0));
        }
示例#16
0
        protected Vector2 CheckMove(RigidBody parentObject, Vector2 currentMove, List <PlatformObject> allObjects, ref PlatformObject onGround)
        {
            const float EPSILON     = 0.01f;
            Vectangle   moveBoundsX = GetMoveBoundsX(currentMove);
            Vectangle   moveBoundsY = GetMoveBoundsY(currentMove);

            foreach (PlatformObject obj in allObjects)
            {
                if (obj == this || IgnoreCollisions(obj, currentMove))
                {
                    continue;
                }

                Vectangle objBounds = obj.bounds;
                if (currentMove.X != 0 && moveBoundsX.Intersects(objBounds))
                {
                    // TODO: need to calculate this more precisely.
                    if (currentMove.X > 0)
                    {
                        if (moveBoundsX.Intersects(objBounds.LeftSide))
                        {
                            HandleColliding(obj, currentMove);
                            currentMove.X = objBounds.X - (pos.X + size.X + EPSILON);
                            obj.CollidedX(parentObject);
                            moveBoundsX = GetMoveBoundsX(currentMove);
                        }
                    }
                    else
                    {
                        if (moveBoundsX.Intersects(objBounds.RightSide))
                        {
                            HandleColliding(obj, currentMove);
                            currentMove.X = objBounds.MaxX + EPSILON - pos.X;
                            obj.CollidedX(parentObject);
                            moveBoundsX = GetMoveBoundsX(currentMove);
                        }
                    }
                }

                if (currentMove.Y != 0 && moveBoundsY.Intersects(objBounds))
                {
                    if (currentMove.Y > 0)
                    {
                        if (moveBoundsY.Intersects(objBounds.TopSide))
                        {
                            HandleColliding(obj, currentMove);
                            currentMove.Y = objBounds.Y - (pos.Y + size.Y + EPSILON);
                            obj.CollidedY(parentObject);
                            moveBoundsY = GetMoveBoundsY(currentMove);
                            onGround    = obj;
                        }
                    }
                    else
                    {
                        if (moveBoundsY.Intersects(objBounds.BottomSide))
                        {
                            HandleColliding(obj, currentMove);
                            currentMove.Y = objBounds.MaxY + EPSILON - pos.Y;
                            obj.CollidedY(parentObject);
                            moveBoundsY = GetMoveBoundsY(currentMove);
                        }
                    }
                }
            }

            return(currentMove);
        }
示例#17
0
 public WorldObject(Texture2D texture, Vector2 pos)
 {
     sprite            = new SpriteObject(texture, pos);
     sprite.layerDepth = 0.0f;
     bounds            = new Vectangle(pos, texture.Size());
 }