Skip to content

Instantly share code, notes, and snippets.

@ntoll
Created April 10, 2018 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntoll/a1164abe53a0d1352fca939160d7aff8 to your computer and use it in GitHub Desktop.
Save ntoll/a1164abe53a0d1352fca939160d7aff8 to your computer and use it in GitHub Desktop.
Attack of the Killer-Cave Plotter from the Planet Raxxla!
"""
Attack of the Killer-Cave Plotter from the Planet Raxxla!
by Nicholas H.Tollervey. Released into the public domain.
Instructions:
Open Mu, put it into Adafruit mode and switch on the REPL
and plotter.
Rotate your Circuit Playground Express device along its X
axis to steer your space ship (the middle line) up or down.
Avoid the roof and floor of the cave.
Press CTRL-D to restart the game.
"""
import time
import random
from adafruit_circuitplayground.express import cpx
steps = 0 # The number of steps taken into the cave.
pause = 0.05 # The amount of time to sleep between steps.
roof = 100 # The reading for the cave roof.
width = 200 # The width of the cave (roof-width=floor).
spikiness = 10 # The amount of spikiness in the cave walls.
power_up = 200 # The number of steps before difficulty increases.
sensitivity = 10 # How sensitive to make the accelerometer reading.
while True:
time.sleep(pause) # Pause to make the game run at human speed.
steps += 1 # Increment the score.
x, y, z = cpx.acceleration # Read the X, Y, Z accelerometer values.
roof += random.randint(-spikiness, spikiness) # Change the roof value.
roof = max(-49, min(249, roof)) # Ensure the middle of the cave remains "around" 0.
floor = roof - width # Calculate the floor value.
player_position = x * sensitivity # Boost the accelerometer reading.
if steps % power_up == 0: # If we pass a power-up point...
# ...then make things a little more difficult.
pause -= 0.01 # Make the game faster.
spikiness += 2 # Make the cave walls more jagged.
width -= 5 # Make the cave a tighter fit.
print((roof, player_position, floor)) # Output the tuple for Mu's plotter.
if player_position >= roof or player_position <= floor: # Has the player crashed?
break # Yes! Break out the loop.
# End of game...
print("You crashed!")
print("Score: {}".format(steps))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment