<commit_before>/*
 * astronauts
 * by @andres
 * http://bit.ly/bb-astro
 *
 * based on bitsbox activity "Escape Pod" (2902)
 */

fill('stars2')

saucerX = 350
saucerY = 900
astroCount = 5
astroSpeed = 20
rotationRevs = 100
rotationSecs = 500
driftOutSecs = 1
launchSecs = 3
planetBeatSecs = 4
resultDelaySecs = 1.5

planetStamps = [
  'mercury',
  'venus',
  'earth',
  'moon',
  'mars',
  'jupiter',
  'saturn',
  'neptune',
  'uranus',
  'pluto6'
]

launched = false
arrows = []
foundPlanets = []
score = 0
results = text("")
planet = stamp('pluto5',-100,400,200)
pod = stamp('saucer',saucerX,saucerY)
scoreboard = text(score,700,990,80,'white')

repeat(createAstro,astroCount)
delay(showArrows,driftOutSecs*1000)
pod.back()
updateScore()
createSun()
delay(startPlanets,3000)

// Workaround for delay function leak
sessionKey = random(9999999)

function startPlanets() {
    launchPlanet(sessionKey)
}

function launchPlanet(key) {
  // Only launch planet if this is the latest session
  currentSession = key == sessionKey
  if (!launched && currentSession) {
    planetIndex = random(10) - 1
    planetStamp = planetStamps[planetIndex]
    planetY = random(900)
    planet = stamp(planetStamp,-100,planetY,165+random(65))
    planet.rotate((random(100)+50)*360,rotationSecs*1000)
    planet.move(1000,planetY,5000)
    delay(function() { launchPlanet(key) },(planetBeatSecs+random(3)-1)*1000)
  }
}

function createSun() {
  sun = stamp('sun',30)
  sun.back()
}

function createArrow() {
  arrow = stamp('arrow3',205)
  arrow.hide()
  arrow.move()
  arrow.rotate()
  arrow.rotate(rotationRevs*360,rotationSecs*1000)
  arrows.push(arrow)
  return arrow
}

function createAstro() {
  astro = stamp('drifter',saucerX,saucerY,100)
  astro.arrow = createArrow()
  astro.move(arrow.x,arrow.y,driftOutSecs*1000)
  astro.rotate(arrow.rotation)
  astro.rotate(rotationRevs*360,rotationSecs*1000)
  astro.tap = thrust
}

function thrust() {
  this.change('flyer')
  this.rotate(this.rotation)
  sound('explosion')
}

function launch(target) {
  target.move(target.x,-600,launchSecs*1000)
}

function fly(astronaut) {
  astronaut.tap = undefined
  astronaut.arrow.hide()
  astronaut.move(UP,astroSpeed)
  if (astronaut.hits(planet)) {
    astronaut.explode()
    sound('nuke',60)
  }
  if (astronaut.hits(pod)) {
    score++
    updateScore()
    astronaut.rotate(0).change('astro')
    sound('jump',30)
    if (launched) {
      sound('whoohoo')
      printResults()
    }
  }
}

function updateScore() {
  scoreboard.change(score)
}

function printResults() {
  results.hide()
  scoreboard.hide()
  messageX = 160
  if (score == 0) {
    message = 'nadie alcanzó'
    messageX += 110
    delay(soundToilet,resultDelaySecs)
  } else if (score == 1) {
    message = '¡salvaste a 1 astronauta!'
    messageX += 40
  } else if (score > 1 && score < astroCount) {
    message = '¡salvaste a ' + score + ' astronautas!'
    messageX += 35
    delay(soundClaps,resultDelaySecs)
  } else {
    message = '¡salvaste a TODOS los astronautas!'
    messageX -= 80
    delay(soundApplause,resultDelaySecs)
  }
  results = text(message,messageX,990,'white')
}

function loop() {
  find('flyer').forEach(fly)
  saved = find('astro')
  drifting = find('drifter')
  if (drifting.length == 0) {
    pod.change('flying saucer')
    launch(pod)
    saved.forEach(launch)
    if (!launched) {
      printResults()
      sound('rocket',50)
      launched = true
    }
  }
}

function showArrows() {
  arrows.forEach(showArrow)
}

function showArrow(arrow) {
  arrow.back()
  arrow.show()
}

function soundToilet() {
  sound('toilet')
}

function soundClaps() {
  sound('claps')
}

function soundApplause() {
  sound('applause')
}
<commit_msg>Make sun grow and burn everything if not launched yet<commit_after>/*
 * astronauts
 * by @andres
 * http://bit.ly/bb-astro
 *
 * based on bitsbox activity "Escape Pod" (2902)
 */

fill('stars2')

saucerX = 350
saucerY = 900
astroCount = 5
astroSpeed = 20
rotationRevs = 100
rotationSecs = 500
driftOutSecs = 1
launchSecs = 3
planetBeatSecs = 4
resultDelaySecs = 1.5
sunSize = 30
sunGrowth = 0.012

planetStamps = [
  'mercury',
  'venus',
  'earth',
  'moon',
  'mars',
  'jupiter',
  'saturn',
  'neptune',
  'uranus',
  'pluto6'
]

launched = false
arrows = []
foundPlanets = []
score = 0
results = text('')
sun = stamp('sun2',sunSize)
planet = stamp('pluto5',-100,400,200)
pod = stamp('saucer',saucerX,saucerY)
scoreboard = text(score,700,990,80,'white')
planetKey = random(9999999)
sunKey = random(9999999)
logOffset = 50

repeat(createAstro,astroCount)
delay(showArrows,driftOutSecs*1000)
pod.back()
updateScore()
sun.back()
startSun()
delay(startPlanets,3000)

function startPlanets() {
  launchPlanet(planetKey)
}

function launchPlanet(key) {
  if (!launched && key == planetKey) {
    planetIndex = random(10) - 1
    planetStamp = planetStamps[planetIndex]
    planetY = random(900)
    planet = stamp(planetStamp,-100,planetY,165+random(65))
    planet.rotate((random(100)+50)*360,rotationSecs*1000)
    planet.move(1000,planetY,5000)
    delay(function() { launchPlanet(key) },(planetBeatSecs+random(3)-1)*1000)
  }
}

function startSun() {
  growSun(sunKey)
}

function growSun(key) {
  if (sunSize < 30000 && key == sunKey) {
    sun.back()
    sunSize += sunSize*sunGrowth
    sun.size(sunSize)
    delay(function() { growSun(key) },40)
  }
}

function createArrow() {
  arrow = stamp('arrow3',-1000,-1000,205)
  arrow.hide()
  arrow.move()
  arrow.rotate()
  arrow.rotate(rotationRevs*360,rotationSecs*1000)
  arrows.push(arrow)
  return arrow
}

function createAstro() {
  astro = stamp('drifter',saucerX,saucerY,100)
  astro.arrow = createArrow()
  astro.move(arrow.x,arrow.y,driftOutSecs*1000)
  astro.rotate(arrow.rotation)
  astro.rotate(rotationRevs*360,rotationSecs*1000)
  astro.tap = thrust
}

function thrust() {
  this.change('flyer')
  this.rotate(this.rotation)
  sound('explosion')
}

function launch(target) {
  target.move(target.x,-600,launchSecs*1000)
}

function fly(astronaut) {
  astronaut.tap = undefined
  astronaut.arrow.hide()
  astronaut.move(UP,astroSpeed)
  if (astronaut.hits(planet)) {
    astronaut.explode()
    sound('nuke',60)
  }
  if (astronaut.hits(pod)) {
    score++
    updateScore()
    astronaut.rotate(0).change('astro')
    sound('jump',30)
    if (launched) {
      sound('whoohoo')
      printResults()
    }
  }
}

function updateScore() {
  scoreboard.change(score)
}

function printResults() {
  results.hide()
  scoreboard.hide()
  messageX = 160
  if (score == 0) {
    message = 'nadie alcanzó'
    messageX += 110
    delay(soundToilet,resultDelaySecs)
  } else if (score == 1) {
    message = '¡salvaste a 1 astronauta!'
    messageX += 40
  } else if (score > 1 && score < astroCount) {
    message = '¡salvaste a ' + score + ' astronautas!'
    messageX += 35
    delay(soundClaps,resultDelaySecs)
  } else {
    message = '¡salvaste a TODOS los astronautas!'
    messageX -= 80
    delay(soundApplause,resultDelaySecs)
  }
  results = text(message,messageX,990,'white')
}

function loop() {
  find('flyer').forEach(fly)
  saved = find('astro')
  drifting = find('drifter')
  if (!launched && sunSize > 4000) {
    arrows.forEach(explode)
    saved.forEach(explode)
    drifting.forEach(explode)
    pod.explode()
    planet.explode()
    planetKey = -1
  } else if (drifting.length == 0) {
    pod.change('flying saucer')
    launch(pod)
    saved.forEach(launch)
    sun.move(sun.x,sunSize*4,launchSecs*1000)
    planet.move(planet.x,sunSize*4,launchSecs*1000)
    sunKey = -1
    if (!launched) {
      printResults()
      sound('rocket',50)
      launched = true
    }
  }
}

function showArrows() {
  arrows.forEach(showArrow)
}

function showArrow(arrow) {
  arrow.back()
  arrow.show()
}

function soundToilet() {
  sound('toilet')
}

function soundClaps() {
  sound('claps')
}

function soundApplause() {
  sound('applause')
}

function log(msg) {
  text(msg,50,logOffset,30,'white')
  logOffset += 50
}
{'fraction_non_alphanumeric': 0.150018752344043, 'fraction_numerical': 0.0466308288536067, 'mean_word_length': 3.990642545227698, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4853287', 'n_tokens_mistral': 3312, 'n_tokens_neox': 2977, 'n_words': 539}