private bool DetectCollision(OminoCursori ominoCursori, List <Barra> barre) { foreach (Barra barra in barre) { if (barra.DrawRectangle.Intersects(ominoCursori.DrawRectangle)) { return(true); } } return(false); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); //ominosprite = Content.Load<Texture2D>("Omino"); ominosprite = Content.Load <Texture2D>("mario2"); drawRectangle.Height = ominosprite.Height; drawRectangle.Width = ominosprite.Width; //barraSprite = Content.Load<Texture2D>("Barra"); barraSprite = Content.Load <Texture2D>("barra2"); barraOrizzontaleSprite = Content.Load <Texture2D>("barra_orizzontale"); spriteFont = Content.Load <SpriteFont>("Arial_12"); drawRectangle.X = 20; drawRectangle.Y = 20; drawRectangleOminoCursori.X = 50; drawRectangleOminoCursori.Y = 50; drawRectangleBarra.X = 100; drawRectangleBarra.Y = 100; //omino = new Omino(ominosprite, drawRectangle, 0, 0); Vector2 ominoDirection = new Vector2((float)1000, (float)1000); omino = new Omino(ominosprite, drawRectangle, ominoDirection, (float)0.1); ominoCursori = new OminoCursori(ominosprite, drawRectangleOminoCursori, 0, 0); //barraOggetto = new Barra(barra, drawRectangleBarra, 100, 100); for (int i = 0; i < Globals.NUMBER_OF_BARS; i++) { barre.Add(new Barra(barraSprite, //rand.Next(graphics.PreferredBackBufferWidth-(barraSprite.Width/Barra.XSpriteRatio)), Globals.BAR_X_POSITIONS[i], rand.Next(graphics.PreferredBackBufferHeight - (barraSprite.Height / Barra.YSpriteRatio)), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, Globals.BAR_X_SPEED, Globals.BAR_Y_SPEED )); } var firstBar = new BarraOrizzontale(barraOrizzontaleSprite, //rand.Next(graphics.PreferredBackBufferWidth-(barraSprite.Width/Barra.XSpriteRatio)), Globals.HORIZONTAL_BAR_X_POSITIONS[0], rand.Next(Globals.HORIZONTAL_BAR_UPPER_MARGIN, graphics.PreferredBackBufferHeight - (barraOrizzontaleSprite.Height / Barra.YSpriteRatio)), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, Globals.HORIZONTAL_BAR_X_SPEED, Globals.HORIZONTAL_BAR_Y_SPEED ); firstBar.RegisterObserver(ominoCursori); barreOrizzontali.Add(firstBar); for (int i = 1; i < Globals.NUMBER_OF_HORIZONTAL_BARS; i++) { barreOrizzontali.Add(new BarraOrizzontale(barraOrizzontaleSprite, //rand.Next(graphics.PreferredBackBufferWidth-(barraSprite.Width/Barra.XSpriteRatio)), Globals.HORIZONTAL_BAR_X_POSITIONS[i], rand.Next(Globals.HORIZONTAL_BAR_UPPER_MARGIN, graphics.PreferredBackBufferHeight - (barraOrizzontaleSprite.Height / Barra.YSpriteRatio)), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, Globals.HORIZONTAL_BAR_X_SPEED, Globals.HORIZONTAL_BAR_Y_SPEED )); } // TODO: use this.Content to load your game content here //spriteBatch.DrawString(spriteFont, "score", new Vector2(5, 5), Color.White); }