I want to make the boost stop when the recharging meter is spent. however, if I hold onto the shift key, I boost infinitely. When I let go i can't boost again, but i want to make it so that the boost can stop while holding the shift if the meter is spent. Help? boost() just changes the velocity to 5 if that helps
import greenfoot.*;
/**
* protagonist actions
*
* @author Spooks
* @version 1.0
*/
public class _hero extends Mover
{
/**
* sets velocity and recharge
*/
public _hero()
{
// put your code here
this.velocity = 2;
this.rechargemtr = 20;
}
/**
* Act - do whatever the _hero wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move();
}
/**
* Moving actions
*/
public void move()
{
//moves ship accordingly
if(Greenfoot.isKeyDown("right")){
moveRight();
}
if(Greenfoot.isKeyDown("left")){
moveLeft();
}
if(Greenfoot.isKeyDown("up")){
moveUp();
}
if(Greenfoot.isKeyDown("down")){
moveDown();
}
//speeds up ship if shift is held
while(Greenfoot.isKeyDown("shift") && rechargemtr != 0){
boost();
setImage("heroboost.png");
rechargemtr--;
}
if(!Greenfoot.isKeyDown("shift")){
velocity = 2;
setImage("Hero.png");
}
}
/**
* regenerates boost meter
*/
public void regeneration(){
if(rechargemtr < 100 || rechargemtr == 0){
rechargemtr++;
}
}
}

