L
Luc The Perverse
I have a class - it starts like this (the rest of the class is irrelevant)
class MazeWalker extends AdvanceSprite{
public static final int STILL = 0, MOVING = 1, WALKING=0, RUNNING=2;
public static final int LEFT = 1, RIGHT = 2, UP = 3, DOWN = 4;
. . .
I have an instantiation of the class called Heina
In another function in another class I am trying to implement this.
boolean okToFire = (timer==null) || timer.action(elapsedTime);
if (okToFire)
if(keyDown(KeyEvent.VK_SPACE)) {
switch(Heina.getDirection()){
case Heina.UP:
GOODBULLETS.add(new GoodBullet(getImages("Projectile.png",
2,1),Heina.getX()+Heina.getWidth()/2, +Heina.getY(),
Heina.getHorizontalSpeed(), -0.8+Heina.getVerticalSpeed()));
break;
case Heina.DOWN:
GOODBULLETS.add(new GoodBullet(getImages("Projectile.png",
2,1),Heina.getX()+Heina.getWidth()/2, +Heina.getY()+Heina.getHeight()/2,
Heina.getHorizontalSpeed(), 0.8+Heina.getVerticalSpeed()));
break;
case Heina.LEFT:
GOODBULLETS.add(new GoodBullet(getImages("Projectile.png",
2,1),Heina.getX(), +Heina.getY()+Heina.getHeight()/2,
Heina.getHorizontalSpeed()-0.8, Heina.getVerticalSpeed()));
break;
case Heina.RIGHT:
GOODBULLETS.add(new GoodBullet(getImages("Projectile.png",
2,1),Heina.getX()+Heina.getWidth(), +Heina.getY()+Heina.getHeight()/2,
Heina.getHorizontalSpeed()+0.8, Heina.getVerticalSpeed()));
break;
}
timer = new Timer(800);
}
else
timer=null;
But I get the error message
"Constant expression required" for each of my case statements. Doesn't my
declaration make those values constant?
class MazeWalker extends AdvanceSprite{
public static final int STILL = 0, MOVING = 1, WALKING=0, RUNNING=2;
public static final int LEFT = 1, RIGHT = 2, UP = 3, DOWN = 4;
. . .
I have an instantiation of the class called Heina
In another function in another class I am trying to implement this.
boolean okToFire = (timer==null) || timer.action(elapsedTime);
if (okToFire)
if(keyDown(KeyEvent.VK_SPACE)) {
switch(Heina.getDirection()){
case Heina.UP:
GOODBULLETS.add(new GoodBullet(getImages("Projectile.png",
2,1),Heina.getX()+Heina.getWidth()/2, +Heina.getY(),
Heina.getHorizontalSpeed(), -0.8+Heina.getVerticalSpeed()));
break;
case Heina.DOWN:
GOODBULLETS.add(new GoodBullet(getImages("Projectile.png",
2,1),Heina.getX()+Heina.getWidth()/2, +Heina.getY()+Heina.getHeight()/2,
Heina.getHorizontalSpeed(), 0.8+Heina.getVerticalSpeed()));
break;
case Heina.LEFT:
GOODBULLETS.add(new GoodBullet(getImages("Projectile.png",
2,1),Heina.getX(), +Heina.getY()+Heina.getHeight()/2,
Heina.getHorizontalSpeed()-0.8, Heina.getVerticalSpeed()));
break;
case Heina.RIGHT:
GOODBULLETS.add(new GoodBullet(getImages("Projectile.png",
2,1),Heina.getX()+Heina.getWidth(), +Heina.getY()+Heina.getHeight()/2,
Heina.getHorizontalSpeed()+0.8, Heina.getVerticalSpeed()));
break;
}
timer = new Timer(800);
}
else
timer=null;
But I get the error message
"Constant expression required" for each of my case statements. Doesn't my
declaration make those values constant?