Я искал в Интернете, чтобы найти ответ на свой вопрос, и я так и сделал, но даже после того, как я попытался настроить каждый ответ, я не могу найти решение для создания коллизии между моим rectangleShape и ovalShape. Я пытался использовать IntersectsWith и .Bound, но они не будут работать по любой причине.
Это мой код:
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 TitleScreen_GameScreen_HelpScreen
{
public partial class GameScreen : Form
{
int a = 0;
int x = 10;
int y = 10;
public int speed_left = 4;
public int speed_top = 4;
public int point = 0;
public GameScreen()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (ovalShape1.Left > 350)
{
x = -10;
}
if (ovalShape1.Left < 0)
{
x = 10;
}
if (ovalShape1.Top > 335)
{
x = 10;
}
if (ovalShape1.Top < 0)
{
y = -10;
}
a = a + 1;
label2.Text = a.ToString();
ovalShape1.Left = ovalShape1.Left + x;
ovalShape1.Top = ovalShape1.Top - y;
if (ovalShape1.Top == 335 && ovalShape1.Left > rectangleShape1.Left && ovalShape1.Right < rectangleShape1.Right)
{
y = -10;
}
}
private void GameScreen_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.D)
{
rectangleShape1.Left = rectangleShape1.Left + 10;
}
if (e.KeyCode == Keys.A)
{
rectangleShape1.Left = rectangleShape1.Left - 10;
}
}