質問編集履歴

2

2018/02/06 03:01

投稿

rsetuhbcln
rsetuhbcln

スコア13

test CHANGED
@@ -1 +1 @@
1
- ボールとカゴの当たり判定について
1
+ 物質判定方法ゲーム理論
test CHANGED
File without changes

1

2018/02/06 03:01

投稿

rsetuhbcln
rsetuhbcln

スコア13

test CHANGED
File without changes
test CHANGED
@@ -10,176 +10,4 @@
10
10
 
11
11
 
12
12
 
13
- namespace _1108_ボール_斜方投射
13
+ namespace _1108_ボール_斜
14
-
15
- {
16
-
17
- public partial class Formballshoot : Form
18
-
19
- {
20
-
21
-
22
-
23
- double ballPos_x;
24
-
25
- double ballPos_y;
26
-
27
- double vx = 10;      //x座標の初速度
28
-
29
- double vy = -30;       //y座標の初速度
30
-
31
- double g = 1.0;       //加速度
32
-
33
- double power = 1;
34
-
35
- int t = 0; //時間
36
-
37
- int ballRadius = 10;     //ボールの半径
38
-
39
- double deg; //打ちだし角度
40
-
41
- Timer timer = new Timer();
42
-
43
- Random rand = new Random(); //乱数を発生させるrandを生成
44
-
45
-
46
-
47
- public Formballshoot()
48
-
49
- {
50
-
51
-
52
-
53
- //角度を30度~60度の間で発生
54
-
55
- deg = rand.Next(30, 60);
56
-
57
-
58
-
59
- this.ballPos_x = 10; //x座標の初期位置
60
-
61
- this.ballPos_y = 650; //y座標の初期位置
62
-
63
- InitializeComponent();
64
-
65
-
66
-
67
- PictureBox1.Left = 150; //カゴのy座標の初期位置
68
-
69
- PictureBox1.Top = 500; //カゴのx座標の初期位置
70
-
71
-
72
-
73
- //マウスホイールイベントの追加
74
-
75
- this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.Scroll_MouseWheel);
76
-
77
-
78
-
79
- //タイマーイベント
80
-
81
- Timer timer = new Timer();
82
-
83
- timer.Interval = 50;
84
-
85
- timer.Tick += new EventHandler(Update);
86
-
87
- //timer.Start();
88
-
89
-
90
-
91
- }
92
-
93
-
94
-
95
- private void Update(object sender, EventArgs e)
96
-
97
- {
98
-
99
-
100
-
101
- ballPos_x += vx * Math.Cos(deg * (Math.PI / 180));
102
-
103
- ballPos_y += vy * Math.Sin(deg * (Math.PI / 180)) + g * t;
104
-
105
- this.t++;
106
-
107
-
108
-
109
- //再描写
110
-
111
- Invalidate();
112
-
113
-
114
-
115
- //ボールが画面の下を超えた場合
116
-
117
- //繰り返しボールを飛ばす
118
-
119
- if (ballPos_y > 650)
120
-
121
- {
122
-
123
-
124
-
125
- this.vx = power; //初速をpowerにする
126
-
127
- this.vy = -30;      //y座標の初速度を再び示す 
128
-
129
- this.g = 1.0; //加速度を再び示す
130
-
131
- this.ballPos_x = 10; //x座標の初期位置に戻す
132
-
133
- this.ballPos_y = 650; //y座標の初期位置に戻す
134
-
135
- deg = rand.Next(30, 60); //角度を30度~60度に設定
136
-
137
- this.t = 0;
138
-
139
- this.t++;
140
-
141
- ballPos_x += vx * Math.Cos(deg * (Math.PI / 180));
142
-
143
- ballPos_y += vy * Math.Sin(deg * (Math.PI / 180)) + g * t;
144
-
145
-
146
-
147
- }
148
-
149
-
150
-
151
- //ボールとカゴの当たり判定
152
-
153
- if ((ballPos_x > PictureBox1.Location.X) &&
154
-
155
- (ballPos_x < PictureBox1.Left + PictureBox1.Size.Width) &&
156
-
157
- (ballPos_y > PictureBox1.Location.Y) &&
158
-
159
- (ballPos_y < PictureBox1.Top + PictureBox1.Size.Height))
160
-
161
- {
162
-
163
-
164
-
165
- this.vx = -1;
166
-
167
- this.vy = -1;
168
-
169
-
170
-
171
- }
172
-
173
-
174
-
175
- }
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
- }