SolvedNeed help IntersectWith

Posts 14 of 4 · Page 1 of 1
Need help IntersectWith
Hello everyone ! I am learning to code in c# , and im learning a little game .. When I want to create colision , I use > IntersectWith , and I got this error : Error 2 'System.Drawing.Rectangle' does not contain a definition for 'IntersectWith' and no extension method 'IntersectWith' accepting a first argument of type 'System.Drawing.Rectangle' could be found (are you missing a using directive or an assembly reference?) C:\Users\Kenny\Desktop\Website\3. C#\Game\Game\Form1.cs 28 28 Game

Player is my pictureBox which represent the player.
Block is anotherPictureBox which represent an obstacle

Here is the part of the code :
Code:
 public void Colision()
        {
          if(Player.Bounds.IntersectWith(Block.Bounds))
        {
            right = false;
        }
Can you help me please.. ? Thank you !

( Full code if you want to know more.. )

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace Game
{
   

    public partial class Form1 : Form
    {
        bool jump;
        int G = 25;
        int Force;
        bool right, left;
        public Form1()
        {
            InitializeComponent();
        }
        public void Colision()
        {
          if(Player.Bounds.IntersectWith(Block.Bounds))
        {
            right = false;
        }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (left) { Player.Left -= 4; }
            if (right) { Player.Left += 4; }
            
            
            if(jump)
            {
                Player.Top -= Force;
                Force -= 1;
            }
            if(Player.Top + Player.Height >= Screen.Height)
            {
                Player.Top = Screen.Height - Player.Height;
                jump = false;
            }
            else
            { Player.Top += 1; }
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.A) { left = true; }
            if (e.KeyCode == Keys.D) { right = true; }   
            if(!jump)
                {
                    if(e.KeyCode == Keys.Space)
                    {
                        jump = true;
                        Force = G;
                    }
                }
        }

        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.A) { left = false; }
            if (e.KeyCode == Keys.D) { right = false; }   
        }
    }
}
You made a small typo.

Code:
public void Colision()
{
    if(Player.Bounds.IntersectsWith(Block.Bounds))
    {
        right = false;
    }
}
Oh god I am stupid.. Thanks..
Oh no no don't use this kind of method. Well it's fine as long as it's a classic pong game, otherwise download a physics library and use it.
Posts 14 of 4 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?