Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
309 views
in Technique[技术] by (71.8m points)

python - 红点移动时,蓝点如何移动?(How to move with blue dot while red dot is moving?)

I want to move with joystick a blue dot while red dot is randomly falling, but if I press joystick, blue dot doesn't show or move.

(我想用操纵杆移动一个蓝点,而红色点随机下落,但是如果按操纵杆,则蓝点不会显示或移动。)

I use raspberry Pi 3 and Sense hat(led metrix and joystick)

(我使用树莓派3和Sense帽子(led metrix和操纵杆))

Here is my code: (it's for rasberry pi and Sense hat)

(这是我的代码:(用于rasberry pi和Sense hat))

x = 0
y = 7

while True:

    x1 = randint(0,7)
    y1 = 0

    start_number = 1

    for i in range(start_number,1000, 1):
        print(i)
        sense.set_pixel(x1, y1, (255, 58, 0))
        y1 = y1 + 1
        sleep(1)
        sense.clear()

        if y1 > 7:
            y1 = 0
            x1 = randint(0,7)

    for event in sense.stick.get_events():

        sense.set_pixel(x, y, (77, 195, 255))




    #Check if the joystick was pressed
    if event.action == "pressed":


      # Check which direction
      if event.direction == "up" and x > 0:
        x = x - 1
        sense.clear()

      elif event.direction == "down" and x < 7:
        x = x + 1
        sense.clear()

      elif event.direction == "left" and y < 7:
        y = y + 1
        sense.clear()

      elif event.direction == "right" and y > 0:
        y = y - 1
        sense.clear()

      elif event.direction == "middle":
        sense.set_pixel(x - x, y - y, (77, 195, 255))
        sense.clear()
  ask by Tom hala translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...