Skip to content

Instantly share code, notes, and snippets.

@Legend-of-iPhoenix
Created July 3, 2018 22:08
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 Legend-of-iPhoenix/1c8c848fe8154dd6ead19019ea4d2bf8 to your computer and use it in GitHub Desktop.
Save Legend-of-iPhoenix/1c8c848fe8154dd6ead19019ea4d2bf8 to your computer and use it in GitHub Desktop.
from sense_hat import SenseHat, ACTION_RELEASED
from signal import pause
import threading
x = 3
y = 3
xv = 1
yv = 1
sense = SenseHat()
sense.set_rotation(270)
sense.set_pixel(4,0,255,0,255)
coins = [[255, 255, 0] for j in range(64)]
def physics_handler():
threading.Timer(0.05, physics_handler).start()
global x,y,xv,yv
y += yv
if (y > 0):
y = y % 8
x += xv
if (x > 0):
x = x % 8
xv *= .98
yv -= .05
if (xv < .01):
xv = 0
if (yv < 0 and y <= 0):
yv = 0
y = 0
x = max(0, min(x, 7))
y = max(0, min(y,7))
if (yv or xv):
print((xv,yv))
sense.clear()
sense.set_pixel(int(x), int(y), 255, 255, 255)
def handle_movement(event):
global x,y,xv,yv,coins
if event.action != ACTION_RELEASED:
if event.direction == "right":
yv += .5
if event.direction == "down":
xv -= .5
if event.direction == "up":
xv += .5
sense.stick.direction_any = handle_movement
physics_handler()
pause()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment