from js import Image, window
sprites_url = "/apps/codejam/static/sprites/"
window.sprites = {}
for sprite in ['neptune', 'earthtest', 'moon', 'earth', 'jupiter', 'saturn', 'asteroids', 'mercury', 'health', 'uranus', 'Explosion Animation', 'spaceship', 'player', 'sun', 'scanner', 'mars', 'venus']:
# Skip the folder name "asteroid sprites" which would request "asteroid%20sprites.png"
if sprite == "asteroid sprites":
continue
window.sprites[sprite] = Image.new()
window.sprites[sprite].src = sprites_url + sprite + ".png"
window.audio_list = ['music_main.ogg', 'text.ogg', 'explosion.ogg', 'music_thematic.ogg', 'bang1.ogg', 'bang3.ogg', 'scan.ogg', 'death.ogg', 'bang2.ogg']
window.sprites["asteroids"] = Image.new()
window.sprites["asteroids"].src = sprites_url + "asteroids.png"
window.planets = [{"id": 10, "name": "Sun", "sprite": "sun.png"}, {"asteroid": {"count": 7, "damage": 7, "durability": 4, "speed": 10}, "id": 199, "info": "PLANETARY SCAN COMPLETE: Mercury\n\n*******************************************************************************\n\n PHYSICAL DATA:\n Vol. Mean Radius (km) = 2439.4+-0.1 Density (g cm^-3) = 5.427\n Mass x10^23 (kg) = 3.302 Volume (x10^10 km^3) = 6.085 \n Sidereal rot. period = 58.6463 d Sid. rot. rate (rad/s)= 0.00000124001\n Mean solar day = 175.9421 d Core radius (km) = ~1600 \n Geometric Albedo = 0.106 Surface emissivity = 0.77+-0.06\n GM (km^3/s^2) = 22031.86855 Equatorial radius, Re = 2440.53 km\n GM 1-sigma (km^3/s^2) = Mass ratio (Sun/plnt) = 6023682\n Mom. of Inertia = 0.33 Equ. gravity m/s^2 = 3.701 \n Atmos. pressure (bar) = \u003c 5x10^-15 Max. angular diam. = 11.0\" \n Mean Temperature (K) = 440 Visual mag. V(1,0) = -0.42 \n Obliquity to orbit[1] = 2.11\u0027 +/- 0.1\u0027 Hill\u0027s sphere rad. Rp = 94.4 \n Sidereal orb. per. = 0.2408467 y Mean Orbit vel. km/s = 47.362 \n Sidereal orb. per. = 87.969257 d Escape vel. km/s = 4.435\n Perihelion Aphelion Mean\n Solar Constant (W/m^2) 14462 6278 9126\n Maximum Planetary IR (W/m^2) 12700 5500 8000\n Minimum Planetary IR (W/m^2) 6 6 6\n*******************************************************************************\n", "level": ["Mercury - Scan Required", "\n", "Asteroid counts : *******", "Asteroid speed : **********", "Asteroid damage : *******", "Asteroid durability: ****", "Scan difficulty : ********************", "\n", "Mercury\u0027s sparse asteroid field is more forgiving than most, but the", "Sun\u0027s proximity, and the constant bombardment of high-energy radiation", "particles will gnaw at the ship over time and slow damage it.", "\n", "Ship controls:", "\tMovement: Arrow Keys or WASD", "\tUse scanner: Hold Spacebar"], "name": "Mercury", "scan_multiplier": 3.6, "sprite": "mercury.png", "x": 50464198.3250268, "y": 9059796.87177754}, {"asteroid": {"count": 12, "damage": 12, "durability": 8, "speed": 15}, "id": 299, "info": "PLANETARY SCAN COMPLETE: Venus\n\n*******************************************************************************\n\n PHYSICAL DATA:\n Vol. Mean Radius (km) = 6051.84+-0.01 Density (g/cm^3) = 5.204\n Mass x10^23 (kg) = 48.685 Volume (x10^10 km^3) = 92.843\n Sidereal rot. period = 243.018484 d Sid. Rot. Rate (rad/s)= -0.00000029924\n Mean solar day = 116.7490 d Equ. gravity m/s^2 = 8.870\n Mom. of Inertia = 0.33 Core radius (km) = ~3200\n Geometric Albedo = 0.65 Potential Love # k2 = ~0.25\n GM (km^3/s^2) = 324858.592 Equatorial Radius, Re = 6051.893 km\n GM 1-sigma (km^3/s^2) = +-0.006 Mass ratio (Sun/Venus)= 408523.72\n Atmos. pressure (bar) = 90 Max. angular diam. = 60.2\"\n Mean Temperature (K) = 735 Visual mag. V(1,0) = -4.40\n Obliquity to orbit = 177.3 deg Hill\u0027s sphere rad.,Rp = 167.1\n Sidereal orb. per., y = 0.61519726 Orbit speed, km/s = 35.021\n Sidereal orb. per., d = 224.70079922 Escape speed, km/s = 10.361\n Perihelion Aphelion Mean\n Solar Constant (W/m^2) 2759 2614 2650\n Maximum Planetary IR (W/m^2) 153 153 153\n Minimum Planetary IR (W/m^2) 153 153 153\n*******************************************************************************\n", "level": ["Venus - Scan Required", "\n", "Asteroid counts : ************", "Asteroid speed : ***************", "Asteroid damage : ************", "Asteroid durability: ********", "Scan difficulty : ************", "\n", "Piloting this dense asteroid field will keep you too busy to", "ponder the mysteries of what lies beneath Venus\u0027s veil of toxic clouds.", "Even the difficulties of navigating its orbit are better than the searing", "heat and crushing atmosphere of its surface.", "\n", "Ship controls:", "\tMovement: Arrow Keys or WASD", "\tUse scanner: Hold Spacebar"], "name": "Venus", "scan_multiplier": 1.6, "sprite": "venus.png", "x": 62265012.79592998, "y": 88255225.26065554}, {"asteroid": {"count": 5, "damage": 40, "durability": 19, "speed": 20}, "id": 399, "info": "PLANETARY SCAN COMPLETE: Mars\n\n*******************************************************************************\n\n PHYSICAL DATA:\n Vol. mean radius (km) = 3389.92+-0.04 Density (g/cm^3) = 3.933(5+-4)\n Mass x10^23 (kg) = 6.4171 Flattening, f = 1/169.779\n Volume (x10^10 km^3) = 16.318 Equatorial radius (km)= 3396.19\n Sidereal rot. period = 24.622962 hr Sid. rot. rate, rad/s = 0.0000708822 \n Mean solar day (sol) = 88775.24415 s Polar gravity m/s^2 = 3.758\n Core radius (km) = ~1700 Equ. gravity m/s^2 = 3.71\n Geometric Albedo = 0.150 \n\n GM (km^3/s^2) = 42828.375662 Mass ratio (Sun/Mars) = 3098703.59\n GM 1-sigma (km^3/s^2) = +- 0.00028 Mass of atmosphere, kg= ~ 2.5 x 10^16\n Mean temperature (K) = 210 Atmos. pressure (bar) = 0.0056 \n Obliquity to orbit = 25.19 deg Max. angular diam. = 17.9\"\n Mean sidereal orb per = 1.88081578 y Visual mag. V(1,0) = -1.52\n Mean sidereal orb per = 686.98 d Orbital speed, km/s = 24.13\n Hill\u0027s sphere rad. Rp = 319.8 Escape speed, km/s = 5.027\n Perihelion Aphelion Mean\n Solar Constant (W/m^2) 717 493 589\n Maximum Planetary IR (W/m^2) 470 315 390\n Minimum Planetary IR (W/m^2) 30 30 30\n*******************************************************************************\n", "level": ["Mars - Scan Required", "\n", "Asteroid counts : *****", "Asteroid speed : ******************", "Asteroid damage : ********************", "Asteroid durability: *******************", "Scan difficulty : ****************", "\n", "Though Mars\u0027s asteroid belt is deceptively thin, its dense icy rocks", "strike with brutal force. Here, survival depends not on dodging many,", "but on avoiding the few that could end you instantly.", "\n", "Ship controls:", "\tMovement: Arrow Keys or WASD", "\tUse scanner: Hold Spacebar"], "name": "Mars", "scan_multiplier": 2.6, "sprite": "mars.png", "x": 121056565.2223383, "y": -91071517.42399806}, {"asteroid": {"count": 12, "damage": 17, "durability": 3, "speed": 9}, "id": 499, "info": "PLANETARY SCAN COMPLETE: Earth\n\n*******************************************************************************\n\n GEOPHYSICAL PROPERTIES:\n Vol. Mean Radius (km) = 6371.01+-0.02 Mass x10^24 (kg)= 5.97219+-0.0006\n Equ. radius, km = 6378.137 Mass layers:\n Polar axis, km = 6356.752 Atmos = 5.1 x 10^18 kg\n Flattening = 1/298.257223563 oceans = 1.4 x 10^21 kg\n Density, g/cm^3 = 5.51 crust = 2.6 x 10^22 kg\n J2 (IERS 2010) = 0.00108262545 mantle = 4.043 x 10^24 kg\n g_p, m/s^2 (polar) = 9.8321863685 outer core = 1.835 x 10^24 kg\n g_e, m/s^2 (equatorial) = 9.7803267715 inner core = 9.675 x 10^22 kg\n g_o, m/s^2 = 9.82022 Fluid core rad = 3480 km\n GM, km^3/s^2 = 398600.435436 Inner core rad = 1215 km\n GM 1-sigma, km^3/s^2 = 0.0014 Escape velocity = 11.186 km/s\n Rot. Rate (rad/s) = 0.00007292115 Surface area:\n Mean sidereal day, hr = 23.9344695944 land = 1.48 x 10^8 km\n Mean solar day 2000.0, s = 86400.002 sea = 3.62 x 10^8 km\n Mean solar day 1820.0, s = 86400.0 Love no., k2 = 0.299\n Moment of inertia = 0.3308 Atm. pressure = 1.0 bar\n Mean surface temp (Ts), K= 287.6 Volume, km^3 = 1.08321 x 10^12\n Mean effect. temp (Te), K= 255 Magnetic moment = 0.61 gauss Rp^3\n Geometric albedo = 0.367 Vis. mag. V(1,0)= -3.86\n Solar Constant (W/m^2) = 1367.6 (mean), 1414 (perihelion), 1322 (aphelion)\n HELIOCENTRIC ORBIT CHARACTERISTICS:\n Obliquity to orbit, deg = 23.4392911 Sidereal orb period = 1.0000174 y\n Orbital speed, km/s = 29.79 Sidereal orb period = 365.25636 d\n Mean daily motion, deg/d = 0.9856474 Hill\u0027s sphere radius = 234.9 \n*******************************************************************************\n", "level": ["Earth - Scan Required", "\n", "Asteroid counts : ************", "Asteroid speed : *********", "Asteroid damage : *****", "Asteroid durability: *****************", "Scan difficulty : *********", "\n", "In high orbit over Earth, safely above the new asteroid fields, lies", "Chiaki Spacestation, which will afford you a unique opportunity for a", "ship repair upon completing this mission.", "\n", "Ship controls:", "\tMovement: Arrow Keys or WASD", "\tUse scanner: Hold Spacebar"], "name": "Earth", "scan_multiplier": 1.3, "sprite": "earth.png", "x": -205766295.2832569, "y": -121439888.7499874}, {"asteroid": {"count": 12, "damage": 10, "durability": 10, "speed": 15}, "id": 599, "info": "PLANETARY SCAN COMPLETE: Jupiter\n\n*******************************************************************************\n\n PHYSICAL DATA:\n Mass x 10^26 (kg) = 18.9819 Density (g/cm^3) = 1.3262 +- .0003\n Equat. radius (1 bar) = 71492+-4 km Polar radius (km) = 66854+-10\n Vol. Mean Radius (km) = 69911+-6 Flattening = 0.06487\n Geometric Albedo = 0.52 Rocky core mass (Mc/M)= 0.0261\n Sid. rot. period (III)= 9h 55m 29.711 s Sid. rot. rate (rad/s)= 0.00017585\n Mean solar day, hrs = ~9.9259 \n GM (km^3/s^2) = 126686531.900 GM 1-sigma (km^3/s^2) = +- 1.2732\n Equ. grav, ge (m/s^2) = 24.79 Pol. grav, gp (m/s^2) = 28.34\n Vis. magnitude V(1,0) = -9.40\n Vis. mag. (opposition)= -2.70 Obliquity to orbit = 3.13 deg\n Sidereal orbit period = 11.861982204 y Sidereal orbit period = 4332.589 d\n Mean daily motion = 0.0831294 deg/d Mean orbit speed, km/s= 13.0697\n Atmos. temp. (1 bar) = 165+-5 K Escape speed, km/s = 59.5 \n A_roche(ice)/Rp = 2.76 Hill\u0027s sphere rad. Rp = 740\n Perihelion Aphelion Mean\n Solar Constant (W/m^2) 56 46 51\n Maximum Planetary IR (W/m^2) 13.7 13.4 13.6\n Minimum Planetary IR (W/m^2) 13.7 13.4 13.6\n*******************************************************************************\n", "level": ["Jupiter - Scan Required", "\n", "Asteroid counts : ************", "Asteroid speed : ***************", "Asteroid damage : **********", "Asteroid durability: **********", "Scan difficulty : ************", "\n", "Besides Jupiter\u0027s dangerous asteroid fields, the solar system\u0027s", "largest planet has a strong gravitational field that you will", "constantly need to fight against lest it claims you for its endless", "storms.", "\n", "Ship controls:", "\tMovement: Arrow Keys or WASD", "\tUse scanner: Hold Spacebar"], "name": "Jupiter", "scan_multiplier": 1.8, "sprite": "jupiter.png", "x": -100070012.8507128, "y": 765661098.764396}, {"asteroid": {"count": 12, "damage": 18, "durability": 17, "speed": 16}, "id": 699, "info": "PLANETARY SCAN COMPLETE: Saturn\n\n*******************************************************************************\n\n PHYSICAL DATA:\n Mass x10^26 (kg) = 5.6834 Density (g/cm^3) = 0.687+-.001\n Equat. radius (1 bar) = 60268+-4 km Polar radius (km) = 54364+-10\n Vol. Mean Radius (km) = 58232+-6 Flattening = 0.09796\n Geometric Albedo = 0.47 Rocky core mass (Mc/M) = 0.1027\n Sid. rot. period (III)= 10h 39m 22.4s Sid. rot. rate (rad/s) = 0.000163785 \n Mean solar day, hrs =~10.656 \n GM (km^3/s^2) = 37931206.234 GM 1-sigma (km^3/s^2) = +- 98\n Equ. grav, ge (m/s^2) = 10.44 Pol. grav, gp (m/s^2) = 12.14+-0.01\n Vis. magnitude V(1,0) = -8.88 \n Vis. mag. (opposition)= +0.67 Obliquity to orbit = 26.73 deg\n Sidereal orbit period = 29.447498 yr Sidereal orbit period = 10755.698 d\n Mean daily motion = 0.0334979 deg/d Mean orbit velocity = 9.68 km/s\n Atmos. temp. (1 bar) = 134+-4 K Escape speed, km/s = 35.5 \n Aroche(ice)/Rp = 2.71 Hill\u0027s sphere rad. Rp = 1100\n Perihelion Aphelion Mean\n Solar Constant (W/m^2) 16.8 13.6 15.1\n Maximum Planetary IR (W/m^2) 4.7 4.5 4.6\n Minimum Planetary IR (W/m^2) 4.7 4.5 4.6\n*******************************************************************************\n", "level": ["Saturn - Scan Required", "\n", "Asteroid counts : ************", "Asteroid speed : ****************", "Asteroid damage : ******************", "Asteroid durability: *****************", "Scan difficulty : ****************", "\n", "When Sol\u0027s system passed through a vast galactic asteroid field,", "sometime in the early 23rd century, each planet captured its own", "share of asteroids into its orbit. The collisions between Saturn\u0027s", "newly captured asteroids and its already existing rings have created", "the perfect rock and ice maelstrom to test even the most daring pilots.", "\n", "Ship controls:", "\tMovement: Arrow Keys or WASD", "\tUse scanner: Hold Spacebar"], "name": "Saturn", "scan_multiplier": 2.6, "sprite": "saturn.png", "x": 1427205111.636179, "y": -76337597.30005142}, {"asteroid": {"count": 12, "damage": 18, "durability": 17, "speed": 16}, "id": 799, "info": "PLANETARY SCAN COMPLETE: Uranus\n\n*******************************************************************************\n\n PHYSICAL DATA:\n Mass x10^24 (kg) = 86.813 Density (g/cm^3) = 1.271\n Equat. radius (1 bar) = 25559+-4 km Polar radius (km) = 24973+-20\n Vol. Mean Radius (km) = 25362+-12 Flattening = 0.02293\n Geometric Albedo = 0.51\n Sid. rot. period (III)= 17.24+-0.01 h Sid. rot. rate (rad/s) = -0.000101237\n Mean solar day, h =~17.24 Rocky core mass (Mc/M) = 0.0012 \n GM (km^3/s^2) = 5793950.6103 GM 1-sigma (km^3/s^2) = +-4.3 \n Equ. grav, ge (m/s^2) = 8.87 Pol. grav, gp (m/s^2) = 9.19+-0.02\n Visual magnitude V(1,0)= -7.11\n Vis. mag. (opposition)= +5.52 Obliquity to orbit = 97.77 deg\n Sidereal orbit period = 84.0120465 y Sidereal orbit period = 30685.4 d\n Mean daily motion = 0.01176904 dg/d Mean orbit velocity = 6.8 km/s\n Atmos. temp. (1 bar) = 76+-2 K Escape speed, km/s = 21.3 \n Aroche(ice)/Rp = 2.20 Hill\u0027s sphere rad., Rp = 2700\n Perihelion Aphelion Mean\n Solar Constant (W/m^2) 4.09 3.39 3.71\n Maximum Planetary IR (W/m^2) 0.72 0.55 0.63\n Minimum Planetary IR (W/m^2) 0.72 0.55 0.63\n*******************************************************************************\n", "level": ["Uranus - Scan Required", "\n", "Asteroid counts : ************", "Asteroid speed : ****************", "Asteroid damage : ******************", "Asteroid durability: *****************", "Scan difficulty : ****************", "\n", "Viewed from far above, the tranquil appearance of Uranus masks a", "world of ever-present swirling storms and harsh winds laden with", "icy particles. ", "\n", "Ship controls:", "\tMovement: Arrow Keys or WASD", "\tUse scanner: Hold Spacebar"], "name": "Uranus", "scan_multiplier": 2.6, "sprite": "uranus.png", "x": 1548241220.947309, "y": 2474904952.161897}, {"asteroid": {"count": 14, "damage": 18, "durability": 17, "speed": 12}, "id": 899, "info": "PLANETARY SCAN COMPLETE: Neptune\n\n*******************************************************************************\n\n PHYSICAL DATA (update 2021-May-03):\n Mass x10^24 (kg) = 102.409 Density (g/cm^3) = 1.638\n Equat. radius (1 bar) = 24766+-15 km Volume, 10^10 km^3 = 6254 \n Vol. mean radius (km) = 24624+-21 Polar radius (km) = 24342+-30\n Geometric Albedo = 0.41 Flattening = 0.0171\n Sid. rot. period (III)= 16.11+-0.01 hr Sid. rot. rate (rad/s) = 0.000108338 \n Mean solar day, h =~16.11 h \n GM (km^3/s^2) = 6835099.97 GM 1-sigma (km^3/s^2) = +-10 \n Equ. grav, ge (m/s^2) = 11.15 Pol. grav, gp (m/s^2) = 11.41+-0.03\n Visual magnitude V(1,0)= -6.87\n Vis. mag. (opposition)= +7.84 Obliquity to orbit = 28.32 deg\n Sidereal orbit period = 164.788501027 y Sidereal orbit period = 60189 d\n Mean daily motion = 0.006020076dg/d Mean orbit velocity = 5.43 km/s \n Atmos. temp. (1 bar) = 72+-2 K Escape speed (1 bar) = 23.5 km/s \n Aroche(ice)/Rp = 2.98 Hill\u0027s sphere rad., Rp = 4700\n Perihelion Aphelion Mean\n Solar Constant (W/m^2) 1.54 1.49 1.51\n Maximum Planetary IR (W/m^2) 0.52 0.52 0.52\n Minimum Planetary IR (W/m^2) 0.52 0.52 0.52\n*******************************************************************************\n", "level": ["Neptune - Scan Required", "\n", "Asteroid counts : **************", "Asteroid speed : ************", "Asteroid damage : ******************", "Asteroid durability: *****************", "Scan difficulty : ************", "\n", "Neptune reigns at the edge of humanity\u0027s realm of reasonable exploration;", "You may be too busy dodging asteroids to fully its deep, arresting blue.", "\n", "Ship controls:", "\tMovement: Arrow Keys or WASD", "\tUse scanner: Hold Spacebar"], "name": "Neptune", "scan_multiplier": 2.2, "sprite": "neptune.png", "x": 4470024777.676497, "y": 12434785.46605173}]
for planet in window.planets:
planet["spritesheet"] = Image.new()
planet["spritesheet"].src = sprites_url + planet["sprite"]
window.credits = "MISSION COMPLETE!\n\nA Space Exploration Adventure\nMade for Python Discord\u0027s 2025 CodeJam\n\"Wrong Tool for the Job\"\n\nDeveloper Team (Cool Cacti)\n\nDark_Zero\nDoomy\nRealisticTurtle\nSoosh\n\nSpecial Thanks (Music by)\nElemeno Peter\n\n\nThank you for playing!\n\n\n\n\nGreat job on scanning a grand total 8e0 planets!\n\n\n\n\nAre you still here?\n\n\n\n\n\n\n\n\nThe credits are already over.\n\n\n\n...can we move on?\n\n\n\n\n\n\n\n42"
window.lore = "Why does boss want so much info on random planets...?\nYeah man...this mission seems pointless. We already scanned 2.3e+15 planets yesterday, including rogue ones...what could he possibly do with all that data?\nWell, at least we can scan efficiently. Remember yesterday? We were scanning 8e+10 planets per second!\nThat\u0027s true. I heard some civilizations actually need to be in orbit to get a planet\u0027s data!\nSeriously?? I remember a few years ago we only had a range of a light-year, even that was terrible...\nI can\u0027t imagine such primitive technology!\nYeah, if you had to orbit each planet, you couldn\u0027t travel 200x light speed!\nI bet their technology is so bad that they have to stay in orbit for a minute or so just to scan one planet.\nReally now? Then they could only get hundreds of planets a day then.\nBoss won\u0027t even consider a number without scientific notation nowadays...\nYeah, at least we\u0027re advanced...anyway, let\u0027s get the day started. Turn on the planet scanner!\n*Flips switch* Hey! The terminal is reading SyntaxError: invalid syntax on line 42: print(hello world).\n??? What do you mean, shouldn\u0027t the console print \u0027hello world\u0027?\nNo, dingus. There aren\u0027t quotes. No wonder you failed programming 101...\nSince you\u0027re soooo smart, why don\u0027t you fix the error?\nWe don\u0027t have access to the source code of this ship...\nWhat does that mean...?\nI can\u0027t fix the error, we can\u0027t scan planets.\nARE YOU SERIOUS!!! We are 12 TRILLION universes away from home, and NOW you tell me that?\nNot my fault, man. We\u0027ll be fine though. I just remembered that I have this wireless barcode scanner from work that I accidentally took from my shift. It only has a range of several hundred km though, so we\u0027ll have to go orbit planets for a minute or so to scan them.\nUhm, excuse me? That sounds just like that primitive technology! I am NOT having it!\nBoss will kill us if we return home with no planet data...\nBut..a barcode scanner? To scan a planet? That\u0027s INSANE!\nWe\u0027ll have to make do with......THE WRONG TOOL FOR THE JOB."
# exposing canvas globally (used by Player clamp logic)
from js import document
window.canvas = document.getElementById('gameCanvas')
# initialize game scripts
from audio import AudioHandler
window.audio_handler = AudioHandler("/apps/codejam/static/")
import game