-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBossBeam.java
143 lines (129 loc) · 3.35 KB
/
BossBeam.java
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
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import javax.swing.ImageIcon;
/*
* Created on 2005/03/19
*
*/
/**
* ビームクラス
*
* @author kozuka
*
*/
public class BossBeam {
// ビームのスピード
private static final int SPEED = 7;
// ビームの保管座標(画面に表示されない場所)
private static final Point STORAGE = new Point(-20, -20);
// ビームの位置(x座標)
private int x;
// ビームの位置(y座標)
private int y;
// ビームの幅
private int width;
// ビームの高さ
private int height;
// ビームの画像
private Image image;
// メインパネルへの参照
private MainPanel panel;
//コンストラクタ
public BossBeam(MainPanel panel) {
x = STORAGE.x;
y = STORAGE.y;
this.panel = panel;
// イメージをロード
loadImage();
}
/**
* ビームを移動する
*/
public void move(int i) {
// 保管庫に入っているなら何もしない
if (this.isInStorage()) {
return;
// 画面外のビームは保管庫行き
} else if (y > MainPanel.HEIGHT || y < 0 || x < 0 || x > MainPanel.WIDTH) {
this.store();
// 画面内なら移動
} else {
double degree = (double) Math.PI/4 + (double) ((double) Math.PI/2 / (MainPanel.getNumBossBeam() - 1)) * i;
this.x += BossBeam.SPEED * (double) Math.cos(degree);
this.y += BossBeam.SPEED * (double) Math.sin(degree);
}
}
/**
* ビームの位置を返す
*
* @return ビームの位置座標
*/
public Point getPos() {
return new Point(x, y);
}
/**
* ビームの位置をセットする
*
* @param x ビームのx座標
* @param y ビームのy座標
*/
public void setPos(int x, int y) {
this.x = x;
this.y = y;
}
/**
* ビームの幅を返す。
*
* @param width ビームの幅。
*/
public int getWidth() {
return width;
}
/**
* ビームの高さを返す。
*
* @return height ビームの高さ。
*/
public int getHeight() {
return height;
}
/**
* ビームを保管庫に入れる
*/
public void store() {
x = STORAGE.x;
y = STORAGE.y;
}
/**
* ビームが保管庫に入っているか
*
* @return 入っているならtrueを返す
*/
public boolean isInStorage() {
if (x == STORAGE.x && y == STORAGE.x) {
return true;
}
return false;
}
/**
* ビームを描画する
*
* @param g 描画オブジェクト
*/
public void draw(Graphics g) {
// ビームを描画する
g.drawImage(image, x, y, null);
}
/**
* イメージをロードする
*
*/
private void loadImage() {
ImageIcon icon = new ImageIcon(getClass().getResource("image/bossbeam.gif"));
image = icon.getImage();
// 幅と高さをセット
width = image.getWidth(panel);
height = image.getHeight(panel);
}
}