 LEDTable ledtable = LEDTable(2, 20, 15, PIXELORDER<flip_xy, snake>);
 
 int numberOfPlayers = 0;
+unsigned int frame;
 
 #define PINS_PER_PLAYER 2
 const int playerPins[MAXIMUM_NUMBER_OF_PLAYERS][PINS_PER_PLAYER] = {{3,4},{5,6},{7,8},{9,10},{11,12},{13,A0},{A1,A2},{A3,A4}};
 const Color colors[MAXIMUM_NUMBER_OF_PLAYERS] = {color_red, color_green, color_yellow, color_violet, 
                                                  color_orange, color_darkgreen, color_darkgoldenrod, color_white};
 
-class Effect
-{
-private:
-  const Color colors[EFFECT_COLORS] = {color_black, color_black, color_black, color_black, color_black};
-  int x;
-  int y;
-  uint8_t color_index;
-  bool activated; 
-public:
-  Effect()
-  {
-    activated = false;
-    color_index = 0;
-  }
-
-  void activate()
-  {
-    for (int i = 10; i; i--)
-    {
-      x = random(ledtable.minX(), ledtable.maxX() + 1);
-      y = random(ledtable.minY(), ledtable.maxY() + 1);
-      activated = ledtable.at(x, y) == BACKGROUND_COLOR;
-      if (activated)
-      {
-        break;
-      }
-    }
-  }
-
-  void update()
-  {
-    if (activated)
-    {
-      paint();
-      collide();
-    }
-  }
-
-  void paint()
-  {
-    color_index = (color_index + 1) % EFFECT_COLORS;
-    ledtable.fill(x, y, colors[color_index]);
-  }
-
-  void collide()
-  {
-    
-  }
-};
-
-
-enum PlaterState {MOVING, EXPLODING, END_OF_EXPLOSION, DEAD};
+enum PlaterState {MOVING, EXPLODING, END_OF_EXPLOSION, DEAD, INVULNERABLE};
 enum PlayerDirection {DOWN = 0, LEFT = 1, UP = 2, RIGHT = 3, STANDING};
 enum ButtonState {CATCHING_INPUT, WAITING_FOR_PLAYER_TO_SWITCH_BACK};
+
+void letOtherPlayersCollide(int index);
+void speedup();
+void slowdown();
 
 class Player
 {

void loop()
{
  updatePlayers();
  ledtable.show();
  wait();
  frame++;


void catchInput()
{
  FOR_PLAYERS(i)
  {
    players[i].catchInput();
  }
}


void letOtherPlayersCollide(int index)
{
  bool collided = false;
  for (int i = index + 1; i < NUMBER_OF_PLAYERS; i++)
  {
    if (players[i].collidesWith(&players[index]) && players[index].collidesWith(&players[i]))
    {
      players[i].collided();
      collided = true;
    }
  }
  if (collided)
  {
    players[index].collided();
  }
}

/********************** Powerups ************************/

int time_between_frames;

void speedup()
{
  if (time_between_frames == TIME_BETWEEN_ROUNDS_MILLIS_SLOWDOWN)
  {
    time_between_frames = TIME_BETWEEN_ROUNDS_MILLIS;
  } else {
    time_between_frames = TIME_BETWEEN_ROUNDS_MILLIS_SPEEDUP;
  }
}

void slowdown()
{
  if (time_between_frames == TIME_BETWEEN_ROUNDS_MILLIS_SPEEDUP)
  {
    time_between_frames = TIME_BETWEEN_ROUNDS_MILLIS;
  } else {
    time_between_frames = TIME_BETWEEN_ROUNDS_MILLIS_SLOWDOWN;
  }
}


#define POWERUP_COLORS 3

Color powerup_colors[POWERUP_COLORS] = { SPEEDUP_COLOR, INVULNERABLE_COLOR, SLOWDOWN_COLOR };

void spawnPowerup()
{
  if (random(0, EXPECTED_TIME_BETWEEN_POWERUPS) == 0)
  {
      int x = random(ledtable.minX(), ledtable.maxX() + 1);
      int y = random(ledtable.minY(), ledtable.maxY() + 1);
      if (ledtable.at(x, y) == BACKGROUND_COLOR)
      {
        int choice = random(0, POWERUP_COLORS);
        ledtable.fill(x, y, powerup_colors[choice]);
      }
  }
}

void setup()
{
  // randomness
  uint8_t v = EEPROM.read(0);
  for (int i = 0; i < v; i++)
  {
    random(256);
  }
  EEPROM.write(0, random(256));
  frame = 1;
  time_between_frames = TIME_BETWEEN_ROUNDS_MILLIS;
  Serial.begin(9600);
  ledtable.begin();
  ledtable.fill(BACKGROUND_COLOR);
  //ledtable.brightness(50);
