*
* @param event - Event from View or Timer event
*/
private void checkInput(final QueueEvent event)
{
final Player player = model.getPlayer();
final boolean xVelocity = (player.getXVelocity() != 0);
final boolean yVelocity = (player.getYVelocity() != 0);
if (event instanceof ViewKeyPress)
{
final Keys code = ((ViewKeyPress) event).getKey();
final boolean pressed = ((ViewKeyPress) event).isPress();
switch (code)
{ //set velocity only if it's needed to set it, and reset it the same
case UP: if (pressed && !yVelocity)
{
player.setYVelocity(-player.getMaxVelocity());
}
else if (!pressed && yVelocity)
{
player.setYVelocity(0);
}
break;
case DOWN: if (pressed && !yVelocity)
{
player.setYVelocity(player.getMaxVelocity());
}
else if (!pressed && yVelocity)
{
player.setYVelocity(0);
}
break;
case LEFT: if (pressed && !xVelocity)
{
player.setXVelocity(-player.getMaxVelocity());
}
else if (!pressed && xVelocity)
{
player.setXVelocity(0);
}
break;
case RIGHT: if (pressed && !xVelocity)
{
player.setXVelocity(player.getMaxVelocity());
}
else if (!pressed && xVelocity)
{
player.setXVelocity(0);
}
break;
case PLANT: if (pressed)
{
model.plantBomb();
}
break;
case TIMER_1:
case TIMER_2:
case TIMER_3: if (pressed)
{
// depends on the number of timer enum, sets appropriate number of seconds
player.setBombTimer( (code.ordinal() - Keys.TIMER_1.ordinal() + 1) * 1000 );
}
break;
case PAUSE: if (pressed)
{
model.switchPause();