public void FillPowerup(Powerup pwr, int id) { int r = pwr.size / 2; for (int i = -r; i <= r; i++) for (int j = -r; j <= r; j++) if ((i * i) + (j * j) <= r * r) // disallow snake overriding if (!pointsHistory.ContainsKey(field[pwr.x + i, pwr.y + j])) field[pwr.x + i, pwr.y + j] = id; }
public void AddPowerup(Powerup p) { int powerupId = findPowerup(p); if ((powerupId == -1) || (p.unique == false)) { PowerupEffects.Start(this, p); powerups.Add(p); } else powerups[powerupId].expirationTime = p.expirationTime; }
public static void Start(Snake s, Powerup p) { switch (p.effect) { case Effects.greenSpeed: s.speed *= 2; s.turningSpeed *= 1.5; break; case Effects.redSpeed: s.speed *= 2; break; case Effects.greenSlow: s.speed /= 2; break; case Effects.redSlow: s.speed /= 2; s.turningSpeed /= 1.5; break; case Effects.greenThin: s.size /= 2; s.RecreateTrailingPen(); break; case Effects.redThick: s.size *= 2; s.RecreateTrailingPen(); break; case Effects.greenTurns: s.turningSpeed *= 1.5; break; case Effects.redTurns: s.turningSpeed /= 1.5; break; case Effects.greenRightAngle: case Effects.redRightAngle: s.rightAngleTurns = !s.rightAngleTurns; break; case Effects.greenInvisibility: s.isDrawing = false; break; case Effects.redInverse: s.inverse *= -1; break; default: break; } }
int findPowerup(Powerup pwr) { for (int i = 0; i < powerups.Count; i++) if (powerups[i].effect == pwr.effect) return i; return -1; }