I'm creating a Jframe game where I need to create multiple rectangles that will be the projectiles / bullets of my main / I created the following class:
Class Bullets
package dannark;
import java.awt.Color;
import java.awt.Graphics;
public class balas {
int x,y,lar,alt;
String dir;
public balas(int x, int y, int lar, int alt, String dir){
this.x = x;
this.y = y;
this.lar = lar;
this.alt = alt;
this.dir = dir;
}
public void draw(Graphics bbg){
if(dir.equals("right")){
x += 10;
}else{
x -= 10;
}
bbg.setColor(Color.yellow);
bbg.fillRect(main.camX+x, main.camY+y, lar, alt);
}
}
More like I can call it in my main class so that when I press the C button it always shoots a new ball?
Main Class
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == e.VK_C){
//o que fazer aqui para spawnar varios novos retangulos?
}
}