質問編集履歴

2

コードの表示

2017/11/27 07:41

投稿

rsetuhbcln
rsetuhbcln

スコア13

test CHANGED
File without changes
test CHANGED
@@ -1,3 +1,281 @@
1
1
  現在、Pictureboxのプロパティでボールを入れるカゴを表示していて、solidbrushで描いたボールをカゴに入れるようなゲームを作成しているのですが、ボールがカゴに重なるとボールがPictureboxの裏に隠れてしまいます。
2
2
 
3
3
  ボールを表に重ねるにはどうしたらいいでしょうか?
4
+
5
+
6
+
7
+ using System;
8
+
9
+ using System.Collections.Generic;
10
+
11
+ using System.ComponentModel;
12
+
13
+ using System.Data;
14
+
15
+ using System.Drawing;
16
+
17
+ using System.Linq;
18
+
19
+ using System.Text;
20
+
21
+ using System.Threading.Tasks;
22
+
23
+ using System.Windows.Forms;
24
+
25
+ using System.Drawing.Drawing2D;
26
+
27
+
28
+
29
+
30
+
31
+ namespace _1108_ボール_斜方投射
32
+
33
+ {
34
+
35
+ public partial class Formballshoot : Form
36
+
37
+ {
38
+
39
+
40
+
41
+ double ballPos_x;
42
+
43
+ double ballPos_y;
44
+
45
+ double vx = 10;      //x座標の初速度
46
+
47
+ double vy = -30;       //y座標の初速度
48
+
49
+ double g = 1.0;       //加速度
50
+
51
+ double power = 1;
52
+
53
+ int t = 0; //時間
54
+
55
+ int ballRadius = 10;     //ボールの半径
56
+
57
+ double deg; //打ちだし角度
58
+
59
+ Timer timer = new Timer();
60
+
61
+ Random rand = new Random(); //乱数を発生させるrandを生成
62
+
63
+
64
+
65
+
66
+
67
+ public Formballshoot()
68
+
69
+ {
70
+
71
+
72
+
73
+ //角度を30度~60度の間で発生
74
+
75
+ deg = rand.Next(30, 60);
76
+
77
+
78
+
79
+ this.ballPos_x = 10; //x座標の初期位置
80
+
81
+ this.ballPos_y = 650; //y座標の初期位置
82
+
83
+ InitializeComponent();
84
+
85
+
86
+
87
+ //マウスホイールイベントの追加
88
+
89
+ this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.Scroll_MouseWheel);
90
+
91
+
92
+
93
+ //タイマーイベント
94
+
95
+ Timer timer = new Timer();
96
+
97
+ timer.Interval = 50;
98
+
99
+ timer.Tick += new EventHandler(Update);
100
+
101
+ //timer.Start();
102
+
103
+
104
+
105
+ }
106
+
107
+
108
+
109
+ private void Update(object sender, EventArgs e)
110
+
111
+ {
112
+
113
+
114
+
115
+ ballPos_x += vx * Math.Cos(deg * (Math.PI / 180));
116
+
117
+ //vy += g;
118
+
119
+ ballPos_y += vy * Math.Sin(deg * (Math.PI / 180)) + g * t;
120
+
121
+ this.t++;
122
+
123
+
124
+
125
+ //再描写
126
+
127
+ Invalidate();
128
+
129
+
130
+
131
+ //ボールが画面の下を超えた場合
132
+
133
+ //繰り返しボールを飛ばす
134
+
135
+ if (ballPos_y > 650)
136
+
137
+ {
138
+
139
+
140
+
141
+ this.vx = power; //初速をpowerにする
142
+
143
+ this.vy = -30;      //y座標の初速度を再び示す 
144
+
145
+ this.g = 1.0; //加速度を再び示す
146
+
147
+ this.ballPos_x = 10; //x座標の初期位置に戻す
148
+
149
+ this.ballPos_y = 650; //y座標の初期位置に戻す
150
+
151
+ deg = rand.Next(30, 60); //角度を30度~60度に設定
152
+
153
+ this.t = 0;
154
+
155
+ this.t++;
156
+
157
+ ballPos_x += vx * Math.Cos(deg * (Math.PI / 180));
158
+
159
+ ballPos_y += vy * Math.Sin(deg * (Math.PI / 180)) + g * t;
160
+
161
+
162
+
163
+
164
+
165
+ }
166
+
167
+ }
168
+
169
+ private void DrawFiguare(object sender, PaintEventArgs e)
170
+
171
+ {
172
+
173
+
174
+
175
+ e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
176
+
177
+ //円を描画する
178
+
179
+ SolidBrush brush = new SolidBrush(Color.Red);
180
+
181
+ float px = (float)this.ballPos_x - this.ballRadius;
182
+
183
+ float py = (float)this.ballPos_y - this.ballRadius;
184
+
185
+ e.Graphics.FillEllipse(brush, px, py, this.ballRadius * 2, this.ballRadius * 2);
186
+
187
+
188
+
189
+ }
190
+
191
+
192
+
193
+ private void endEToolStripMenuItem_Click(object sender, EventArgs e)
194
+
195
+ {
196
+
197
+
198
+
199
+ //ゲーム終了
200
+
201
+ Close();
202
+
203
+
204
+
205
+ }
206
+
207
+
208
+
209
+ private void Scroll_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
210
+
211
+ {
212
+
213
+
214
+
215
+ int Wheel = (e.Delta / 120);
216
+
217
+ label1.Text = (e.Delta * SystemInformation.MouseWheelScrollLines / 120).ToString();
218
+
219
+
220
+
221
+ //ホイールを上方向に動かす場合
222
+
223
+ if (e.Delta > 0)
224
+
225
+ {
226
+
227
+ this.power++;    //初速を上げる
228
+
229
+
230
+
231
+ }
232
+
233
+
234
+
235
+ //ホイールを下方向に動かす場合
236
+
237
+ else if (e.Delta < 0)
238
+
239
+ {
240
+
241
+
242
+
243
+ this.power--; //初速を下げる
244
+
245
+ }
246
+
247
+ }
248
+
249
+
250
+
251
+ private void Formballshoot_KeyDown(object sender, KeyEventArgs e)
252
+
253
+ {
254
+
255
+
256
+
257
+ Timer timer = new Timer();
258
+
259
+ timer.Interval = 50;
260
+
261
+
262
+
263
+ //エンターキーを押した場合
264
+
265
+ if (e.KeyData == Keys.Enter)
266
+
267
+ {
268
+
269
+ timer.Tick += new EventHandler(Update);
270
+
271
+ timer.Start(); //タイマースタート
272
+
273
+
274
+
275
+ }
276
+
277
+ }
278
+
279
+ }
280
+
281
+ }

1

誤字

2017/11/27 07:41

投稿

rsetuhbcln
rsetuhbcln

スコア13

test CHANGED
@@ -1 +1 @@
1
- Pictureboxの表表示したい
1
+ Pictureboxに重なるようにしたい
test CHANGED
File without changes