-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyPanel.java
executable file
·119 lines (98 loc) · 2.41 KB
/
MyPanel.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
import java.awt.*;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Dimension;
public class MyPanel extends JPanel {
private MyModel mm;
private PlayerBullet[] pb;
private Enemy[] enemy;
private int px, py;
private int[] ex, ey;
private int NUM_BULLET;
private int NUM_ENEMY;
private int point;
private boolean isExprosion;
private Image playerimage;
private Image explosionimage;
public void setPlayerImage(Image playerimage){
this.playerimage = playerimage;
}
public void setExplosionImage(Image explosionimage){
this.explosionimage = explosionimage;
}
public void setPlayerx(int px){
this.px = px;
}
public void setPlayery(int py){
this.py = py;
}
public void setEnemyx(int[] ex){
this.ex = ex;
}
public void setEnemyy(int[] ey){
this.ey = ey;
}
public void setPlayerBullet(PlayerBullet[] pb) {
this.pb = pb;
}
public void setEnemy(Enemy[] enemy) {
this.enemy = enemy;
}
public void setNUM_BULLET(int NUM_BULLET){
this.NUM_BULLET = NUM_BULLET;
}
public void setNUM_ENEMY(int NUM_ENEMY){
this.NUM_ENEMY = NUM_ENEMY;
}
public void setPoint(int point){
this.point = point;
}
public void setIsExprosion(boolean isExprosion){
this.isExprosion = isExprosion;
}
public void setMyModel(MyModel mm){
this.mm = mm;
}
public boolean getIsExplosion(){
return this.isExprosion;
}
public MyPanel(int px, int py) {
this.px = px;
this.py = py;
this.ex = ex;
this.ey = ey;
setBackground(Color.black);
setPreferredSize(new Dimension(1280, 720));
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Toolkit.getDefaultToolkit().sync();
//borderLine
g.drawLine(0, 360, 1280, 360);
//player
g.drawImage(this.playerimage, this.px, this.py, this);
//playerbullet
for (int i = 0; i < NUM_BULLET; i++) {
if (pb[i].isAlive()) {
pb[i].draw(g);
}
}
String point = String.valueOf(this.point);
//Playerpoint
g.setFont(new Font("MS ゴシック",Font.PLAIN,30));
g.drawString("Point: " + point, 10, 50);
for (int i = 0; i < NUM_ENEMY; i++) {
if (enemy[i].isAlive()){
enemy[i].draw(g);
}
}
//enemyExprosion
for (int i = 0; i < NUM_ENEMY; i++){
if (enemy[i].isCollision()) {
//System.out.println("Exprosion!! x-> " + enemy[i].getEnemyx() + "y -> " + enemy[i].getEnemyy());
g.drawImage(this.explosionimage, enemy[i].getEnemyx(), enemy[i].getEnemyy(), this);
}
}
requestFocusInWindow();
}
}