2
I’m creating a little game Jframe where I need to create several rectangles that will be the projectiles/bullets of my character(main/main) then I created the following class:
Bullet Class
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 button C She always fires 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?
}
}
In which package is the Main class? You managed to overwrite the method
keyPressed()
correctly?– Math
in the dannark package, but actually Voce doesn’t need to be based on my code, I would just need a
luz
how to do this so that I can adapt myself later :) The codes I showed above were supposed to be examples but I think I messed up a little bit.– Dannark
OBS The keyPressed() It works perfectly the problem is that the way I did I can shoot only one projectile at a time...
– Dannark
How many projectiles should I shoot? Wouldn’t it be the case to make a
for
?– Math
as much as it is necessary, every time I shoot I shoot 1 time, but if the user prices 100 times in a second for example, I wanted 100 projectiles to come out. If the case were as it would be?
– Dannark
Now I understand, but I find it strange not to shoot several. Can you tell what is the "limit" of balls that shoots? Example: if press 2 times in a second is ok, more than that gives dick. O
for
I suggested when I hadn’t quite understood your question, forget it.– Math
Do not see well, for now I would not like to impose limits.. the problem is that I do not know how to draw more than one rectangle... In other words I instanceio the bullets class: bullet = new bullet(x,y-25,6,3,direction); and then somewhere I draw her bullet.draw(main.bbg); and when I Preciono C eu Seto the position for mega. x and mega. y that is my main character.
– Dannark
Let’s go continue this discussão in chat.
– Dannark