hi
I'm writing a small game and need to pass an image into an ArrayList. The Image and bounds are set in Attacker Class with an ArrayList partially constructed in my GameScrn Class posted below. Have spent 2 days on this one issue and failing badly...guessing as usual, im missing something really simple.
any help please...
package castledefender;
import java.awt.Graphics;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
/**
*
* @author paul
*/
public class GameScrn extends JComponent implements Runnable
{
public int lastx = 0;
public int lasty = 0;
//place images into icons
private ImageIcon castle = new ImageIcon(getClass().getResource("background.jpg"));
private ImageIcon turret = new ImageIcon(getClass().getResource("turret1.gif"));
private Defender def = new Defender(this);
// private Attacker att = new Attacker(this);
private Missile miss = new Missile(this);
private Thread animation = new Thread(this);
public ArrayList<Attacker> atk = new ArrayList<Attacker>();
GameScrn()
{
Object[] ol = atk.toArray();
System.out.println(ol);
animation.start();
}
public void run()
{
while (true)
{
repaint();
try
{
Thread.sleep(30);
}
catch (InterruptedException ex)
{
}
}
}
@Override
public void paint(Graphics g)
{
g.drawImage(castle.getImage(), 0, 0, this);//draw background image
def.draw(g);//draw defender
miss.draw(g);//draw missile
g.drawImage(turret.getImage(), 0, 11, this);//set position of gif image on top of defender and castle
//att.add(new Attacker(this));
System.out.println("contents of att = " + atk);
// att.draw(g);//draw attacker
atk.add(new Attacker(this));
}
public void moveDef(int hMove, int vMove)
{
def.moveDef(hMove, vMove);
//miss.moveMiss(hMove, vMove);
}
public void moveAtk(int hMove, int vMove)
{
}
public void moveMiss(int hMove, int vMove)
{
miss.moveMiss(hMove, vMove);
System.out.println("Vmove" + vMove);
}
}