我是个业余爱好者,所以我还在学习。我放弃了我的旧代码,因为我很早就被卡住了。我想出了一个更“基于整数”的脚本,而不是使用预先设置的图像。我认为使用简单的整数可以更容易地使用控制流,操纵整数(因此也可以是图像),而不必更改和测试图像。我也在考虑用这两个按钮创建一个计算器,这样建议就会派上用场。谢谢你帮了我的忙!
下面是更新后的代码,以防您怀疑。我正在尝试添加随机敌人/墙生成:from microbit import *
import random
game_over == False
player_x = 2
player_y = 4
#starting coords for 'player' pixel
light = 5
wall_light = 7
#brightness. self explanatory
wall_pos_x = [0, 1, 2, 3, 4]
wall_y = 0
#all possible coords of wall. y coords
#are changed in function
#generates enemy wall with a randomly generated hole
def enemy_wall():
open_x = random.randint(0,4)
open_y = 0
for wall_xs in range(open_x-1, open_x, -1)
wall_pos_x[wall_xs]
pass
#for loops will iterate over all possible x coords except
#the open hole's coords. for loop will use iteration and
#display all possible x coords except open_x.
def player(x, y, bright):
if x <= -1:
x = 0
elif x >= 5:
x = 4
display.set_pixel(x,y,bright)
return x
#if x coord is +- 1 more than available coords,
#doesnt move/change position at edge
#updated newer player control. push of button changes x coord by -+ 1
#cannot change y coord
while game_over != True:
player(player_x,player_y,light)
sleep(750)
#player coords re/displayed, and button cooldown 750ms
if button_a.is_pressed():
player_x = player(player_x-1,player_y,light)
display.clear()
#runs through player(), then clears display of
#previous pixel *player*.
elif button_b.is_pressed():
player_x = player(player_x+1,player_y,light)
display.clear()