bar_x = 0 in_missile = False missile_x = 0 missile_y = 0 point = 0 interval = 0 interval_step = 0 ufo_x = 0 ufo_y = 0 ufo_dx = 0 ufo_dy = 0 in_game = False def on_button_pressed_a(): global bar_x if bar_x > 0: led.unplot(bar_x, 4) bar_x = bar_x - 1 led.plot(bar_x, 4) input.on_button_pressed(Button.A, on_button_pressed_a) def on_button_pressed_ab(): global in_missile, missile_x, missile_y if not (in_missile): in_missile = True missile_x = bar_x missile_y = 3 input.on_button_pressed(Button.AB, on_button_pressed_ab) def on_button_pressed_b(): global bar_x if bar_x < 4: led.unplot(bar_x, 4) bar_x = bar_x + 1 led.plot(bar_x, 4) input.on_button_pressed(Button.B, on_button_pressed_b) def on_forever(): global point, interval, interval_step, ufo_x, ufo_y, ufo_dx, ufo_dy, bar_x, in_game, in_missile, missile_y point = 0 interval = 500 interval_step = 10 ufo_x = 0 ufo_y = 0 ufo_dx = 1 ufo_dy = 0 bar_x = 2 basic.show_string("GO!") led.plot(0, 0) led.plot(bar_x, 4) basic.pause(interval) in_game = True while in_game: if ufo_y == 0 and ufo_x == 4: ufo_dx = 0 ufo_dy = 1 elif ufo_y == 1 and ufo_x == 4: ufo_dx = -1 ufo_dy = 0 elif ufo_y == 1 and ufo_x == 0: ufo_dx = 0 ufo_dy = 1 elif ufo_y == 2 and ufo_x == 0: ufo_dx = 1 ufo_dy = 0 elif ufo_y == 2 and ufo_x == 4: ufo_dx = 0 ufo_dy = 1 elif ufo_y == 3 and ufo_x == 4: ufo_dx = -1 ufo_dy = 0 elif ufo_y == 3 and ufo_x == 0: in_game = False if in_game: if Math.random_range(0, 9) < 8: led.plot(ufo_x + ufo_dx, ufo_y + ufo_dy) led.unplot(ufo_x, ufo_y) ufo_x = ufo_x + ufo_dx ufo_y = ufo_y + ufo_dy else: game.set_score(point) game.game_over() basic.pause(interval) if in_game and in_missile: if missile_y < 0: led.unplot(missile_x, missile_y + 1) in_missile = False else: led.plot(missile_x, missile_y) led.unplot(missile_x, missile_y + 1) led.plot(ufo_x, ufo_y) if missile_x == ufo_x and missile_y == ufo_y: point = point + 1 in_missile = False ufo_x = 0 ufo_y = 0 ufo_dx = 1 ufo_dy = 0 if interval - interval_step >= 0: interval = interval - interval_step led.plot(ufo_x, ufo_y) for index in range(30): basic.pause(10) led.toggle(missile_x, missile_y) led.unplot(missile_x, missile_y) else: missile_y = missile_y - 1 led.plot(bar_x, 4) basic.forever(on_forever)