import QHos,QHled,QHaudio,QHinput,QHmathdef pre_run():returndef aftrer_run():returnmonster_1_x = Nonemonster_1_y = Nonehuman_x = Nonestep_time_ms = Nonemonster_1_refresh = Nonedef powerOn():global monster_1_x monster_1_x = 0global monster_1_y monster_1_y = 0global human_x human_x = 0global step_time_ms step_time_ms = 400global monster_1_refresh monster_1_refresh = 0 QHled.set_brightness(3) QHled.show_pic(QHled.HEART) QHaudio.set_volume(2) QHaudio.tone_ring(7) QHos.usleep(100) QHled.clear_led() QHled.show_pixel(human_x,4) while True: if not monster_1_y and not monster_1_refresh: monster_1_refresh= 1 monster_1_x = QHmath.random(0, 4) QHled.change_pixel(monster_1_x,monster_1_y) QHos.usleep(step_time_ms) QHled.cancel_pixel(monster_1_x,monster_1_y) monster_1_y = (monster_1_y if isinstance(monster_1_y, int) else 0) + 1 QHled.change_pixel(monster_1_x,monster_1_y) if monster_1_y == 4: if human_x == monster_1_x: monster_1_y = 0 monster_1_refresh = 0 QHled.change_pixel(human_x,4) else: break QHled.show_pic(QHled.NO) returndef buttonA_func():global human_x QHled.cancel_pixel(human_x,4) human_x = (human_x if isinstance(human_x, int) else 0) - 1if human_x <= 0: human_x = 0 QHled.change_pixel(human_x,4) returndef buttonB_func(): global human_x QHled.cancel_pixel(human_x,4) human_x = (human_x if isinstance(human_x, int) else 0) + 1if human_x >= 4: human_x = 4 QHled.change_pixel(human_x,4) returnQHinput.buttonA_listener(buttonA_func)QHinput.buttonB_listener(buttonB_func)powerOn()
总结:
提示:本文由电子发烧友社区发布,转载请注明以上来源。如需社区合作及入群交流,请添加微信EEFans0806,或者发邮箱liuyong@huaqiu.com。
原文标题:启鸿开发板试用体验:简单使用-接豆子游戏
文章出处:【微信公众号:电子发烧友开源社区】欢迎添加关注!文章转载请注明出处。
全部0条评论
快来发表一下你的评论吧 !