I made a pong game on the microsoft micr:bit a few weeks ago, thought I might share it with y'all. HOW TO PLAY THIS: go to makecode.microbit.org and make a new project. Go to the JAVASCRIPT section and delete the code in it, then paste the code in the notes and credits into it. Then boom, It works! Play using A and B to go up/down, and there is an AI to play against!
function unplot_enemy () { led.unplot(4, enemy_y) led.unplot(4, enemy_y + 1) } function plot_ball () { led.plot(ball_x, ball_y) } function plot_enemy () { led.plot(4, enemy_y) led.plot(4, enemy_y + 1) } input.onButtonPressed(Button.A, function () { unplot_player() if (!(player_y == 0)) { player_y += -1 } plot_player() }) function round_end () { basic.pause(200) ball_direction_x = randint(1, 2) ball_direction_y = randint(1, 2) player_y = 2 enemy_y = 2 ball_x = 2 ball_y = randint(1, 3) plot_player() plot_enemy() plot_ball() } function unplot_ball () { led.unplot(ball_x, ball_y) } input.onButtonPressed(Button.AB, function () { basic.clearScreen() ball_direction_x = randint(1, 3) ball_direction_y = randint(1, 2) player_y = 2 enemy_y = 2 ball_x = 2 ball_y = randint(1, 3) plot_player() plot_enemy() plot_ball() }) input.onButtonPressed(Button.B, function () { unplot_player() if (!(player_y == 3)) { player_y += 1 } plot_player() }) function unplot_player () { led.unplot(0, player_y) led.unplot(0, player_y + 1) } function plot_player () { led.plot(0, player_y) led.plot(0, player_y + 1) } let ball_y = 0 let ball_x = 0 let enemy_y = 0 let player_y = 0 let ball_direction_y = 0 let ball_direction_x = 0 ball_direction_x = randint(1, 2) ball_direction_y = randint(1, 2) player_y = 2 enemy_y = 2 ball_x = 2 ball_y = randint(1, 3) plot_player() plot_enemy() plot_ball() basic.forever(function () { plot_ball() basic.pause(250) unplot_ball() if (ball_y == 0) { ball_direction_y = 1 } if (ball_y == 4) { ball_direction_y = 2 } if (ball_x == 3) { if (ball_y == enemy_y) { ball_direction_y = 1 ball_direction_x = 1 } if (ball_y == enemy_y + 1) { ball_direction_y = 2 ball_direction_x = 1 } } if (ball_x == 1) { if (ball_y == player_y) { ball_direction_y = 1 ball_direction_x = 2 } if (ball_y == player_y + 1) { ball_direction_y = 2 ball_direction_x = 2 } } if (ball_direction_x == 1) { if (ball_direction_y == 1) { ball_x += -1 ball_y += 1 } if (ball_direction_y == 2) { ball_x += -1 ball_y += -1 } } if (ball_direction_x == 2) { if (ball_direction_y == 1) { ball_x += 1 ball_y += 1 } if (ball_direction_y == 2) { ball_x += 1 ball_y += -1 } } }) basic.forever(function () { basic.pause(300) unplot_enemy() if (enemy_y < ball_y && !(enemy_y == 3)) { enemy_y += 1 } if (enemy_y > ball_y && !(enemy_y == 0)) { enemy_y += -1 } plot_enemy() }) basic.forever(function () { }) basic.forever(function () { if (ball_x == -1 || ball_x == 5) { ball_direction_x = randint(1, 3) ball_direction_y = randint(1, 2) ball_x = 2 ball_y = randint(1, 3) plot_player() } })