Tech Support Guy banner
Status
Not open for further replies.
1 - 7 of 7 Posts

·
Registered
Joined
·
4 Posts
Discussion Starter · #1 ·
Hi, I keep getting this illegal start of expression error, and I cannot figure out where to fix it.
Any help would be greatly appreciated. It is the line "public void keyReleased(KeyEvent k) {}"

/********************************************************
*key listener events
******************************************************/
public void keyReleased(KeyEvent k){}
public void keyTyped(KeyEvent k){}
public void keyPressed(KeyEvent k){

int keyCode = k.getKeyCode();

switch (keyCode)
{
case KeyEvent.VK_LEFT:
//left arrow rotates ship left 5 degrees
ship.incFaceAngle(-5);
if (ship.getFaceAngle() > 0) ship.setFaceAngle(360-5);
break;

case KeyEvent.VK_RIGHT:
//right arrow rotates ship right 5 degrees
ship.incFaceAngle(5);
if (ship.getFaceAngle() > 360) ship.setFaceAngle(5);
break;

case keyEvent.VK_UP:
//up arrow adds thrust to ship (1/10 normal speed)
ship.setMoveAngle(ship.getFaceAngle() -90);
ship.incVelX(calcAngleMoveX(ship.getMoveAngle())*0.1);
ship.incVelY(calcAngleMoveY(ship.getMoveAngle())*0.1);
break;

//Ctrl, Enter, or Space can be used to fire weapon
case KeyEvent.VK_CONTROL:
case KeyEvent.VK_ENTER:
case KeyEvent.VK_SPACE:
//fire a bullet
currentBullet++;
if (currentBullet > BULLETS -1) currentBullet = 0;
bullet[currentBullet].setAlive(true);

//point bullet in same direction ship is facing
bullet[currentBullet].setX(ship.getX());
bullet[currentBullet].setY(ship.getY());
bullet[currentBullet].setMoveAngle(ship.getFaceAngle()-90);

//fire bullet at angle of the ship
double angle = bullet[currentBullet].getMoveAngle();
double svx = ship.getVelX();
double svy = ship.getVelY();
bullet[currentBullet].setVelX(svx + calcAngleMoveX(angle)*2);
bullet[currentBullet].setVelY(svy + calcAngleMoveY(angle)*2);
break;
}
}

Thanks in advance!
 

·
Registered
Joined
·
75 Posts
Honestly it has been a few years since I worked in java, so I would need to look it up in order to be correct.

I am just guessing that is what it has a problem with.
 
1 - 7 of 7 Posts
Status
Not open for further replies.
Top