C sharp - Necesito ayuda para hacer que estos objetos colisionen

 
Vista:

Necesito ayuda para hacer que estos objetos colisionen

Publicado por Gema (1 intervención) el 01/05/2020 01:56:01
Buenas , disculpen alguien me ayudar con esto, estoy haciendo un juego de una nave espacial y para esto se tiene que mover dentro de un tablero , y ese tablero lo genere con una matriz de picturebox de 10*10 , y dentro de ese tablero genero 2 variables random , para que se inserten unas imagenes de un meteoros y unos ovnis dentro de las celdas de la matriz del picturebox . Lo que necesito ayuda es saber como puedo hacer para que a la hora de que la nave espacial choque con un ovni y un meteoro, esta regrese a su lugar de inicio, pero no logro hacer que los objetos choquen , así que si porfavor me puede ayudar o decir otra forma de hacerlo lo agradecería mucho. Ya intente con varias formas pero no logro .

Adjunto mi código

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
PictureBox[,] tablero = new PictureBox[10, 10];
 
Random ovnis = new Random();
Random meteoros = new Random();
 
public Form1()
{
    InitializeComponent();
    this.KeyPreview = true;
    meteoritos = new List<PictureBox>();
}
 
 
public void Tablerojuego()
{
 
    for (int j = 0; j < 10; j++)
    {
 
        for (int i = 0; i < 10; i++)
        {
 
            tablero[i, j] = new PictureBox();
            Controls.Add(tablero[i, j]);
            tablero[i, j].Width = 70;
            tablero[i, j].Height = 70;
            tablero[i, j].Top = 70 * j;
            tablero[i, j].Left = 70 * i;
            tablero[i, j].BackColor = Color.BlueViolet;
            tablero[i, j].BackgroundImage = Properties.Resources.fondo;
 
 
        }
    }
}
 
 
public void meteoro()
{
 
 
    int m1x = pictureBox1.Location.X;
    int m1y = pictureBox1.Location.Y;
    int m2x = pictureBox2.Location.X;
    int m2y = pictureBox2.Location.Y;
    int nave = 1;
      int trampas = ovnis.Next(1, 3);
 
      PictureBox imagenmeteoro = new PictureBox();
 
 
    for (int j = 0; j < 10; j++)
    {
 
        for (int i = 0; i < 10; i++)
        {
 
            if (ovnis.Next(0, 16) == 4)
            {
 
 
                tablero[i, j].Image = Properties.Resources.meteorito;
                tablero[i, j].Name = "A";
 
                label4.Text = tablero.GetValue(i, j).ToString();
            }
        }
 
    }
 
    for (int j = 0; j < 10; j++)
    {
 
        for (int i = 0; i < 10; i++)
        {
            Random rnd = new Random();
            int m = rnd.Next(m1y, m1x);
            int m2 = rnd.Next(m2y, m2x);
            pictureBox1.Location = new Point(m, 0);
            pictureBox3.Location = new Point(m, 0);
            pictureBox2.Location = new Point(m2, 0);
 
        }
    }
 
 
}
private void Form1_Load(object sender, EventArgs e)
{
 
 
    Tablerojuego();
    meteoro();
 
}
 
private void timer1_Tick(object sender, EventArgs e)
{
    int x = pictureBox1.Location.X;
    int y = pictureBox1.Location.Y;
 
   for (int j = 0; j < 10; j++)
    {
 
        for (int i = 0; i < 10; i++)
        {
            if (meteoros.Next(0, 100) == 50)
 
            tablero[i, j].Image = Properties.Resources.ovnis;
 
        }
    }
    for (int j = 0; j < 10; j++)
    {
 
        for (int i = 0; i < 10; i++)
        {
            Random rnd = new Random();
            Random p = new Random();
            int m = rnd.Next(y, x);
 
 
            pictureBox1.Location = new Point(m, 0);
            pictureBox1.Created.ToString();
 
            if (meteoros.Next(0, 100) == 50)
 
                tablero[i, j].Image = pictureBox1.Image;
        }
    }
}
 
public void movimientos()
{
    int posicionx = NaveEspacial.Location.X;
    int posiciony = NaveEspacial.Location.Y;
 
    label1.Text = posicionx.ToString();
    label2.Text = posiciony.ToString();
}
 
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    int posicionx = NaveEspacial.Location.X;
    int posiciony = NaveEspacial.Location.Y;
    int cont = 0;
    label2.Text = posicionx.ToString();
    label3.Text = posiciony.ToString();
 
 
    if (e.KeyCode == Keys.Left)
    {
 
        posicionx -= 54;
    }
 
    if (e.KeyCode == Keys.Right)
    {
        posicionx += 54;
    }
 
    if (e.KeyCode == Keys.Up)
    {
        posiciony -= 54;
    }
    if (e.KeyCode == Keys.Down)
    {
        posiciony += 60;
    }
 
    NaveEspacial.Location = new System.Drawing.Point(posicionx, posiciony);
 
    if (int.Parse(label2.Text) < 1000)
    {
 
        cont = 1;
        cont++;
        label1.Text = cont.ToString();
    }
 
    if (int.Parse(label2.Text) < 11)
    {
        NaveEspacial.Location = new Point(605, 72);
        MessageBox.Show("Espacio No explorado");
    }
    if (int.Parse(label3.Text) > 600)
    {
        NaveEspacial.Location = new Point(605, 72);
        MessageBox.Show("Espacio No explorado");
    }
 
 
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
    Tablerojuego();
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder