Example #1
0
        public override JabRectangle GetRectangle()
        {
            SetScaledPos();

            JabRectangle rect = base.GetRectangle();

            SetRegularPos();


            return(rect);
        }
Example #2
0
        public override void OnTap(Vector2 p)
        {
            JabRectangle rect = GetRectangle();

            if (Contains(p.X, p.Y))
            {
                MenuEvent ev = new MenuEvent(MenuEvent.EventType.TAP);
                ev.sender = this;
                EventManager.Get.SendEvent(ev);
            }
        }
Example #3
0
        public override void Update(GameTime gameTime)
        {
            UpdateTrajectory();
            base.Update(gameTime);
            //Camera.Get.Position = Position;// +new Vector2(400, -400);

            if (cannonRect == null)
            {
                cannonRect = GetRectangle();
            }
            Vector2 topleft = TopLeftPosition();

            if (!smoke.CheckFlag(Jabber.Flags.PASSRENDER))
            {
                smoke.Update(gameTime);
            }
        }
Example #4
0
        public virtual bool Contains(float posx, float posy)
        {
            JabRectangle rect = GetRectangle();

            if (rect.Left <= posx)
            {
                if (rect.Right >= posx)
                {
                    if (rect.Top <= posy)
                    {
                        if (rect.Bottom >= posy)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Example #5
0
        public override void Update(GameTime gameTime)
        {
            UpdateTrajectory();
            base.Update(gameTime);
            //Camera.Get.Position = Position;// +new Vector2(400, -400);

            if(cannonRect == null)
                cannonRect = GetRectangle();
            Vector2 topleft = TopLeftPosition();

            if (!smoke.CheckFlag(Jabber.Flags.PASSRENDER))
            {
                smoke.Update(gameTime);
            }
        }
Example #6
0
        public virtual bool IsVisible(BaseSprite sprite)
        {
            {
                float max = (float)Math.Max(sprite.Width * ScaleX, sprite.Height * ScaleY);
                Vector2 pos = sprite.Position;

                Vector2 bottomRight = ScreenToWorld(Vector2.One);
                Vector2 topLeft = ScreenToWorld(Vector2.Zero);

                if (pos.X < bottomRight.X && pos.X > topLeft.X)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }

            JabRectangle camView = new JabRectangle(0, 0, 1.0f, 1.0f);
            JabRectangle spriteRect = sprite.GetRectangle();

            if (!(camView.Intersects(spriteRect) || spriteRect.Intersects(camView)))
            {
                int k = 0;
            }

            return camView.Intersects(spriteRect) || spriteRect.Intersects(camView);
        }
Example #7
0
        public virtual JabRectangle GetRectangle()
        {
            JabRectangle rec;

            if (DrawIn == DrawSpace.SCREENSPACE)
            {
                rec = new JabRectangle((float)TopLeftPosition().X, (float)TopLeftPosition().Y, (float)(Width * ScaleX),
                    (float)(Height * ScaleY));
            }
            else
            {
                Vector2 topleftpos = TopLeftPosition();
                rec = new JabRectangle(topleftpos.X, topleftpos.Y, (float)(Width * ScaleX * Camera.Get.WorldScale.X), (float)(Height * ScaleY * Camera.Get.WorldScale.Y));
            }

            Vector2 topleft = Vector2.Zero;
            topleft.X = rec.Left;
            topleft.Y = rec.Top;

            Vector2 bottomRight = Vector2.Zero;
            bottomRight.X = rec.Right;
            bottomRight.Y = rec.Bottom;

            Vector2 topright = Vector2.Zero;
            topright.X = rec.Right;
            topright.Y = rec.Top;

            Vector2 bottomleft = Vector2.Zero;
            bottomleft.X = rec.Left;
            bottomleft.Y = rec.Bottom;

            topleft = JabMath.RotateVectorAround(HandleAdjustedPosition(), topleft, Rot);
            bottomRight = JabMath.RotateVectorAround(HandleAdjustedPosition(), bottomRight, Rot);
            bottomleft = JabMath.RotateVectorAround(HandleAdjustedPosition(), bottomleft, Rot);
            topright = JabMath.RotateVectorAround(HandleAdjustedPosition(), topright, Rot);

            Vector2 newTopLeft = Vector2.Zero;
            Vector2 newBottomRight = Vector2.Zero;

            if (DrawIn == DrawSpace.WORLDSPACE)
            {
                newTopLeft = new Vector2(Math.Min(Math.Min(topleft.X, bottomRight.X), Math.Min(bottomleft.X, topright.X)),
                    Math.Min(Math.Min(topleft.Y, bottomRight.Y), Math.Min(bottomleft.Y, topright.Y)));

                newBottomRight = new Vector2(
                    Math.Max(Math.Max(topleft.X, bottomRight.X), Math.Max(bottomleft.X, topright.X)),
                    Math.Max(Math.Max(topleft.Y, bottomRight.Y), Math.Max(bottomleft.Y, topright.Y)));
            }
            else
            {
                newTopLeft = new Vector2(Math.Min(Math.Min(topleft.X, bottomRight.X), Math.Min(bottomleft.X, topright.X)),
                    Math.Min(Math.Min(topleft.Y, bottomRight.Y), Math.Min(bottomleft.Y, topright.Y)));

                newBottomRight = new Vector2(
                    Math.Max(Math.Max(topleft.X, bottomRight.X), Math.Max(bottomleft.X, topright.X)),
                    Math.Max(Math.Max(topleft.Y, bottomRight.Y), Math.Max(bottomleft.Y, topright.Y)));
            }

            float rectangleWidth = (float)Math.Abs((float)newTopLeft.X - newBottomRight.X);
            float rectangleHeight = (float)Math.Abs((float)newTopLeft.Y - newBottomRight.Y);

            Vector2 pos = bottomRight - (new Vector2(rectangleWidth, rectangleHeight));
            if (DrawIn == DrawSpace.SCREENSPACE)
            {
                rec = new JabRectangle(newTopLeft.X,
                                        newTopLeft.Y,
                                        rectangleWidth, rectangleHeight);
            }
            else
            {
                newTopLeft /= BaseGame.Get.BackBufferDimensions;
                rec = new JabRectangle(newTopLeft.X, newTopLeft.Y, rectangleWidth / BaseGame.Get.BackBufferWidth, rectangleHeight / BaseGame.Get.BackBufferHeight);
            }
            return rec;
        }
Example #8
0
        public virtual JabRectangle GetRectangle()
        {
            JabRectangle rec;

            if (DrawIn == DrawSpace.SCREENSPACE)
            {
                rec = new JabRectangle((float)TopLeftPosition().X, (float)TopLeftPosition().Y, (float)(Width * ScaleX),
                                       (float)(Height * ScaleY));
            }
            else
            {
                Vector2 topleftpos = TopLeftPosition();
                rec = new JabRectangle(topleftpos.X, topleftpos.Y, (float)(Width * ScaleX * Camera.Get.WorldScale.X), (float)(Height * ScaleY * Camera.Get.WorldScale.Y));
            }

            Vector2 topleft = Vector2.Zero;

            topleft.X = rec.Left;
            topleft.Y = rec.Top;

            Vector2 bottomRight = Vector2.Zero;

            bottomRight.X = rec.Right;
            bottomRight.Y = rec.Bottom;

            Vector2 topright = Vector2.Zero;

            topright.X = rec.Right;
            topright.Y = rec.Top;

            Vector2 bottomleft = Vector2.Zero;

            bottomleft.X = rec.Left;
            bottomleft.Y = rec.Bottom;

            topleft     = JabMath.RotateVectorAround(HandleAdjustedPosition(), topleft, Rot);
            bottomRight = JabMath.RotateVectorAround(HandleAdjustedPosition(), bottomRight, Rot);
            bottomleft  = JabMath.RotateVectorAround(HandleAdjustedPosition(), bottomleft, Rot);
            topright    = JabMath.RotateVectorAround(HandleAdjustedPosition(), topright, Rot);

            Vector2 newTopLeft     = Vector2.Zero;
            Vector2 newBottomRight = Vector2.Zero;

            if (DrawIn == DrawSpace.WORLDSPACE)
            {
                newTopLeft = new Vector2(Math.Min(Math.Min(topleft.X, bottomRight.X), Math.Min(bottomleft.X, topright.X)),
                                         Math.Min(Math.Min(topleft.Y, bottomRight.Y), Math.Min(bottomleft.Y, topright.Y)));

                newBottomRight = new Vector2(
                    Math.Max(Math.Max(topleft.X, bottomRight.X), Math.Max(bottomleft.X, topright.X)),
                    Math.Max(Math.Max(topleft.Y, bottomRight.Y), Math.Max(bottomleft.Y, topright.Y)));
            }
            else
            {
                newTopLeft = new Vector2(Math.Min(Math.Min(topleft.X, bottomRight.X), Math.Min(bottomleft.X, topright.X)),
                                         Math.Min(Math.Min(topleft.Y, bottomRight.Y), Math.Min(bottomleft.Y, topright.Y)));

                newBottomRight = new Vector2(
                    Math.Max(Math.Max(topleft.X, bottomRight.X), Math.Max(bottomleft.X, topright.X)),
                    Math.Max(Math.Max(topleft.Y, bottomRight.Y), Math.Max(bottomleft.Y, topright.Y)));
            }

            float rectangleWidth  = (float)Math.Abs((float)newTopLeft.X - newBottomRight.X);
            float rectangleHeight = (float)Math.Abs((float)newTopLeft.Y - newBottomRight.Y);

            Vector2 pos = bottomRight - (new Vector2(rectangleWidth, rectangleHeight));

            if (DrawIn == DrawSpace.SCREENSPACE)
            {
                rec = new JabRectangle(newTopLeft.X,
                                       newTopLeft.Y,
                                       rectangleWidth, rectangleHeight);
            }
            else
            {
                newTopLeft /= BaseGame.Get.BackBufferDimensions;
                rec         = new JabRectangle(newTopLeft.X, newTopLeft.Y, rectangleWidth / BaseGame.Get.BackBufferWidth, rectangleHeight / BaseGame.Get.BackBufferHeight);
            }
            return(rec);
        }