What I want to do is create some sort of a loop that goes back and forth between to states. One will countdown, the other count up.
My code as of now:
This does not work. shotCountDownPlayer ticks down by playerRateOfFire, but stops after one decerment.
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 39 40 41 42 43 44 45 | private int playersSpeed = 3 ; private int shotCountDownPlayer = 60 ; private int playerRateOfFire = 2 ; private boolean canShoot; public void act() { playerControlsMovement(); playerControlsFiring(); playersShooting(); } private void playerControlsMovement() { if ( this != null && Greenfoot.isKeyDown( "a" )) { move(-playersSpeed); } if ( this != null && Greenfoot.isKeyDown( "d" )) { move(playersSpeed); } } private void playerControlsFiring() { MyWorld spaceInvWorld = (MyWorld) getWorld(); worldBullet playersBullet = new worldBullet(); int turretY = getY()-getImage().getHeight()/ 2 ; if ( this != null && Greenfoot.isKeyDown( "space" ) && canShoot == true ) { spaceInvWorld.addObject(playersBullet, getX(), turretY); } } private void playersShooting() { while (shotCountDownPlayer >= 60 ) { shotCountDownPlayer = shotCountDownPlayer - playerRateOfFire; canShoot = true ; } if (shotCountDownPlayer <= 0 ) { shotCountDownPlayer = shotCountDownPlayer + playerRateOfFire; canShoot = false ; } } } |