Intersects() public method

public Intersects ( Rectangle value ) : bool
value Rectangle
return bool
Beispiel #1
0
 public void HandleBulletZombieCollision(Player p, EnemyHandler e)
 {
     foreach (Bullet b in p.bullets)
         if (b.Visible)
         {
             bulletRectangle = new Rectangle((int)b.X, (int)b.Y, 2, 1);
             foreach (ZombieDispenser zd in e.zombies)
                 foreach (Zombie z in zd.zombies)
                     if (z.Visible)
                     {
                         zombieRectangle = new Rectangle((int)(z.X + 18 * z.Scale), (int)(z.Y + 19 * z.Scale), (int)(28 * z.Scale), (int)(45 * z.Scale));
                         zombieHeadRectangle = new Rectangle((int)(z.X + 18 * z.Scale), (int)(z.Y + 4 * z.Scale), (int)(22 * z.Scale), (int)(15 * z.Scale));
                         if (bulletRectangle.Intersects(zombieRectangle))
                         {
                             z.Hitpoints -= bulletDmg;
                             b.SprayBlood = true;
                             b.Visible = false;
                         }
                         else if(bulletRectangle.Intersects(zombieHeadRectangle))
                         {
                             z.Hitpoints = 0;
                             p.Score += 5;
                             b.SprayBlood = true;
                             b.Visible = false;
                         }
                     }
         }
 }
 public Screen Mouseclik(int x, int y)
 {
     Rectangle mouserec = new Rectangle(x, y, 10, 10);
     if (mouserec.Intersects(world1rect))
     {
         VibrateController vc = VibrateController.Default;
         vc.Start(TimeSpan.FromMilliseconds(100));
         return (Screen.ChooseLevelScreen);
     }
     else if (mouserec.Intersects(world2rect))
     {
         VibrateController vc = VibrateController.Default;
         vc.Start(TimeSpan.FromMilliseconds(100));
         return (Screen.ChooseLevelScreen2);
     }
     else if (mouserec.Intersects(world3rect))
     {
         VibrateController vc = VibrateController.Default;
         vc.Start(TimeSpan.FromMilliseconds(100));
         return (Screen.ChooseLevelScreen3);
     }
     else if (mouserec.Intersects(backbuttonw))
     {
         VibrateController vc = VibrateController.Default;
         vc.Start(TimeSpan.FromMilliseconds(100));
         return (Screen.StartScreen);
     }
     return (Screen.ChooseWorldScreen);
 }
        public static bool HasCollisionWithObject(Player player, int targetPositionX, int targetPositionY, Map map, Vector2 mapPosition)
        {
            Rectangle playerRect = new Rectangle(targetPositionX, targetPositionY, player.Image.Width,
                player.Image.Height);

            foreach(var mapElement in map.MapElements)
            {
                var mapElementRect = new Rectangle(mapElement.TopLeftX + (int) mapPosition.X,
                                                   mapElement.TopLeftY + (int) mapPosition.Y,
                                                   mapElement.Image.Width,
                                                   mapElement.Image.Height);

                if (playerRect.Intersects(mapElementRect))
                {
                    return true;
                }
            }

            foreach (var mapCreature in map.MapCreatures)
            {
                var mapCreatureRect = new Rectangle(mapCreature.TopLeftX + (int)mapPosition.X,
                                                   mapCreature.TopLeftY + (int)mapPosition.Y,
                                                   mapCreature.Image.Width,
                                                   mapCreature.Image.Height);

                if (playerRect.Intersects(mapCreatureRect))
                {
                    return true;
                }
            }

            return false;
        }
Beispiel #4
0
 void MouseClicked(int x, int y, ref GameType gametype)
 {
     mouseClick = new Rectangle(x, y, 10, 10);
     if (mouseClick.Intersects(Bouton_Play))
     {
         gametype = GameType.Menu_Play_Type;
     }
     else if (mouseClick.Intersects(Bouton_Exit))
     {
         Game1.GetGame().Exit();
     }
     else if (mouseClick.Intersects(Bouton_Res))
     {
         gametype = GameType.Menu_Option_Type;
     }
     else if (mouseClick.Intersects(Bouton_Full))
     {
         Game1.GetGame().IsFullScreen = !Game1.GetGame().IsFullScreen;
     }
     else if (mouseClick.Intersects(Bouton_Sound))
     {
         SoundEffect.MasterVolume = 1.0f - SoundEffect.MasterVolume;
         MediaPlayer.Volume = 1.0f - MediaPlayer.Volume;
     }
 }
Beispiel #5
0
 public Screen Mouseclik(int x, int y)
 {
     Rectangle mouserec = new Rectangle(x, y, 10, 10);
     if (mouserec.Intersects(world1rect))
     {
         current = Screen.ChooseLevelScreen;
         return (current);
     }
     else if (mouserec.Intersects(world2rect))
     {
         current = Screen.ChooseLevelScreen2;
         return (current);
     }
     else if (mouserec.Intersects(world3rect))
     {
         current = Screen.ChooseLevelScreen3;
         return (current);
     }
     else if (mouserec.Intersects(backbuttonw))
     {
         current = Screen.StartScreen;
         return (current);
     }
     return (current);
 }
Beispiel #6
0
        public void checkPaddleCollision(Rectangle paddle, SoundEffectInstance soundEngineInstance)
        {
            Rectangle ballLocation = new Rectangle((int)position.X, (int)position.Y,
                sprite.Width, sprite.Height);

            if (paddle.Intersects(ballLocation) && !inCollision)
            {
                inCollision = true;

                // La balle émet le son approprié
                soundEngineInstance.Volume = 0.75f;
                soundEngineInstance.Play();

                //Collision avec le top de la palette
                if (ballLocation.Intersects(new Rectangle(paddle.X, paddle.Y, paddle.Width, 0)))
                {
                    direction.Y *= -1;
                    position.Y = paddle.Y - sprite.Height;

                    float paddleCenter = paddle.X + (paddle.Width/2);
                    float ballCenter = position.X + sprite.Width/2;
                    direction.X = (ballCenter - paddleCenter) / (paddle.Width / 2);
                    direction = Vector2.Normalize(direction);
                }

            }
            else if(!paddle.Intersects(ballLocation))
                inCollision = false;
        }
Beispiel #7
0
        void MouseClicked(int x, int y, ref GameType gameType)
        {
            mouseClick = new Rectangle(x, y, 10, 10);

            if (mouseClick.Intersects(Bouton_Play))
            {
                gameType = GameType.Menu_Play_Type;
            }
            if (mouseClick.Intersects(Bouton_Exit))
            {
                Game1.GetGame().Exit();
            }
            if (mouseClick.Intersects(Bouton_Options))
            {
                gameType = GameType.Menu_Option_Type;
            }

            if (mouseClick.Intersects(Bouton_Solo))
            {
                gameType = GameType.Menu_Play_Solo_Type;
            }
            if (mouseClick.Intersects(host))
            {
                System.Diagnostics.Process.Start("C:/Users/epita/Desktop/Final/zbra/bin/Debug/zbra.exe");
            }
            if (mouseClick.Intersects(join))
            {
                System.Diagnostics.Process.Start("C:/Users/epita/Desktop/Final/Client/bin/Debug/Client.exe");
            }
            if (mouseClick.Intersects(local))
            {
                gameType = GameType.Menu_Play_Multi_Type;
            }
        }
Beispiel #8
0
        public static Direction GetCollidingSide(Rectangle rectangle)
        {
            if (!IsCollidingWithSide(rectangle))
            {
                return Direction.NONE;
            }
            var left = new Rectangle((int)Position.X - 1, (int)Position.Y, 2, 600);
            var right = new Rectangle((int)Position.X + 799, (int)Position.Y, 2, 600);

            var top = new Rectangle((int)Position.X, (int)Position.Y - 1, 800, 2);
            var bottom = new Rectangle((int)Position.X, (int)Position.Y + 599, 800, 2);

            if (rectangle.Intersects(left))
            {
                return Direction.LEFT;
            }

            if (rectangle.Intersects(right))
            {
                return Direction.RIGHT;
            }

            if (rectangle.Intersects(top))
            {
                return Direction.UP;
            }

            if (rectangle.Intersects(bottom))
            {
                return Direction.DOWN;
            }

            return Direction.NONE;
        }
Beispiel #9
0
        public void Update(GameTime gameTime)
        {
            Pad rightPlayer = PongGame.GameWorld.rightPlayer; //copy by reference
            Pad leftPlayer = PongGame.GameWorld.leftPlayer;

            //making collision mask
            ballRect = new Rectangle((int)(position.X-origin.X), (int)(position.Y-origin.Y), ballTex.Width, ballTex.Height);

            //position update
            position.X += velocity.X;
            position.Y += velocity.Y;

            //collision check
            if (position.Y - origin.Y < 0 || position.Y + origin.Y > PongGame.GameDimensions.Y)
            {
                velocity.Y *= -1;
            }

            if (ballRect.Intersects(rightPlayer.padRect) && (lastIntersectID == 0 || lastIntersectID == -1))
            {
                velocity.X *= (-1 + (position.Y - (rightPlayer.position.Y + rightPlayer.origin.Y)) * bounceMod);
                lastIntersectID = 1;
            }

            if (ballRect.Intersects(leftPlayer.padRect) && (lastIntersectID == 1 || lastIntersectID == -1))
            {
                velocity.X *= (-1 + (position.Y - (leftPlayer.position.Y + leftPlayer.origin.Y)) * bounceMod);
                lastIntersectID = 0;
            }
        }
Beispiel #10
0
        public void UpdateButtons(GameTime GameTime)
        {
            bool pressed = Input.MousePressed(MouseButtons.Left);
            bool released = Input.MouseReleased(MouseButtons.Left);
            Rectangle mouseCurrent = new Rectangle((int)Input.MousePosition.X, (int)Input.MousePosition.Y, 5, 5);
            Rectangle mousePrevious = new Rectangle((int)Input.MousePositionPrevious.X, (int)Input.MousePositionPrevious.Y, 5, 5);

            foreach (Button button in _Buttons)
            {
                if (mouseCurrent.Intersects(button.CollisionBox))
                {
                    // Pressed
                    if (Input.MousePressed(MouseButtons.Left))
                        button.OnPressed();
                    // Released
                    else if (Input.MouseReleased(MouseButtons.Left))
                        button.OnReleased();
                    // On Enter
                    else if (mousePrevious.Intersects(button.CollisionBox) == false)
                        button.OnEnter();
                    // On Hover
                    else
                        button.OnHover();
                }
                // On Exit
                else if (mousePrevious.Intersects(button.CollisionBox))
                {
                    button.OnExit();
                }
            }
        }
Beispiel #11
0
        public Screen Mouseclik(int x, int y)
        {
            Rectangle mouserec = new Rectangle(x, y, 10, 10);
            if (mouserec.Intersects(level1rect))
            {
                GlobalVar.texture = "textsable";
                GlobalVar.xmlfile = "pets";
                GlobalVar.sound = "grassland";
                current = Screen.GamePlayScreen;
            }
            else if (mouserec.Intersects(level2rect))
            {
                GlobalVar.texture = "textg";
                GlobalVar.xmlfile = "Level";
                GlobalVar.sound = "grassland";
                current = Screen.GamePlayScreen;
            }
            else if (mouserec.Intersects(level3rect))
            {

                GlobalVar.texture = "textsable";
                GlobalVar.xmlfile = "Level";
                GlobalVar.sound = "grassland";
                current = Screen.GamePlayScreen;
            }
            else if (mouserec.Intersects(backbutton))
            {
                current = Screen.ChooseWorldScreen;
            }
            return (current);
        }
Beispiel #12
0
        public void MouseClicked(int x, int y, GameMaster sender)
        {
            Rectangle mouseClickRect = new Rectangle(x, y, 10, 10);

            //int resumeWidth = resumeButton.Width / 2;
            //int resumeHeight = resumeButton.Height / 2;

            Rectangle resumeButtonRect = new Rectangle(screenCenter.X - (resumeButton.Width / 2), 400, resumeButton.Width, resumeButton.Height);

            //int quitGameWidth = quitGameButton.Width / 2;
            //int quitGameHeight = quitGameButton.Height / 2;

            Rectangle quitGameButtonRect = new Rectangle(screenCenter.X - (quitGameButton.Width / 2), 500, quitGameButton.Width, quitGameButton.Height);

            if (mouseClickRect.Intersects(resumeButtonRect))
            {
                sender.gameState = PacManMulti.GameMaster.GameState.Playing;
                sender.restart = false;
                sender.isPaused = false;
            }
            else if (mouseClickRect.Intersects(quitGameButtonRect))
            {
                sender.gameState = PacManMulti.GameMaster.GameState.StartMenu;
                sender.restart = true;
                sender.isPaused = false;
            }
        }
Beispiel #13
0
        public void MouseClicked(int x, int y, ref GameType gameType)
        {
            mouseClick = new Rectangle(x, y, 10, 10);

            if (mouseClick.Intersects(Bouton_Exit))
            {
                Game1.GetGame().Exit();
            }
            else if (mouseClick.Intersects(Bouton_Options))
            {
                gameType = GameType.Menu_Option_Type;
            }
            else if (mouseClick.Intersects(Bouton_Multi))
            {
                gameType = GameType.Menu_Play_Multi_Type;
            }
            else if (mouseClick.Intersects(Bouton_Play))
            {
                gameType = GameType.Menu_Play_Type;
            }
            else if (mouseClick.Intersects(Bouton_Solo))
            {
                gameType = GameType.Menu_Play_Solo_Type;
            }
        }
Beispiel #14
0
        public bool Intersects(Rectangle rec)
        {
            int BoundHeight = (int)EndPos.Y - (int)StartPos.Y;
            int BoundWidth =(int)EndPos.X - (int)StartPos.X;

            if (rec.Intersects(new Rectangle((int)StartPos.X, (int)StartPos.Y, BoundWidth == 0 ? 1 : BoundWidth, BoundHeight == 0 ? 1 : BoundHeight)))
                return true;
            return rec.Intersects(new Rectangle((int)StartPos.X, (int)StartPos.Y, BoundWidth == 0 ? 1 : BoundWidth, BoundHeight == 0 ? 1 : BoundHeight));
        }
Beispiel #15
0
 public void Update()
 {
     mousePosition = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
     Cursor_Rectangle = new Rectangle(Convert.ToInt32(mousePosition.X + mouseSpeed.X), Convert.ToInt32(mousePosition.Y + mouseSpeed.Y), Cursor_Texture.Width, Cursor_Texture.Height);
     if (Cursor_Rectangle.Intersects(Game_Rectangle) && Mouse.GetState().LeftButton == ButtonState.Pressed) { Menu_State = false; Bool_Play = true; Bool_Save = false; Bool_Load = false; }
     else if (Cursor_Rectangle.Intersects(Exit_Rectangle) && Mouse.GetState().LeftButton == ButtonState.Pressed) { Exit = true; }
     else if (Cursor_Rectangle.Intersects(Save_Rectangle) && Mouse.GetState().LeftButton == ButtonState.Pressed) { Bool_Save = true; Bool_Load = false; Bool_Play = false; }
     else if (Cursor_Rectangle.Intersects(Load_Rectangle) && Mouse.GetState().LeftButton == ButtonState.Pressed) { Bool_Load = true; Bool_Save = false; Bool_Play = false; }
 }
Beispiel #16
0
 public override bool isCollidingPosition(Microsoft.Xna.Framework.Rectangle position, xTile.Dimensions.Rectangle viewport, bool isFarmer, int damagesFarmer, bool glider, Character character)
 {
     if ((bool)landslide && position.Intersects(landSlideRect))
     {
         return(true);
     }
     if ((bool)railroadAreaBlocked && position.Intersects(railroadBlockRect))
     {
         return(true);
     }
     return(base.isCollidingPosition(position, viewport, isFarmer, damagesFarmer, glider, character));
 }
Beispiel #17
0
 public override bool isCollidingPosition(Microsoft.Xna.Framework.Rectangle position, xTile.Dimensions.Rectangle viewport, bool isFarmer, int damagesFarmer, bool glider, Character character)
 {
     if (_exitsBlocked && position.Intersects(turtle1Spot))
     {
         return(true);
     }
     if (!westernTurtleMoved && position.Intersects(turtle2Spot))
     {
         return(true);
     }
     return(base.isCollidingPosition(position, viewport, isFarmer, damagesFarmer, glider, character));
 }
Beispiel #18
0
        public override void Update(GameTime gameTime)
        {
            Rectangle mouseRect = new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1);
            mIsColliding = mouseRect.Intersects(mPosition) && Mouse.GetState().LeftButton == ButtonState.Pressed;
            if (mouseRect.Intersects(mPosition) || selectedIndex == index)
            {
                mPosition = new Rectangle(mPosition.X, mPosition.Y, mImage.Width, mImage.Height);
            }
            else
            {
                mPosition = new Rectangle(mPosition.X, mPosition.Y, (int)(mImage.Width * 0.7f), (int)(mImage.Height * 0.7f));
            }

            base.Update(gameTime);
        }
Beispiel #19
0
        public virtual void Update()
        {
            try
            {
                TouchCollection touches = TouchPanel.GetState();                    //enable touches
                foreach (TouchLocation t in touches)
                {

                    gestureLocation = t.Position;                                     //assign toch point to gesture location
                    gestureBoundingBox = new Rectangle((int)gestureLocation.X         //make 1x1 box for touch point
                        , (int)gestureLocation.Y,
                        1,
                        1);



                    if (t.State == TouchLocationState.Pressed)           //loop through all btn if any btn is pressed then change its color
                    {
                        for (int i = 0; i < index; i++)
                        {
                            if (gestureBoundingBox.Intersects(btnBoundingBoxes[i]))
                            {
                                btnColor[i] = Color.Teal;
                                break;

                            }
                        }
                    }

                    else if (t.State == TouchLocationState.Released)            //on releasing if gester pos still intesects btn then 
                    //assign index value to selector and changes its color to default
                    {
                        for (int i = 0; i < index; i++)
                        {
                            btnColor[i] = Color.White;
                            if (gestureBoundingBox.Intersects(btnBoundingBoxes[i]))
                            {
                                selecter = i;
                                SoundManager.soundManager.btnClick.Play();
                                break;
                            }
                        }
                    }
                }
            }
            catch(Exception e){}

        }
Beispiel #20
0
        public void Update(Microsoft.Xna.Framework.Rectangle mouseRectangle, float scaleX, float scaleY)
        {
            this.rectangle   = new Microsoft.Xna.Framework.Rectangle((int)((float)this.originalRectangle.X * scaleX), (int)((float)this.originalRectangle.Y * scaleY), (int)((float)this.originalRectangle.Width * scaleX), (int)((float)this.originalRectangle.Height * scaleY));
            this.isHovered   = false;
            this.isActivated = false;
            MouseState state = Mouse.GetState();

            if (mouseRectangle.Intersects(this.rectangle))
            {
                this.isHovered = true;
            }
            if (this.isHovered)
            {
                if (state.LeftButton == ButtonState.Pressed)
                {
                    this.isActivated = true;
                    if (this.canSound)
                    {
                        this.click.Play();
                        this.canSound            = false;
                        this.incrementSoundTimer = true;
                    }
                }
            }
            if (this.incrementSoundTimer)
            {
                this.soundTimer++;
                if (this.soundTimer == 50)
                {
                    this.incrementSoundTimer = false;
                    this.soundTimer          = 0;
                    this.canSound            = true;
                }
            }
        }
Beispiel #21
0
        public static bool PlaceEmptyRectangle(RectangleF rr)
        {
            foreach (RoomLayer rl in roomLayers)
            {
                if (rl.Visible)
                {
                    if (rl is ObjectLayer)
                    {
                        ObjectLayer ol = (ObjectLayer)rl;
                        foreach (GameObject g in ol.Objects)
                        {
                            if (g == currentObject)
                            {
                                continue;
                            }

                            RectangleF r = new Rectangle((int)g.Position.X, (int)g.Position.Y, g.Sprite.ImageRectangle.Width, g.Sprite.ImageRectangle.Height);
                            if (r.Intersects(rr))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            return(true);
        }
Beispiel #22
0
        public void Update(GameTime gameTime, OverworldSprite player)
        {
            if(state == "Solid")
            {
                Rectangle tileRect = new Rectangle((int)Position.X + 6, (int)Position.Y + 13,
                    sourceRect.Width - 12, sourceRect.Height - 12);
                Rectangle playerRect = new Rectangle((int)player.Image.Position.X,
                    (int)player.Image.Position.Y, player.Image.SourceRect.Width, player.Image.SourceRect.Height);
                //here we implement the collision
                if (playerRect.Intersects(tileRect))
                {
                    if (isShopkeeper)
                    {
                        //TO DO: IMPLEMENTATION
                        //trigger the event/open the trading screen
                    }

                    //if the solid tile and the player's rectancgles collide we tell where to put the player in the next frame
                    if (player.Velocity.X < 0)//moving left
                        player.Image.Position.X = tileRect.Right;
                    else if (player.Velocity.X > 0)
                        player.Image.Position.X = tileRect.Left - player.Image.SourceRect.Width;
                    else if (player.Velocity.Y < 0)
                        player.Image.Position.Y = tileRect.Bottom;
                    else
                        player.Image.Position.Y = tileRect.Top - player.Image.SourceRect.Height;

                    //Stop the player from moving.
                    player.Velocity = Vector2.Zero;
                }
            }
        }
        internal static Rectangle UpdateCollision(this GameObject gameObject, Rectangle Destination, Rectangle old, MapObject currentMap)
        {
            foreach (GameTile tile in currentMap.Tiles)
            {
                if (tile.ValidTile && Destination.Intersects(tile.Destination))
                {

                    Rectangle newDestinationXOnly = new Rectangle(Destination.X, old.Y, gameObject.Width, gameObject.Height);
                    Rectangle newDestinationYOnly = new Rectangle(old.X, Destination.Y, gameObject.Width, gameObject.Height);
                    if (newDestinationXOnly.Intersects(tile.Destination))
                    {
                        Destination.X = old.X;
                    }

                    if (newDestinationYOnly.Intersects(tile.Destination))
                    {

                        Destination.Y = old.Y;

                        if (gameObject.Center.Y < tile.Destination.Y)
                        {
                            gameObject.IsJumping = false;
                            gameObject.CurrentSpeed = 0;
                        }
                    }
                }
            }

            return Destination;
        }
Beispiel #24
0
 public bool CanPlace(Microsoft.Xna.Framework.Rectangle area, bool[] validTiles, int padding = 0)
 {
     lock (this._lock)
     {
         if (area.X < 0 || area.Y < 0 || (area.X + area.Width > Main.maxTilesX - 1 || area.Y + area.Height > Main.maxTilesY - 1))
         {
             return(false);
         }
         Microsoft.Xna.Framework.Rectangle rectangle = new Microsoft.Xna.Framework.Rectangle(area.X - padding, area.Y - padding, area.Width + padding * 2, area.Height + padding * 2);
         for (int index = 0; index < this._protectedStructures.Count; ++index)
         {
             if (rectangle.Intersects(this._protectedStructures[index]))
             {
                 return(false);
             }
         }
         for (int x = rectangle.X; x < rectangle.X + rectangle.Width; ++x)
         {
             for (int y = rectangle.Y; y < rectangle.Y + rectangle.Height; ++y)
             {
                 if (Main.tile[x, y].active())
                 {
                     ushort type = Main.tile[x, y].type;
                     if (!validTiles[(int)type])
                     {
                         return(false);
                     }
                 }
             }
         }
         return(true);
     }
 }
        public static bool Collide(IShip shipColliding, IProjectile ball)
        {
            Rectangle shipRect = new Rectangle(
               (int)shipColliding.Position.X + COLLISION_OFFSET,
               (int)shipColliding.Position.Y + COLLISION_OFFSET,
               shipColliding.FrameSize.X - (COLLISION_OFFSET * 2),
               shipColliding.FrameSize.Y - (COLLISION_OFFSET * 2));

            Rectangle cannonBall = new Rectangle(
                (int)ball.Position.X + COLLISION_OFFSET,
                (int)ball.Position.Y + COLLISION_OFFSET,
                ball.FrameSize.X - (COLLISION_OFFSET * 2),
                ball.FrameSize.Y - (COLLISION_OFFSET * 2));

            if (shipRect.Intersects(cannonBall))
            {
                ball.Position = new Vector2(9999,9999); // might be buggy
                return true;
            }
            if (ball.Position.Y >= ball.BallFiredPos.Y)
            {
                ball.Position = new Vector2(999,999);
            }

            return false;
        }
Beispiel #26
0
        public override void Update(GameTime gameTime)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
            boundingBox = new Rectangle((int)Position.X, (int)Position.Y, sprW - 5, sprH - 10);
            //Console.WriteLine("dir: " + Dir);
            if (Dir < 0)
            { //left
                Position -= new Vector2(elapsed, 0) * 100;
            }
            else
            {
                Position += new Vector2(elapsed, 0) * 100;
            }
            base.Update(gameTime);
            foreach (var c in Game.Components)
            {
                Ground b = c as Ground;
                if (b != null)
                {
                    if (boundingBox.Intersects(b.bb) && (boundingBox.Top > b.bb.Top) && (boundingBox.Left > b.bb.Left) && ((b.type == 1) || (b.type == 2) || (b.type == 3)))
                    {
                        spr = new Rectangle(0, 0, 0, 0);
                        Position = new Vector2(0, 0);
                    }

                    if (boundingBox.Top < 50 || boundingBox.Left < 25 || boundingBox.Right >= 800)
                    {
                        spr = new Rectangle(0, 0, 0, 0);

                        Position = new Vector2(0, 0);
                    }
                }
            }
        }
Beispiel #27
0
        public static bool CheckCollision(Rectangle rect_A, Color[] coul_A, Rectangle rect_B, Color[] coul_B)
        {
            if (rect_A.Intersects(rect_B))
            {
                int top = Math.Max(rect_A.Top, rect_B.Top);
                int bottom = Math.Min(rect_A.Bottom, rect_B.Bottom);
                int left = Math.Max(rect_A.Left, rect_B.Left);
                int right = Math.Min(rect_A.Right, rect_B.Right);

                for (int y = top; y < bottom; y++)
                {
                    for (int x = left; x < right; x++)
                    {
                        Color colorA = coul_A[(x - rect_A.Left) + (y - rect_A.Top) * rect_A.Width];
                        Color colorB = coul_A[(x - rect_B.Left) + (y - rect_B.Top) * rect_B.Width];

                        if (colorA.A != 0 && colorB.A != 0)
                        {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
Beispiel #28
0
 public List<Tile> GetCollision(Rectangle objBoundingBox)
 {
     //lock (this)
     {
         List<Tile> collisionTiles;
         collisionTiles = new List<Tile>();
         bool lastlayer = false;
         iterateNodes = new List<QuadTreeNode>();
         iterateNodes.Add(rootNode);
         current_rects = new List<Rectangle>();
         if (objBoundingBox.Intersects(levelBoundingBox))
         {
             while (lastlayer == false)
             {
                 iterateNodes = GetIntersectingChildNodes(iterateNodes, objBoundingBox);
                 foreach (QuadTreeNode node in iterateNodes)
                 {
                     if (node.IsLastLayer)
                     {
                         collisionTiles = collisionTiles.Union(node.LevelTiles).ToList();
                         current_rects.Add(node.GetRect);
                         lastlayer = true;
                     }
                 }
             }
         }
         return collisionTiles;
     }
 }
Beispiel #29
0
 public void Update(MouseState mouse)
 {
     rectangle = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);
     Rectangle mouseRect = new Rectangle(mouse.X, mouse.Y, 1, 1);
     if (mouseRect.Intersects(rectangle))
     {
         if (color.A == 255)
         {
             down = false;
         }
         if (color.A == 0)
         {
             down = true;
         }
         if (down ==  true)
         {
             color.A += 3;
         }
         else
         {
             color.A -= 3;
         }
         if (mouse.LeftButton == ButtonState.Pressed)
         {
             isClicked = true;
         }
     }
     else if(color.A <255)
     {
         color.A += 3;
         isClicked = false;
     }
 }
Beispiel #30
0
        public void Update(MouseState mouse)
        {
            if (Enabled == true)
            {
                rectangle = new Rectangle((int)position.X, (int)position.Y,
                    (int)size.X, (int)size.Y);

                Rectangle mouseRectangle = new Rectangle(mouse.X, mouse.Y, 1, 1);

                if (mouseRectangle.Intersects(rectangle))
                {
                   
                    if (mouse.LeftButton == ButtonState.Pressed)
                    {
                        isClicked = true;
                        isSelected = true;
                        
                        
                    }

                }
                else 
                {
                    isClicked = false;
                }
                if (isSelected==true & isClicked==true)
                {
                   
                    Count();
                }
            }
            wasSelected = isSelected;

            count++;
        }
        public static void UpdateProbabilities(FishingRod rod)
        {
            if (rod.isFishing)
            {
                if (_isFirstTimeOfFishing)
                {
                    Logger.Log("Examine fishing probability");

                    _isFirstTimeOfFishing = false;
                    GameLocation location = Game1.currentLocation;

                    Rectangle rectangle          = new Rectangle(location.fishSplashPoint.X * 64, location.fishSplashPoint.Y * 64, 64, 64);
                    Rectangle value              = new Rectangle((int)rod.bobber.X - 80, (int)rod.bobber.Y - 80, 64, 64);
                    bool      flag               = rectangle.Intersects(value);
                    int       clearWaterDistance = Reflection.GetField <int>(rod, "clearWaterDistance").GetValue();

                    _fishingDictionary = GetFishes(location, rod.attachments[0]?.ParentSheetIndex ?? -1, clearWaterDistance + (flag ? 1 : 0), Game1.player, InstanceHolder.Config.MorePreciseProbabilities ? InstanceHolder.Config.TrialOfExamine : 1);
                }
            }
            else
            {
                _isFirstTimeOfFishing = true;
                _fishingDictionary    = null;
            }
        }
Beispiel #32
0
        public override void Update(GameTime gameTime)
        {
            //base.Update(gameTime);

            Duration -= gameTime.ElapsedGameTime.Milliseconds;

            Rectangle PowerupRect = new Rectangle((int)Location.X - (UpgradeTexture.Width / 2), (int)Location.Y - (UpgradeTexture.Height / 2), UpgradeTexture.Width, UpgradeTexture.Height);
            Rectangle PlayerRect = new Rectangle((int)PlayerShip.Location.X - (PlayerShip.spriteTexture.Width / 2), (int)PlayerShip.Location.Y - (PlayerShip.spriteTexture.Height / 2), PlayerShip.spriteTexture.Width, PlayerShip.spriteTexture.Height);

            if (Duration <= 0)
            {
                ShotList.Add(this);
            }

            if (PowerupRect.Intersects(PlayerRect))
            {
                GamePowerupManager.Collision = true;

                if (GamePowerupManager.SlotOne == (int)UpgradeTypes.Empty)
                {
                    GamePowerupManager.SlotOne = UpgradeID;
                }
                else if (GamePowerupManager.SlotTwo == (int)UpgradeTypes.Empty)
                {
                    GamePowerupManager.SlotTwo = UpgradeID;
                }

                ShotList.Add(this);
            }
        }
Beispiel #33
0
        public bool intersectsTarget(Rectangle targetRec)
        {
            Rectangle bulletRec = new Rectangle((int)_bulletPos.X, (int)_bulletPos.Y, _bulletText.Width, _bulletText.Height);

            if (targetRec.Intersects(bulletRec))return true;
            else return false;
        }
 public void HandleBombsIntersection(Player p, BuildingHandler bh, ContentManager theContentManager)
 {
     if (p.bombs.Count > 0)
     {
         foreach (Bomb b in p.bombs)
         {
             bombRectangle = new Rectangle((int)b.X, (int)b.Y, 20, 20); //TODO: width, height if needed
             foreach (Building building in bh.buildings)
             {
                 buildingRectangle = new Rectangle((int)building.X, (int)building.Y - building.H + 10, building.W, building.H);
                 if (bombRectangle.Intersects(buildingRectangle))
                 {
                     building.Damaged = true;
                     p.score.AddPoints(50);
                     p.eh.CreateExplosion("huge", new Vector2(b.X - 48, b.Y - 16), theContentManager);
                     p.bombs.Remove(b);
                     bombRemoved = true;
                 }
             }
             if (bombRemoved)
             {
                 bombRemoved = false;
                 break;
             }
         }
     }
 }
Beispiel #35
0
 bool ISolid.CollidesWith(Rectangle box)
 {
     if (!Activated || activatedTime < deactivateTime)
         return box.Intersects(TranslatedBoundingBox);
     else
         return false;
 }
        public bool IntersectPerPixelBottom(
            Rectangle rect1, Color[] data1,
            Rectangle rect2, Color[] data2)
        {
            if (rect1.Intersects(rect2))
                return true;
            //int top = Math.Max(rect1.Top, rect2.Top);
            //int bottom = Math.Min(rect1.Bottom, rect2.Bottom);
            //int left = Math.Max(rect1.Left, rect2.Left);
            //int right = Math.Min(rect1.Right, rect2.Right);

            //for (int y = bottom; y > top; y--)
            //{
            //    for (int x = left; x < right; x++)
            //    {
            //        Color color1 = data1[(x - rect1.Left) + ((rect1.Bottom - y) * rect1.Width)];
            //        Color color2 = data2[(x - rect2.Left) + ((rect2.Bottom - y) * rect2.Width)];

            //        if ((color1.A != 0) &&
            //            (color2.A != 0))
            //        {
            //            if ((rect1.Bottom > rect2.Top) &&
            //                (rect1.Bottom < rect2.Bottom) &&
            //                (rect1.Top < rect2.Top))
            //            {
            //                return true;
            //            }
            //        }
            //    }
            //}

            return false;
        }
Beispiel #37
0
        public static bool GameLocation_performAction_Prefix(GameLocation __instance, string action, Farmer who, ref bool __result, Location tileLocation)
        {
            try
            {
                if (action != null && who.IsLocalPlayer)
                {
                    string[] actionParams = action.Split(new char[]
                    {
                        ' '
                    });
                    string text    = actionParams[0];
                    Regex  pattern = new Regex(@"Crib[0-9][0-9]*");
                    if (pattern.IsMatch(text))
                    {
                        int crib = int.Parse(text.Substring(4));
                        Monitor.Log($"Acting on crib {crib+1}");

                        Microsoft.Xna.Framework.Rectangle rect = new Microsoft.Xna.Framework.Rectangle((ModEntry.config.ExistingKidsRoomOffsetX + 15) * 64 + (3 * crib * 64), (ModEntry.config.ExistingKidsRoomOffsetY + 2) * 64, 3 * 64, 4 * 64);
                        using (List <NPC> .Enumerator enumerator = __instance.characters.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                NPC j = enumerator.Current;
                                if (j is Child)
                                {
                                    if (rect.Intersects(j.GetBoundingBox()))
                                    {
                                        if ((j as Child).Age == 1)
                                        {
                                            Monitor.Log($"Tossing {j.Name}");
                                            (j as Child).toss(who);
                                        }
                                        else if ((j as Child).Age == 0)
                                        {
                                            Monitor.Log($"{j.Name} is sleeping");
                                            Game1.drawObjectDialogue(Game1.parseText(Game1.content.LoadString("Strings\\Locations:FarmHouse_Crib_NewbornSleeping", j.displayName)));
                                        }
                                        else if ((j as Child).isInCrib() && (j as Child).Age == 2)
                                        {
                                            Monitor.Log($"acting on {j.Name}");
                                            return(j.checkAction(who, __instance));
                                        }
                                        __result = true;
                                        return(false);
                                    }
                                }
                            }
                        }
                        __result = true;
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                Monitor.Log($"Failed in {nameof(ManorHouse_performAction_Prefix)}:\n{ex}", LogLevel.Error);
            }
            return(true);
        }
Beispiel #38
0
 public override bool isCollidingPosition(Microsoft.Xna.Framework.Rectangle position, xTile.Dimensions.Rectangle viewport, bool isFarmer, int damagesFarmer, bool glider, Character character)
 {
     if (this.oldMariner != null && position.Intersects(this.oldMariner.GetBoundingBox()))
     {
         return(true);
     }
     return(base.isCollidingPosition(position, viewport, isFarmer, damagesFarmer, glider, character));
 }
Beispiel #39
0
 public override bool isCollidingPosition(Microsoft.Xna.Framework.Rectangle position, xTile.Dimensions.Rectangle viewport, bool isFarmer, int damagesFarmer, bool glider, Character character)
 {
     if (!caveOpened && boulderPosition.Intersects(position))
     {
         return(true);
     }
     return(base.isCollidingPosition(position, viewport, isFarmer, damagesFarmer, glider, character));
 }
Beispiel #40
0
 public void ApplyUnsafeMapOverride(string override_map, Microsoft.Xna.Framework.Rectangle?source_rect, Microsoft.Xna.Framework.Rectangle dest_rect)
 {
     ApplyMapOverride(override_map, source_rect, dest_rect);
     Microsoft.Xna.Framework.Rectangle nontile_rect = new Microsoft.Xna.Framework.Rectangle(dest_rect.X * 64, dest_rect.Y * 64, dest_rect.Width * 64, dest_rect.Height * 64);
     if (this == Game1.player.currentLocation && nontile_rect.Intersects(Game1.player.GetBoundingBox()) && Game1.player.currentLocation.isCollidingPosition(Game1.player.GetBoundingBox(), Game1.viewport, isFarmer: true, 0, glider: false, Game1.player))
     {
         Game1.player.TemporaryPassableTiles.Add(nontile_rect);
     }
 }
Beispiel #41
0
 public override bool isCollidingPosition(Microsoft.Xna.Framework.Rectangle position, xTile.Dimensions.Rectangle viewport, bool isFarmer, int damagesFarmer, bool glider, Character character, bool pathfinding, bool projectile = false, bool ignoreCharacterRequirement = false)
 {
     foreach (KeyValuePair <long, FarmAnimal> animal in (Dictionary <long, FarmAnimal>) this.animals)
     {
         if (character != null && !character.Equals((object)animal.Value) && position.Intersects(animal.Value.GetBoundingBox()))
         {
             animal.Value.farmerPushing();
             return(true);
         }
     }
     return(base.isCollidingPosition(position, viewport, isFarmer, damagesFarmer, glider, character, pathfinding, false, false));
 }
Beispiel #42
0
        public virtual bool CheckCollisions(Microsoft.Xna.Framework.Rectangle rectangle)
        {
            int wall_width = 16;

            if (rectangle.Intersects(new Microsoft.Xna.Framework.Rectangle((int)position.X, (int)position.Y, 192, wall_width)))
            {
                return(true);
            }
            if (rectangle.Intersects(new Microsoft.Xna.Framework.Rectangle((int)position.X, (int)position.Y + 128 - wall_width, 64, wall_width)))
            {
                return(true);
            }
            if (rectangle.Intersects(new Microsoft.Xna.Framework.Rectangle((int)position.X + 128, (int)position.Y + 128 - wall_width, 64, wall_width)))
            {
                return(true);
            }
            if (takeoffState > TakeoffState.Idle && rectangle.Intersects(new Microsoft.Xna.Framework.Rectangle((int)position.X + 64, (int)position.Y + 128 - wall_width, 64, wall_width)))
            {
                return(true);
            }
            if (rectangle.Intersects(new Microsoft.Xna.Framework.Rectangle((int)position.X, (int)position.Y, wall_width, 128)))
            {
                return(true);
            }
            if (rectangle.Intersects(new Microsoft.Xna.Framework.Rectangle((int)position.X + 192 - wall_width, (int)position.Y, wall_width, 128)))
            {
                return(true);
            }
            return(false);
        }
Beispiel #43
0
        public static bool checkCollision(Microsoft.Xna.Framework.Rectangle rec1, Microsoft.Xna.Framework.Rectangle rec2)
        {
            bool result = rec1.Intersects(rec2);

            if (result)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #44
0
 public static bool EmptyTile(int i, int j, bool ignoreTiles = false)
 {
     Microsoft.Xna.Framework.Rectangle rectangle = new Microsoft.Xna.Framework.Rectangle(i * 16, j * 16, 16, 16);
     if (Main.tile[i, j].active && !ignoreTiles)
     {
         return(false);
     }
     for (int k = 0; k < 255; k++)
     {
         if (Main.player[k].active && rectangle.Intersects(new Microsoft.Xna.Framework.Rectangle((int)Main.player[k].position.X, (int)Main.player[k].position.Y, Main.player[k].width, Main.player[k].height)))
         {
             return(false);
         }
     }
     for (int l = 0; l < 200; l++)
     {
         if (Main.npc[l].active && rectangle.Intersects(new Microsoft.Xna.Framework.Rectangle((int)Main.npc[l].position.X, (int)Main.npc[l].position.Y, Main.npc[l].width, Main.npc[l].height)))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #45
0
 public static void DamageArea(Vector2 p, int width, int damage, int knockback)//hostile npcs, no crit, no immunity
 {
     damage = (int)(damage * Main.rand.Next(90, 111) / 100.0);
     Microsoft.Xna.Framework.Rectangle hurtbox = new Microsoft.Xna.Framework.Rectangle((int)p.X - width, (int)p.Y - width, width * 2, width * 2);
     for (int i = 0; i < 200; i++)
     {
         bool flag2 = hurtbox.Intersects(Main.npc[i].getRect());
         if (Main.npc[i].active && !Main.npc[i].dontTakeDamage && flag2 && !Main.npc[i].townNPC)
         {
             int direction = (Main.npc[i].position.X > p.X ? 1:-1);
             int d         = (int)Main.npc[i].StrikeNPC(damage, knockback, direction, false, false, false);
             NetMessage.SendData(28, -1, -1, null, i, (float)damage, knockback, (float)direction, 0, 0, 0);
         }
     }
 }
Beispiel #46
0
 public override bool isCollidingPosition(Microsoft.Xna.Framework.Rectangle position, xTile.Dimensions.Rectangle viewport, bool isFarmer, int damagesFarmer, bool glider, Character character, bool pathfinding, bool projectile = false, bool ignoreCharacterRequirement = false)
 {
     foreach (KeyValuePair <long, FarmAnimal> kvp in animals.Pairs)
     {
         if (character != null && !character.Equals(kvp.Value) && position.Intersects(kvp.Value.GetBoundingBox()) && (!isFarmer || !Game1.player.GetBoundingBox().Intersects(kvp.Value.GetBoundingBox())))
         {
             if (isFarmer && (character as Farmer).TemporaryPassableTiles.Intersects(position))
             {
                 break;
             }
             kvp.Value.farmerPushing();
             return(true);
         }
     }
     return(base.isCollidingPosition(position, viewport, isFarmer, damagesFarmer, glider, character, pathfinding));
 }
Beispiel #47
0
        public static GameObject instance_place(Vector2 vec, Type go)
        {
            List <GameObject> appliable = SceneObjects.FindAll(x => x.GetType() == go);
            Point             s         = currentObject.Sprite.ImageRectangle.Size;
            Rectangle         fr        = new Rectangle((int)vec.X, (int)vec.Y, s.X, s.Y);

            foreach (GameObject g in appliable)
            {
                RectangleF r = new Rectangle((int)g.Position.X, (int)g.Position.Y, g.Sprite.ImageRectangle.Width, g.Sprite.ImageRectangle.Height);
                if (r.Intersects(fr))
                {
                    return(g);
                }
            }

            return(null);
        }
Beispiel #48
0
 public override bool isCollidingPosition(Microsoft.Xna.Framework.Rectangle position, xTile.Dimensions.Rectangle viewport, bool isFarmer, int damagesFarmer, bool glider, Character character, bool pathfinding, bool projectile = false, bool ignoreCharacterRequirement = false)
 {
     if (projectile && damagesFarmer == 0 && position.Bottom < 832)
     {
         if (position.Intersects(new Microsoft.Xna.Framework.Rectangle(3648, 576, 256, 64)))
         {
             if (Game1.IsMasterGame && !treeNutShot.Value)
             {
                 Game1.player.team.MarkCollectedNut("TreeNutShot");
                 treeNutShot.Value = true;
                 Game1.createItemDebris(new Object(73, 1), new Vector2(58.5f, 11f) * 64f, 0, this, 0);
             }
             return(true);
         }
         return(false);
     }
     return(base.isCollidingPosition(position, viewport, isFarmer, damagesFarmer, glider, character, pathfinding, projectile, ignoreCharacterRequirement));
 }
Beispiel #49
0
 public override bool isCollidingPosition(Microsoft.Xna.Framework.Rectangle position, xTile.Dimensions.Rectangle viewport, bool isFarmer, int damagesFarmer, bool glider, Character character, bool pathfinding, bool projectile = false, bool ignoreCharacterRequirement = false)
 {
     if (log != null && log.getBoundingBox(log.tile).Intersects(position))
     {
         return(true);
     }
     if (travelingMerchantBounds != null)
     {
         foreach (Microsoft.Xna.Framework.Rectangle r in travelingMerchantBounds)
         {
             if (position.Intersects(r))
             {
                 return(true);
             }
         }
     }
     return(base.isCollidingPosition(position, viewport, isFarmer, damagesFarmer, glider, character, pathfinding, projectile, ignoreCharacterRequirement));
 }
Beispiel #50
0
 // Token: 0x06001180 RID: 4480 RVA: 0x00166C54 File Offset: 0x00164E54
 public override bool isCollidingPosition(Microsoft.Xna.Framework.Rectangle position, xTile.Dimensions.Rectangle viewport, bool isFarmer, int damagesFarmer, bool glider, Character character)
 {
     if (this.log != null && this.log.getBoundingBox(this.log.tile).Intersects(position))
     {
         return(true);
     }
     if (this.travelingMerchantBounds != null)
     {
         foreach (Microsoft.Xna.Framework.Rectangle r in this.travelingMerchantBounds)
         {
             if (position.Intersects(r))
             {
                 return(true);
             }
         }
     }
     return(base.isCollidingPosition(position, viewport, isFarmer, damagesFarmer, glider, character));
 }
Beispiel #51
0
        private void GameHandle_MouseDown(object sender, MouseEventArgs e)
        {
            Microsoft.Xna.Framework.Rectangle rect = new Microsoft.Xna.Framework.Rectangle(0, 0, GameHandle.Width, GameHandle.Height);

            Vector2 v = toData(new Vector2(e.X, e.Y), rect);

            foreach (Monster m in mGroup.Monsters.Keys)
            {
                Vector2 pos = mGroup.Monsters[m];

                Microsoft.Xna.Framework.Rectangle rect1 = new Microsoft.Xna.Framework.Rectangle((int)(v.X - 1.0f), (int)(v.Y - 1.0f), 3, 3);
                Microsoft.Xna.Framework.Rectangle rect2 = new Microsoft.Xna.Framework.Rectangle((int)(pos.X - 1.0f), (int)(pos.Y - 1.0f), 3, 3);

                if (rect1.Intersects(rect2))
                {
                    mCurrentMonster = m;
                }
            }
        }
        public override void draw(SpriteBatch b)
        {
            base.draw(b);
            int border_buffer = 1;

            Microsoft.Xna.Framework.Rectangle viewport_rect    = new Microsoft.Xna.Framework.Rectangle(Game1.viewport.X / 64 - border_buffer, Game1.viewport.Y / 64 - border_buffer, (int)Math.Ceiling((float)Game1.viewport.Width / 64f) + 2 * border_buffer, (int)Math.Ceiling((float)Game1.viewport.Height / 64f) + 3 + 2 * border_buffer);
            Microsoft.Xna.Framework.Rectangle object_rectangle = default(Microsoft.Xna.Framework.Rectangle);
            foreach (Building building in buildings)
            {
                object_rectangle.X     = building.tileX;
                object_rectangle.Width = building.tilesWide;
                int bottom_y = (int)building.tileY + (int)building.tilesHigh;
                object_rectangle.Height = bottom_y - (object_rectangle.Y = bottom_y - (int)Math.Ceiling((float)building.getSourceRect().Height * 4f / 64f));
                if (object_rectangle.Intersects(viewport_rect))
                {
                    building.draw(b);
                }
            }
        }
        public override void drawFloorDecorations(SpriteBatch b)
        {
            int border_buffer = 1;

            Microsoft.Xna.Framework.Rectangle viewport_rect    = new Microsoft.Xna.Framework.Rectangle(Game1.viewport.X / 64 - border_buffer, Game1.viewport.Y / 64 - border_buffer, (int)Math.Ceiling((float)Game1.viewport.Width / 64f) + 2 * border_buffer, (int)Math.Ceiling((float)Game1.viewport.Height / 64f) + 3 + 2 * border_buffer);
            Microsoft.Xna.Framework.Rectangle object_rectangle = default(Microsoft.Xna.Framework.Rectangle);
            foreach (Building building in buildings)
            {
                int additional_radius = building.GetAdditionalTilePropertyRadius();
                object_rectangle.X     = (int)building.tileX - additional_radius;
                object_rectangle.Width = (int)building.tilesWide + additional_radius * 2;
                int bottom_y = (int)building.tileY + (int)building.tilesHigh + additional_radius;
                object_rectangle.Height = bottom_y - (object_rectangle.Y = bottom_y - (int)Math.Ceiling((float)building.getSourceRect().Height * 4f / 64f) - additional_radius);
                if (object_rectangle.Intersects(viewport_rect))
                {
                    building.drawBackground(b);
                }
            }
            base.drawFloorDecorations(b);
        }
        private bool IsPositionGood(List <Microsoft.Xna.Framework.Rectangle> otherRects)
        {
            bool flag;

            foreach (Microsoft.Xna.Framework.Rectangle otherRect in otherRects)
            {
                if (Vector2.Distance(position, new Vector2((float)otherRect.X, (float)otherRect.Y)) < 100f)
                {
                    if ((!rectangle.Intersects(otherRect) ? false : rectangle != otherRect))
                    {
                        position  = new Vector2((float)Destroyable.random.Next(100, 9800), (float)Destroyable.random.Next(100, 7900));
                        rectangle = new Microsoft.Xna.Framework.Rectangle((int)position.X, (int)position.Y, textureOne.Width, textureOne.Height);
                        flag      = false;
                        return(flag);
                    }
                }
            }
            flag = true;
            return(flag);
        }
Beispiel #55
0
 public void CheckWarp()
 {
     if (Game1.player.currentLocation == this && Game1.currentLocation == this && Game1.locationRequest == null)
     {
         if (Game1.player.Position.X + 48 < 0)
         {
             Warp(ExitDirection.LEFT);
         }
         else if (Game1.player.Position.Y + 48 < 0)
         {
             Warp(ExitDirection.TOP);
         }
         else if (Game1.player.Position.X + 16 > this.mapWidth.Value * 64)
         {
             Warp(ExitDirection.RIGHT);
         }
         else if (Game1.player.Position.Y + 16 > this.mapHeight.Value * 64)
         {
             Warp(ExitDirection.BOTTOM);
         }
         else
         {
             var playerRectangle = new Microsoft.Xna.Framework.Rectangle((int)(Game1.player.Position.X + 8), (int)(Game1.player.Position.Y + 8), 64 - 16, 64 - 16);
             foreach (var additionalExitLocation in additionalExitLocations.Keys)
             {
                 var additionalExitLocationRectangle = new Microsoft.Xna.Framework.Rectangle((int)(additionalExitLocation.X * 64 + 8), (int)(additionalExitLocation.Y * 64 + 8), 64 - 16, 64 - 16);
                 if (playerRectangle.Intersects(additionalExitLocationRectangle))
                 {
                     if (additionalExitLocations[additionalExitLocation] == -1)
                     {
                         Warp(CastEnterDirToExitDir(EnterDir));
                     }
                     else
                     {
                         Warp((ExitDirection)additionalExitLocations[additionalExitLocation]);
                     }
                 }
             }
         }
     }
 }
Beispiel #56
0
        void MouseDown(object sender, MouseEventArgs e)
        {
            //      Vector2 coord = new Vector2((e.X / GameHandle.Width) * 100, (e.Y / GameHandle.Height) * 100);

            int x = (int)((((float)e.X) / ((float)GameHandle.Width)) * 100.0f);
            int y = (int)((((float)e.Y) / ((float)GameHandle.Height)) * 100.0f);

            Microsoft.Xna.Framework.Rectangle rect = new Microsoft.Xna.Framework.Rectangle(x, y, 3, 3);

            mPrevCurrentSpline = null;
            mNextCurrentSpline = null;
            foreach (BezierSpline spline in mFormation.Splines)
            {
                for (int i = 0; i < spline.CurveCount; i++)
                {
                    int         pointNum = 0;
                    CubicBezier bez      = spline.GetCurve(i);
                    for (int j = 0; j < bez.Points.Length; j++)
                    {
                        pointNum++;
                        Microsoft.Xna.Framework.Rectangle test = new Microsoft.Xna.Framework.Rectangle((int)(bez.Points[j].X - 1), (int)(bez.Points[j].Y - 1), 3, 3);

                        if (test.Intersects(rect))
                        {
                            mCurrentSpline = bez;
                            if ((i + 1) < spline.CurveCount)
                            {
                                mNextCurrentSpline = spline.GetCurve(i + 1);
                            }
                            if (i > 0)
                            {
                                mPrevCurrentSpline = spline.GetCurve(i - 1);
                            }
                            mCurrentParentSpline = spline;
                            mPointNumber         = pointNum;
                        }
                    }
                }
            }
        }
Beispiel #57
0
        public void Draw(SpriteBatch spriteBatch, Camera cam)
        {
            //Vi gör en rektangel lika stor som kameran.
            Microsoft.Xna.Framework.Rectangle camRect = new Microsoft.Xna.Framework.Rectangle(
                Convert.ToInt32(cam.position.X),
                Convert.ToInt32(cam.position.Y),
                (cam.width + 1) * (texture.Width / numberOfTilesInTexture),
                (cam.height + 2) * texture.Height);

            cam.visibleTiles.Clear();
            //vi loopar igenom ALLA rutor
            for (int x = (int)((cam.position.X / Settings.gridsize)); x <= ((cam.position.X / Settings.gridsize) + cam.width + 1); x++)
            {
                for (int y = (int)((cam.position.Y / Settings.gridsize)); y <= ((cam.position.Y / Settings.gridsize) + cam.height + 1); y++)
                {
                    //För varje ruta så gör vi en rektangel-
                    Microsoft.Xna.Framework.Rectangle tileRect = new Microsoft.Xna.Framework.Rectangle(x * (texture.Width / numberOfTilesInTexture), y * (texture.Height / numberOfTilesInTexture), texture.Width / numberOfTilesInTexture, texture.Height / numberOfTilesInTexture);

                    //och så kollar vi om rektangeln för rutan är inom rektangeln för kameran.
                    if (tileRect.Intersects(camRect))
                    {
                        //isåfall så ritar vi ut den. vi skickar med kamerans position för att kunna offsetta det vi ritar ut.
                        try{
                            cam.visibleTiles.Add(map [x, y]);
                            map [x, y].Draw(spriteBatch, cam.position);
                        }
                        catch
                        {
                            continue;
                        }
                    }
                }
            }


            foreach (var enemy in enemies)
            {
                enemy.Draw(spriteBatch, cam);
            }
        }
Beispiel #58
0
        public List <Rectangle> GenerateSquareRooms(int mapWidth, int mapHeight, int roomCount, int minRoomDimension, int maxRoomDimension)
        {
            List <Rectangle> Rooms = new List <Rectangle>();

            for (int i = 0; i < roomCount; i++)
            {
                int newRoomWidth  = GameLoop.rndNum.Next(minRoomDimension, maxRoomDimension);
                int newRoomHeight = GameLoop.rndNum.Next(minRoomDimension, maxRoomDimension);

                int newRoomX = GameLoop.rndNum.Next(0, mapWidth - newRoomWidth - 1);
                int newRoomY = GameLoop.rndNum.Next(0, mapHeight - newRoomHeight - 1);

                Rectangle newRoom = new Rectangle(newRoomX, newRoomY, newRoomWidth, newRoomHeight);

                bool newRoomIntersects = Rooms.Any(room => newRoom.Intersects(room));

                if (!newRoomIntersects) // If disabled, can make some interesting shapes as well
                {
                    Rooms.Add(newRoom);
                }
            }
            return(Rooms);
        }
Beispiel #59
0
        public static bool IsTilePassable(GameLocation location, Location tileLocation, xTile.Dimensions.Rectangle viewport)
        {
            PropertyValue passable = null;

            Microsoft.Xna.Framework.Rectangle tileLocationRect = new Microsoft.Xna.Framework.Rectangle((int)tileLocation.X * 64, (int)tileLocation.Y * 64, 64, 64);
            Tile tmp = location.map.GetLayer("Back").PickTile(new Location(tileLocation.X * 64, tileLocation.Y * 64), viewport.Size);

            if (tmp != null)
            {
                tmp.TileIndexProperties.TryGetValue("Passable", out passable);
            }
            Tile tile = location.map.GetLayer("Buildings").PickTile(new Location(tileLocation.X * 64, tileLocation.Y * 64), viewport.Size);

            if (location.largeTerrainFeatures != null)
            {
                using (List <LargeTerrainFeature> .Enumerator enumerator = location.largeTerrainFeatures.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        if (enumerator.Current.getBoundingBox().Intersects(tileLocationRect))
                        {
                            return(false);
                        }
                    }
                }
            }
            Vector2 vLocation = new Vector2(tileLocation.X, tileLocation.Y);

            if (location.terrainFeatures.ContainsKey(vLocation) && tileLocationRect.Intersects(location.terrainFeatures[vLocation].getBoundingBox(vLocation)) && (!location.terrainFeatures[vLocation].isPassable(null) || (location.terrainFeatures[vLocation] is HoeDirt && ((HoeDirt)location.terrainFeatures[vLocation]).crop != null)))
            {
                return(false);
            }
            bool result = passable == null && tile == null && tmp != null;

            return(result);
        }
Beispiel #60
0
        /// <summary>A Harmony prefix patch that causes <see cref="BuildableGameLocation.isBuildable(Vector2)"/> to return true under more conditions.</summary>
        /// <param name="__instance">The buildable location on which this method is called.</param>
        /// <param name="tileLocation">The tile being checked.</param>
        /// <param name="__result">True if this tile should allow <see cref="Building"/> placement.</param>
        /// <returns>False if the original method (and any other patches) should be skipped.</returns>
        public static bool IsBuildable(BuildableGameLocation __instance, Vector2 tileLocation, ref bool __result)
        {
            try
            {
                if (ModEntry.Config.EverythingEnabled()) //if every feature is enabled
                {
                    __result = true;                     //this tile is buildable
                    return(false);                       //skip the original method
                }

                if (ModEntry.Config.EverythingDisabled())                                                                   //if every feature is disabled
                {
                    return(true);                                                                                           //run the original method (do nothing)
                }
                if (ModEntry.Config.BuildOnAllTerrainFeatures == false)                                                     //if most terrain features should prevent building (based on the original method's behavior)
                {
                    Rectangle tileLocationRect = new Rectangle((int)tileLocation.X * 64, (int)tileLocation.Y * 64, 64, 64); //get a rectangle representing this tile

                    if (__instance.terrainFeatures.TryGetValue(tileLocation, out TerrainFeature feature) && //if this tile has a terrain feature
                        tileLocationRect.Intersects(feature.getBoundingBox(tileLocation)))    //AND the feature's box overlaps with the tile (note: copied from GameLocation.isOccupiedForPlacement)
                    {
                        if (!__instance.terrainFeatures[tileLocation].isPassable() || //if the feature is impassable
                            (feature is HoeDirt dirt && dirt.crop != null)) //OR the feature is a crop
                        {
                            __result = false;                               //this tile is NOT buildable
                            return(false);                                  //skip the original method
                        }
                    }
                }

                if (ModEntry.Config.BuildOnOtherBuildings == false)                  //if collision with other buildings should prevent building
                {
                    foreach (Building building in __instance.buildings)              //for each existing building
                    {
                        if (building.isTileOccupiedForPlacement(tileLocation, null)) //if this building occupies this tile
                        {
                            __result = false;                                        //this tile is NOT buildable
                            return(false);                                           //skip the original method
                        }
                    }
                }

                if (ModEntry.Config.BuildOnWater == false) //if water should prevent building
                {
                    if (__instance.doesTileHaveProperty((int)tileLocation.X, (int)tileLocation.Y, "Water", "Back") != null && //if this tile is water
                        __instance.doesTileHaveProperty((int)tileLocation.X, (int)tileLocation.Y, "Passable", "Buildings") == null) //AND this tile does NOT specifically allow buildings
                    {
                        __result = false;                                                                                           //this tile is NOT buildable
                        return(false);                                                                                              //skip the original method
                    }
                }

                if (ModEntry.Config.BuildOnImpassableTiles == false)                                                                        //if impassable tiles should prevent building
                {
                    if (ModEntry.Config.BuildOnWater == false || __instance.isOpenWater((int)tileLocation.X, (int)tileLocation.Y) == false) //if this tile is NOT specifically allowed by the water setting
                    {
                        if (__instance.isTileOccupiedForPlacement(tileLocation) || //if this tile is occupied
                            __instance.isTilePassable(new Location((int)tileLocation.X, (int)tileLocation.Y), Game1.viewport) == false) //OR if this tile is NOT passable
                        {
                            __result = false;                                                                                           //this tile is NOT buildable
                            return(false);                                                                                              //skip the original method
                        }
                    }
                }

                if (ModEntry.Config.BuildOnNoFurnitureTiles == false)                                                             //if "no furniture" tiles should prevent building
                {
                    if (__instance.doesTileHaveProperty((int)tileLocation.X, (int)tileLocation.Y, "NoFurniture", "Back") != null) //if this tile has a "NoFurniture" property
                    {
                        __result = false;                                                                                         //this tile is NOT buildable
                        return(false);                                                                                            //skip the original method
                    }
                }

                if (ModEntry.Config.BuildOnCaveAndShippingZones == false) //if "no build" zones should prevent building
                {
                    //NOTE: as of SDV 1.5.5, the static preset rectangle "zones" no longer exist, and farm maps use the tile property "Buildable" "f" instead;
                    //that tile property may exist elsewhere too, but checking relevant properties here should be understandable enough

                    //try to get the cave and shipping no-build zones
                    Rectangle?caveNoBuildRect         = ModEntry.Instance.Helper.Reflection.GetField <Rectangle>(__instance, "caveNoBuildRect", false)?.GetValue();
                    Rectangle?shippingAreaNoBuildRect = ModEntry.Instance.Helper.Reflection.GetField <Rectangle>(__instance, "shippingAreaNoBuildRect", false)?.GetValue();

                    if (caveNoBuildRect.HasValue && shippingAreaNoBuildRect.HasValue) //if these fields exist (e.g. SDV v1.5.4 or earlier is in use)
                    {
                        if (caveNoBuildRect.Value.Contains(Utility.Vector2ToPoint(tileLocation)) || //if this tile is within the cave entrance zone
                            shippingAreaNoBuildRect.Value.Contains(Utility.Vector2ToPoint(tileLocation))) //OR this tile is within the shipping bin zone
                        {
                            __result = false;                                                             //this tile is NOT buildable
                            return(false);                                                                //skip the original method
                        }
                    }

                    string buildableValue = __instance.doesTileHavePropertyNoNull((int)tileLocation.X, (int)tileLocation.Y, "Buildable", "Back");             //get the value of this tile's "Buildable" property ("" if null)
                    if (buildableValue.Equals("f", StringComparison.OrdinalIgnoreCase) || buildableValue.Equals("false", StringComparison.OrdinalIgnoreCase)) //if the value is false
                    {
                        __result = false;                                                                                                                     //this tile is NOT buildable
                        return(false);                                                                                                                        //skip the original method
                    }
                }

                //all checks have been successful

                __result = true; //this tile is buildable
                return(false);   //skip the original method
            }
            catch (Exception ex)
            {
                ModEntry.Instance.Monitor.LogOnce($"Encountered an error in Harmony patch \"{nameof(HarmonyPatch_BuildOnAnyTile)}\". The default building rules will be used instead. Full error message:\n-----\n{ex.ToString()}", LogLevel.Error);
                return(true); //run the original method
            }
        }