rric

alien_02

Nov 30th, 2021
637
121 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Alien invasion
  2. # Copyright 2021 Roland Richter
  3. # PRIMM Predict-Run-Investigate-Modify-Make
  4.  
  5. from microbit import *
  6. import scrollbit
  7.  
  8. is_alive = True
  9. cannon_x = 8
  10.  
  11. # skull ist Image.SKULL auf dem Kopf stehend
  12. skull = Image("09990:09990:99999:90909:09990")
  13. display.show(skull)
  14.  
  15. while is_alive:
  16.     acc_x = accelerometer.get_x()
  17.  
  18.     # Falls micro:bit nach rechts gedreht wird, vergrößere Position;
  19.     # falls micro:bit nach links gedreht wird, verkleinere Position.
  20.     if acc_x < -200:
  21.         cannon_x -= 0.5
  22.     elif acc_x > 200:
  23.         cannon_x += 0.5
  24.  
  25.     # Sorge dafür, dass Position innerhalb des Anzeige bleibt
  26.     # (die Position muss zwischen ___ und ___ sein).
  27.     if cannon_x < 1:
  28.         cannon_x = 1
  29.     elif cannon_x > 15:
  30.         cannon_x = 15
  31.  
  32.     # Lösche Anzeige und zeichne die Kanone in der ___ Zeile
  33.     scrollbit.clear()
  34.     # Die Kanone hat die Form ___
  35.     scrollbit.set_pixel(int(cannon_x)-1, 0, 64)
  36.     scrollbit.set_pixel(int(cannon_x)  , 0, 64)
  37.     scrollbit.set_pixel(int(cannon_x)+1, 0, 64)
  38.     scrollbit.set_pixel(int(cannon_x),   1, 64)
  39.  
  40.     scrollbit.show()
  41.    
  42. # ----------------------------------------------------------------------
  43. # This program is free software: you can redistribute it and/or modify
  44. # it under the terms of the GNU General Public License as published by
  45. # the Free Software Foundation, either version 3 of the License, or
  46. # (at your option) any later version.
  47. #
  48. # This program is distributed in the hope that it will be useful,
  49. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  50. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  51. # GNU General Public License for more details.
  52. #
  53. # You should have received a copy of the GNU General Public License
  54. # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  55.  
RAW Paste Data