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?