• Create Account

#ActualBambooCatfish

Posted 17 September 2012 - 10:26 AM

Poor explination on my part.

I use weapons and bullets interchangably. I have an array that contains the bullets in my level object, used for updating/deleting/whatever. Weapon is simply a variable on my Player Object that holds the type of bullet to fire.

I tired to do what you said but I am still unsure of exactly how to implement it...

I created a fire function but its not working as expected. Ill show you some of the relevant code:

This is from my GameEntity class which is the parent class of the Player/Enemies. I set the direction to the players dirction and the position of it to the players position plus and offset so i looks like its coming out of the right spot.

public BaseWeapon fire(){
Vector2f position = getPosition();

weapon.setDirection(getDirection());
weapon.setLife(0);

if (getDirection() == 1){
weapon.setPosition(position.x + bulletOffset.x, position.y + bulletOffset.y);
}else{
weapon.setPosition(position.x, position.y + bulletOffset.y);
}

return weapon;
}


In my level I made a simple change (changed form the create to fire);

  if (player.getState() == GameEntity.State.shooting){

try{
System.out.println("Bullets:" + bullets.size());
}catch(Exception e){
System.out.println("Cant make a bullet");
}

}


It works for a hot minute but then it stops adding bullets. I'm guessing it beacuse its pass by reference in Java, but I havnt figured out a work around.

Thanks
Nick

#1BambooCatfish

Posted 17 September 2012 - 09:58 AM

Poor explination on my part.

I think its somewhat irrelevant for me to go into a convoluted explination right now as I think I understand what you are saying so i will see if I can get it to work.

Thanks

PARTNERS