Can anyone spot the problem?
if(bulletCreated)
{
if(shipBullet.bulletMissed())
{
bulletCreated = false;
updatePlayerScore(-100);
}
}
why after a bullet has missed would 100 be taken off once and then once again when fire is next pressed if this is the only place that 100 is ever taken off the score?
thanks to whoever can solve this, it is part of my mainloop in a game
It seems like after you create that second bullet, shipBullet.bulletMissed() is still returning true. Is there something you need to do to update the value of bulletMissed? eg:
Then of course setBulletMissed would have to affect the result of getBulletMissed...
if(bulletCreated){ if(shipBullet.getBulletMissed()) { bulletCreated = false; updatePlayerScore(-100); shipBullet.setBulletMissed(false); }}
Then of course setBulletMissed would have to affect the result of getBulletMissed...
I can't exactly see what is wrong here, but I think you need to post more of your code. From what you've posted its hard to tell what is going on when the code exectutes.
-Limb
-Limb
You reset bulletCreated somewhere else in your code to true. That is why I think the -100 happens twice. I agree that more code is needed though.
if(bulletCreated)
{
if(hit an alien)
{
bulletCreated = false;
updatePlayerScore(1000);
}
if(shipBullet.bulletMissed())
{
bulletCreated = false;
updatePlayerScore(-100);
}
}
public void updatePlayerScore(int add)
{
playerScore += add;
if(playerScore > highScore) highScore = playerScore;
}
also have:
if(!fireKeyPressed) spaceReleased = true;
if(fireKeyPressed&&(!playerDead)&&spaceReleased&& !soundManager.isPlayingSound()&&(!bulletCreated))
{
boolean firePressed = true;
spaceReleased = false;
if(firePressed)
{
tryToFire();
}
}
and:
public void tryToFire()
{
shipBullet.renderBullet();
bulletCreated = true;
}
and that is all that is involved with it really!
{
if(hit an alien)
{
bulletCreated = false;
updatePlayerScore(1000);
}
if(shipBullet.bulletMissed())
{
bulletCreated = false;
updatePlayerScore(-100);
}
}
public void updatePlayerScore(int add)
{
playerScore += add;
if(playerScore > highScore) highScore = playerScore;
}
also have:
if(!fireKeyPressed) spaceReleased = true;
if(fireKeyPressed&&(!playerDead)&&spaceReleased&& !soundManager.isPlayingSound()&&(!bulletCreated))
{
boolean firePressed = true;
spaceReleased = false;
if(firePressed)
{
tryToFire();
}
}
and:
public void tryToFire()
{
shipBullet.renderBullet();
bulletCreated = true;
}
and that is all that is involved with it really!
What compiler are you using?
Why dont you use the debugger and watch the code run. That is a 100% sure way to find out what is going on.
Why dont you use the debugger and watch the code run. That is a 100% sure way to find out what is going on.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement