ActionMissile类
public class ActionMissile {
public ArrayList<Missilies> missilies = new ArrayList<Missilies>();
public void paint(Graphics g, MainClass mc) {
url = mc.getDocumentBase();
missile = mc.getImage(url, "missile.png");
//missilies = p.getMissilies();
for (int i = 0; i < p.missilies.size(); i++ ) {
Missilies m = new Missilies(mc);
m = (Missilies) p.missilies.get(i);
g.drawImage(missile, x, y, mc);
}
}
主要课程
ActionMissile a;
public void init()
{
setSize(800, 600);
p = new Player(this);
e = new Enemy(this);
m = new Missilies(this);
a = new ActionMissile();
public void paint(Graphics g){
p.paint(g, this);
e.paint(g, this);
if (!p.missilies.isEmpty())
a.paint(g, this);
}
玩家类
@Override
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()){
case KeyEvent.VK_SPACE:{
if (lastKey == null || lastKey != e.getKeyChar()) {
lastKey = e.getKeyChar();
Missilies m = new Missilies(x,y);
m.fire();
missilies.add(m);
System.out.println("Missilies "+missilies);
答案 0 :(得分:0)
更改:
p.missilies.size()
要:
mc.p.missiles.size()
你想检查mc中的导弹。
这看起来像,因为你在以下方法中调用方法:
if (!p.missilies.isEmpty())
a.paint(g, this);
该代码在mc中。因此该代码中的p也属于mc。