I have a Player class, a Weapon class and a Projectile class in my applet game.

The weapon class uses Projectile objects when fired.

For example, everytime I click I want this code to execute:

projectileList.add( player.weapon.fire() );

player.weapon.fire() returns one or more projectiles that the projectileList handles every frame.
In every frame, the projectileList should render all the projectile objects in the list, like this:

for(int i = 0;i<projectileList.size();i++){
                projectileList.get(i).draw(g, this);
}

"g" is the Graphics object, and "this" is the image observer.
That's basically what I want to do; simply define the images inside the projectile class, so I can simply use them in a weapon class, like this:

myWeapon.projectile = new Projectile(Projectile.bullet);

But I have no idea how I define images inside the projectile class.

The only image loading code that seems to work for me is this one:

getImage(getCodeBase(),"bullet_machinegun.png");

These aren't working at all:

new ImageIcon("bullet_machinegun.png").getImage();
Toolkit.getDefaultToolkit().getImage("bullet_machinegun.png");

Do you have any ideas on how to make this work?

Anyone?
I'm really stuck right now and won't get far if I don't solve this issue. :(

in the 2 later methods, you have to supply the full path. you have to get the string version of the URL returned by getCodeBase(), and tack it onto the front of the image file name.

I think that should work, I don't know much about the URL class....

It works now, thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.