I'm making a bullet hell game , so I need to add simultaneously dozens of copies of the same bullet . I've chosen to make a 'base' bullet , than to clone it and add those clones in the world.
I use this code to create a clone, which I've found in a discussions :Those clones move as they should , but they don't interact with the player's hitbox
Hitbox code :
If I use bullets wich aren't clones everything works fine . Any tips?
public Object clone()
{
try{ Actor clone=(Actor)super.clone();
return clone;}
catch (CloneNotSupportedException cnse) // must be caught
{
System.out.println("Clone not supported");return null;
}
}public boolean checkHitbox()
{
Enemy_Bullet bullet = (Enemy_Bullet)getOneIntersectingObject(Enemy_Bullet.class);
ENEMY enemy = (ENEMY)getOneIntersectingObject(ENEMY.class);
if((bullet != null && getObjectsInRange(13,Enemy_Bullet.class).contains(bullet)
&& bullet.checkHitSomething()) ||
(enemy != null && getObjectsInRange(13,ENEMY.class).contains(enemy)
&& enemy.checkHitAvatar()))
{
invulnerability = 150;
bullet.setType(0);bullet.setImage();
if(invulnerability==0)return true;
}
if(invulnerability!=0)
{
invulnerability--;
}
return false;
}protected boolean checkHitSomething()
{
Hitbox hitbox = (Hitbox)getOneIntersectingObject(Hitbox.class);
switch(type)
{
case 0:if(getNeighbours(15,false,Hitbox.class).contains(hitbox)) return true;break;
case 1:if(getObjectsInRange(15,Hitbox.class).contains(hitbox)) return true;break;
case 2:if(getOneIntersectingObject(Hitbox.class)==hitbox) return true;break;
case 3:if(getObjectsInRange(8,Hitbox.class).contains(hitbox)) return true;break;
case 4:if(getObjectsInRange(28,Hitbox.class).contains(hitbox)) return true;break;
case 5:if(getObjectsInRange(50,Hitbox.class).contains(hitbox)) return true;break;
}
return false;
}


