I’m making a zombie survival game and I’ve come across a problem when I was making my ArrayList of bullets. The bullets show up on the screen but wont move. With some trouble shooting it looks like the variables “d” and “t” stay null. Some help would be appreciated.
class Bullet
{
PVector pos;
PVector spd;
float damage;
PVector t = null;
PVector d;
//constructor
Bullet (float x, float y)
{
pos = new PVector (x, y);
}
void update ()
{
display();
move();
}
//methods
void display ()
{
fill (#EDED54);
ellipse (pos.x, pos.y, 7, 7);
}
void move ()
{
if (t != null)
{
d = PVector.sub(t, pos);
d.setMag(3);
pos.add(d);
}
}
boolean gone()
{
if (pos.y < 0)
return true;
return false;
}
void keyReleased ()
{
if (key == ' ')
{
t = new PVector(mouseX, mouseY);
}
}
}