rric

alien_01

Nov 30th, 2021
681
129 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.  
  7. is_alive = True
  8. cannon_x = 3
  9.  
  10. while is_alive:
  11.     acc_x = accelerometer.get_x()
  12.  
  13.     # QUIZ Falls micro:bit nach ___ gedreht wird, vergrößere Position;
  14.     #      falls micro:bit nach ___ gedreht wird, verkleinere Position.
  15.     if acc_x < -200:
  16.         cannon_x -= 0.01
  17.     elif acc_x > 200:
  18.         cannon_x += 0.01
  19.  
  20.     # QUIZ Sorge dafür, dass Position innerhalb des Anzeige bleibt
  21.     #      (die Position muss zwischen ___ und ___ sein).
  22.     if cannon_x < 0:
  23.         cannon_x = 0
  24.     elif cannon_x > 4:
  25.         cannon_x = 4
  26.  
  27.     # QUIZ Lösche Anzeige und zeichne die Kanone in der ___ Zeile
  28.     display.clear()
  29.     display.set_pixel(int(cannon_x), 4, 9)
  30.  
  31.  
  32.     # PROBIERE Wie kannst du die Bewegung der Kanone schneller machen?
  33.  
  34. # ----------------------------------------------------------------------
  35. # This program is free software: you can redistribute it and/or modify
  36. # it under the terms of the GNU General Public License as published by
  37. # the Free Software Foundation, either version 3 of the License, or
  38. # (at your option) any later version.
  39. #
  40. # This program is distributed in the hope that it will be useful,
  41. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  42. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  43. # GNU General Public License for more details.
  44. #
  45. # You should have received a copy of the GNU General Public License
  46. # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  47.  
RAW Paste Data