help creating a bullet
in
Programming Questions
•
1 year ago
My program has 3 files - a main, an avatar class that creates the player, and an opponent class that creates the opponent.
I want my avatar and opponent to be able to fire bullets. At first I thought about created a separate bullet class and pass in the vector locations of the player/opponent but that didn't work.
class Bullet{
PVector pos;
void draw(){
ellipse(pos.x, pos.y, 10, 10);
}
void getLoc(PVector a){
pos.x=a.x;
pos.y=a.y;
}
}
Then in main I had
Bullet fire;
fire=new PVector();
if ( key == ' ' ) {
fire.getLoc( player.getPos() );
}
I kept getting a null pointer exception. Anyone got any other ideas about how I can implement the bullet?
I want my avatar and opponent to be able to fire bullets. At first I thought about created a separate bullet class and pass in the vector locations of the player/opponent but that didn't work.
class Bullet{
PVector pos;
void draw(){
ellipse(pos.x, pos.y, 10, 10);
}
void getLoc(PVector a){
pos.x=a.x;
pos.y=a.y;
}
}
Then in main I had
Bullet fire;
fire=new PVector();
if ( key == ' ' ) {
fire.getLoc( player.getPos() );
}
I kept getting a null pointer exception. Anyone got any other ideas about how I can implement the bullet?
1