質問編集履歴
2
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
物質判定方法ゲーム理論
|
body
CHANGED
File without changes
|
1
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,90 +4,4 @@
|
|
4
4
|
なにか良い方法はありませんか?よろしくお願いします。
|
5
5
|
|
6
6
|
|
7
|
-
namespace _1108_ボール_斜
|
7
|
+
namespace _1108_ボール_斜
|
8
|
-
{
|
9
|
-
public partial class Formballshoot : Form
|
10
|
-
{
|
11
|
-
|
12
|
-
double ballPos_x;
|
13
|
-
double ballPos_y;
|
14
|
-
double vx = 10; //x座標の初速度
|
15
|
-
double vy = -30; //y座標の初速度
|
16
|
-
double g = 1.0; //加速度
|
17
|
-
double power = 1;
|
18
|
-
int t = 0; //時間
|
19
|
-
int ballRadius = 10; //ボールの半径
|
20
|
-
double deg; //打ちだし角度
|
21
|
-
Timer timer = new Timer();
|
22
|
-
Random rand = new Random(); //乱数を発生させるrandを生成
|
23
|
-
|
24
|
-
public Formballshoot()
|
25
|
-
{
|
26
|
-
|
27
|
-
//角度を30度~60度の間で発生
|
28
|
-
deg = rand.Next(30, 60);
|
29
|
-
|
30
|
-
this.ballPos_x = 10; //x座標の初期位置
|
31
|
-
this.ballPos_y = 650; //y座標の初期位置
|
32
|
-
InitializeComponent();
|
33
|
-
|
34
|
-
PictureBox1.Left = 150; //カゴのy座標の初期位置
|
35
|
-
PictureBox1.Top = 500; //カゴのx座標の初期位置
|
36
|
-
|
37
|
-
//マウスホイールイベントの追加
|
38
|
-
this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.Scroll_MouseWheel);
|
39
|
-
|
40
|
-
//タイマーイベント
|
41
|
-
Timer timer = new Timer();
|
42
|
-
timer.Interval = 50;
|
43
|
-
timer.Tick += new EventHandler(Update);
|
44
|
-
//timer.Start();
|
45
|
-
|
46
|
-
}
|
47
|
-
|
48
|
-
private void Update(object sender, EventArgs e)
|
49
|
-
{
|
50
|
-
|
51
|
-
ballPos_x += vx * Math.Cos(deg * (Math.PI / 180));
|
52
|
-
ballPos_y += vy * Math.Sin(deg * (Math.PI / 180)) + g * t;
|
53
|
-
this.t++;
|
54
|
-
|
55
|
-
//再描写
|
56
|
-
Invalidate();
|
57
|
-
|
58
|
-
//ボールが画面の下を超えた場合
|
59
|
-
//繰り返しボールを飛ばす
|
60
|
-
if (ballPos_y > 650)
|
61
|
-
{
|
62
|
-
|
63
|
-
this.vx = power; //初速をpowerにする
|
64
|
-
this.vy = -30; //y座標の初速度を再び示す
|
65
|
-
this.g = 1.0; //加速度を再び示す
|
66
|
-
this.ballPos_x = 10; //x座標の初期位置に戻す
|
67
|
-
this.ballPos_y = 650; //y座標の初期位置に戻す
|
68
|
-
deg = rand.Next(30, 60); //角度を30度~60度に設定
|
69
|
-
this.t = 0;
|
70
|
-
this.t++;
|
71
|
-
ballPos_x += vx * Math.Cos(deg * (Math.PI / 180));
|
72
|
-
ballPos_y += vy * Math.Sin(deg * (Math.PI / 180)) + g * t;
|
73
|
-
|
74
|
-
}
|
75
|
-
|
76
|
-
//ボールとカゴの当たり判定
|
77
|
-
if ((ballPos_x > PictureBox1.Location.X) &&
|
78
|
-
(ballPos_x < PictureBox1.Left + PictureBox1.Size.Width) &&
|
79
|
-
(ballPos_y > PictureBox1.Location.Y) &&
|
80
|
-
(ballPos_y < PictureBox1.Top + PictureBox1.Size.Height))
|
81
|
-
{
|
82
|
-
|
83
|
-
this.vx = -1;
|
84
|
-
this.vy = -1;
|
85
|
-
|
86
|
-
}
|
87
|
-
|
88
|
-
}
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
}
|