Hello,
I have to Programm a game for a school project and decidet to do a shooter.I have the actor Spieler(player) and the actor Bullet. first i tryed to do the shooting with isKeydown but it shooted rapidly. then i tryed this code
now i can shoot single shots but when i hold space it CAN happen that the bullets been shot rapidly. how can i fix that?
the code for Bullet is just that
we have to write explanations as comments for our teacher, just ignore them.
1 2 3 4 5 6 7 | public void Fire() { if ( "space" .equals(Greenfoot.getKey())) getWorld().addObject( new Bullet(), getX(), getY()); } |
1 2 3 4 5 6 7 8 | public void act() { /** * die Location des Bullets wird ermittel und auf der x axe mit dem speed von 16 versetzt */ setLocation(getX() + 16 , getY()); } |