I have made a score counter for my game, but whenever I shoot an enemy the score resets instead of adding.
Here is my code in MyWorld:
and this is my code in the projectile:
whenever I shoot the projectile and hit something, the code displays the amount of score it's supposed to, but when I shoot another projectile the score goes back down to 0, how do i fix this?
1 2 3 4 5 6 | public static int score= 0 ; public void act() { showText( "Score: " + score, 350 , 350 ); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | MyWorld score; int scoreUfo= 0 ; int scoreUfoRot= 0 ; int scoreUfoTel= 0 ; public void act() { if (getY()> 1 ) { this .move(); punkteAdd(); } else { this .getWorld().removeObject( this ); } } public void scoreAdd() { Actor Ufo; Ufo = this .getOneIntersectingObject(Ufo. class ); if (Ufo != null ) { scoreUfo=scoreUfo+ 10 ; } Actor UfoRot; UfoRot = this .getOneIntersectingObject(UfoRotating. class ); if (UfoRot != null ) { scoreUfoRot=scoreUfoRot+ 20 ; } Actor UfoTel; UfoTel = this .getOneIntersectingObject(UfoTeleport. class ); if (UfoTel != null ) { scoreUfoTel=scoreUfoTel+ 50 ; } score.score=scoreUfo+scoreUfoRot+scoreUfoTel; } |