-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enemy.java
76 lines (70 loc) · 1.69 KB
/
Enemy.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
package shooting;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
public class Enemy {
protected int x;
protected int y;
protected int width;
protected int height;
protected Image image;
protected MainPanel panel;
protected boolean isDead=false;
protected static final int SCROLL_SPEED=1;
//敵ã®å¢?
protected static final Point TOMB=new Point(-100, -100);
public boolean isAlive=true;
public Enemy(int x,int y,MainPanel panel) {
this.x=x;
this.y=y;
this.panel=panel;
loadImage();
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public Point getPos() {
return new Point(x,y);
}
public void setPos(int x,int y) {
this.x=x;
this.y=y;
}
public void draw(Graphics g) {
g.drawImage(image,x,y,null);
}
protected void loadImage() {
width=image.getWidth(panel);
height=image.getHeight(panel);
}
public boolean collideWith(Shot shot) {
// エイリアンã®çŸ©å½¢ã‚’求ã‚ã‚?
Rectangle rectAlien = new Rectangle(x, y, width, height);
// å¼¾ã®çŸ©å½¢ã‚’求ã‚ã‚?
Point pos = shot.getPos();
Rectangle rectShot = new Rectangle(pos.x, pos.y,
shot.getWidth(), shot.getHeight());
// 矩形åŒå£«ãŒé‡ãªã£ã¦ã?ã‚‹ã‹èª¿ã¹ã‚?
// é‡ãªã£ã¦ã?ãŸã‚‰è¡çªã—ã¦ã?ã‚?
return rectAlien.intersects(rectShot);
}
public void move() {
y=y+SCROLL_SPEED;
if(y>panel.HEIGHT) {
die();
}
}
public void die() {
x=TOMB.x;
y=TOMB.y;
isDead=true;
}
public boolean isInStage() {
// TODO 自動生æˆã•ã‚ŒãŸãƒ¡ã‚½ãƒ?ドã?»ã‚¹ã‚¿ãƒ?
return y>0;
}
}