From 9b861f7bf8e2366e384504dd0080f9ae31d865f4 Mon Sep 17 00:00:00 2001 From: HalloSpaceBoy <111699451+HalloSpaceBoy5@users.noreply.github.com> Date: Thu, 27 Apr 2023 20:16:01 -0400 Subject: [PATCH] Revised to add a score board --- Breakout/breakout.py | 63 ++++++++++++++++++++++++----- Breakout/highscoresbreakout.sc | 10 +++++ Flappy Bird/flappybird.py | 68 +++++++++++++++++++++++++++---- Flappy Bird/highscoresflappy.sc | 9 +++++ Starship/highscoresstarship.sc | 9 +++++ Starship/starship.py | 60 ++++++++++++++++++++++++++-- Tetris/highscorestetris.sc | 9 +++++ Tetris/tetris.py | 71 ++++++++++++++++++++++++++++----- 8 files changed, 268 insertions(+), 31 deletions(-) create mode 100644 Breakout/highscoresbreakout.sc create mode 100644 Flappy Bird/highscoresflappy.sc create mode 100644 Starship/highscoresstarship.sc create mode 100644 Tetris/highscorestetris.sc diff --git a/Breakout/breakout.py b/Breakout/breakout.py index ae992c7..3b50d99 100644 --- a/Breakout/breakout.py +++ b/Breakout/breakout.py @@ -44,16 +44,54 @@ def pause_screen(): elif pgb.button_select() or pgb.button_start(): sleep(0.5) return + +def append_to_board(score): + with open("highscoresbreakout.sc", "r") as s: + scores=s.read().split("\n") + for r in range(len(scores)): + scores[r]=int(scores[r]) + newscores=scores + newscores.append(int(score)) + newscores.sort(reverse=True) + for i in range(len(newscores)): newscores[i]=str(newscores[i]) + with open("highscoresbreakout.sc", "w+") as w: + w.write("\n".join(newscores[:10])) + +def view_scores(): + x=open("highscoresbreakout.sc", "r") + scores=x.read() + x.close() + del x + scores=scores.split("\n") + while True: + if pgb.button_B(): + sleep(0.1) + return + if pgb.button_Home(): + pgb.fill(PicoGameBoy.color(0,0,0)) + pgb.show() + machine.reset() + break + pgb.fill(PicoGameBoy.color(0,0,0)) + pgb.create_text("High Scores:", -1, 15, PicoGameBoy.color(255,255,255)) + for i in range(len(scores)): + pgb.create_text("Score "+str(i+1)+": "+str(scores[i]), -1, 50+i*15, PicoGameBoy.color(255,255,255)) + pgb.create_text("Press B to exit", -1, 220, PicoGameBoy.color(255,255,255)) + pgb.show() def title_screen(): # title screen now = ticks_ms() - while pgb.any_button()==False: + while True: if pgb.button_Home(): pgb.fill(PicoGameBoy.color(0,0,0)) pgb.show() machine.reset() break + if pgb.button_select() or pgb.button_start(): + view_scores() + elif pgb.any_button(): + break pgb.load_image("breakout_title.bin") pgb.show() @@ -64,31 +102,36 @@ def title_screen(): while ticks_diff(ticks_ms(), now) < 200: sleep(0.020) now = ticks_ms() + sleep(0.25) def game_over_screen(): global score global lives global playerx + append_to_board(score) playerx=100 lives=3 pgb.sound(0) - pgb.fill(PicoGameBoy.color(0,0,0)) - pgb.center_text("GAME OVER",PicoGameBoy.color(255,255,255)) - pgb.text("Press A to play again.", 35, 125, PicoGameBoy.color(255,255,255)) - pgb.text("Press home to quit.", 40, 140, PicoGameBoy.color(255,255,255)) - pgb.create_text("Score: "+str(score),-1,80,PicoGameBoy.color(255,255,255)) - pgb.show() - score=0 while True: + pgb.fill(PicoGameBoy.color(0,0,0)) + pgb.center_text("GAME OVER",PicoGameBoy.color(255,255,255)) + pgb.text("Press A to play again.", 35, 125, PicoGameBoy.color(255,255,255)) + pgb.text("Press home to quit.", 40, 140, PicoGameBoy.color(255,255,255)) + pgb.create_text("Press select/start", -1, 175, PicoGameBoy.color(255,255,255)) + pgb.create_text("to view scores.", -1, 190, PicoGameBoy.color(255,255,255)) + pgb.create_text("Score: "+str(score),-1,80,PicoGameBoy.color(255,255,255)) + pgb.show() if pgb.button_Home(): pgb.fill(PicoGameBoy.color(0,0,0)) pgb.show() machine.reset() break + if pgb.button_select() or pgb.button_start(): + view_scores() elif pgb.button_A(): - - return + score=0 + break def win_screen(): global score diff --git a/Breakout/highscoresbreakout.sc b/Breakout/highscoresbreakout.sc new file mode 100644 index 0000000..86807b4 --- /dev/null +++ b/Breakout/highscoresbreakout.sc @@ -0,0 +1,10 @@ +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 \ No newline at end of file diff --git a/Flappy Bird/flappybird.py b/Flappy Bird/flappybird.py index 4778405..b9caaa2 100644 --- a/Flappy Bird/flappybird.py +++ b/Flappy Bird/flappybird.py @@ -53,10 +53,44 @@ def sund(): playjump=False sleep(0.01) +def append_to_board(score): + with open("highscoresflappy.sc", "r") as s: + scores=s.read().split("\n") + for r in range(len(scores)): + scores[r]=int(scores[r]) + newscores=scores + newscores.append(int(score)) + newscores.sort(reverse=True) + for i in range(len(newscores)): newscores[i]=str(newscores[i]) + with open("highscoresflappy.sc", "w+") as w: + w.write("\n".join(newscores[:10])) + +def view_scores(): + x=open("highscoresflappy.sc", "r") + scores=x.read() + x.close() + del x + scores=scores.split("\n") + while True: + if pgb.button_B(): + sleep(0.1) + return + if pgb.button_Home(): + pgb.fill(PicoGameBoy.color(0,0,0)) + pgb.show() + machine.reset() + break + pgb.fill(PicoGameBoy.color(0,0,0)) + pgb.create_text("High Scores:", -1, 15, PicoGameBoy.color(255,255,255)) + for i in range(len(scores)): + pgb.create_text("Score "+str(i+1)+": "+str(scores[i])+" Pipes", -1, 50+i*15, PicoGameBoy.color(255,255,255)) + pgb.create_text("Press B to exit", -1, 220, PicoGameBoy.color(255,255,255)) + pgb.show() + def title_screen(): now = ticks_ms() pgb.free_mem() - while pgb.any_button()==False: + while True: if pgb.button_Home(): pgb.fill(PicoGameBoy.color(0,0,0)) pgb.show() @@ -64,6 +98,10 @@ def title_screen(): break pgb.load_image("flappybird_title.bin") pgb.show() + if pgb.button_select() or pgb.button_start(): + view_scores() + elif pgb.any_button(): + break if ticks_diff(ticks_ms(), now) > 200: now = ticks_ms() pgb.create_text("PRESS ANY BUTTON",20, 120,PicoGameBoy.color(0,0,0)) @@ -105,11 +143,13 @@ def check_collision(speed,detectionradius, posx, posy, width, height, posx2, pos def game_over(): global score - pgb.fill_rect(10,90,220,100,PicoGameBoy.color(0,0,0)) - pgb.center_text("GAME OVER",PicoGameBoy.color(255,255,255)) - pgb.text("Press A to play again.", 35, 125, PicoGameBoy.color(255,255,255)) - pgb.text("Press home to quit.", 40, 140, PicoGameBoy.color(255,255,255)) - pgb.create_text("Score: "+str(int(score/7)), -1, 155, PicoGameBoy.color(255,255,255)) + pgb.fill(PicoGameBoy.color(0,0,0)) + pgb.create_text("GAME OVER",-1, 85,PicoGameBoy.color(255,255,255)) + pgb.text("Press A to play again.", 35, 105, PicoGameBoy.color(255,255,255)) + pgb.text("Press home to quit.", 40, 120, PicoGameBoy.color(255,255,255)) + pgb.create_text("Press select/start", -1, 135, PicoGameBoy.color(255,255,255)) + pgb.create_text("to view scores.", -1, 150, PicoGameBoy.color(255,255,255)) + pgb.create_text("Score: "+str(int(score/7)), -1, 165, PicoGameBoy.color(255,255,255)) pgb.show() pgb.sound(110) sleep(0.05) @@ -119,12 +159,26 @@ def game_over(): sleep(0.05) pgb.sound(0) sleep(0.5) - while not pgb.any_button(): + append_to_board(score/7) + while True: if pgb.button_Home(): pgb.fill(PicoGameBoy.color(0,0,0)) pgb.show() machine.reset() break + pgb.fill(PicoGameBoy.color(0,0,0)) + pgb.create_text("GAME OVER",-1, 85,PicoGameBoy.color(255,255,255)) + pgb.text("Press A to play again.", 35, 105, PicoGameBoy.color(255,255,255)) + pgb.text("Press home to quit.", 40, 120, PicoGameBoy.color(255,255,255)) + pgb.create_text("Press select/start", -1, 135, PicoGameBoy.color(255,255,255)) + pgb.create_text("to view scores.", -1, 150, PicoGameBoy.color(255,255,255)) + pgb.create_text("Score: "+str(int(score/7)), -1, 165, PicoGameBoy.color(255,255,255)) + pgb.show() + if pgb.button_select() or pgb.button_start(): + view_scores() + elif pgb.button_A(): + score=0 + break sleep(0.5) main_game() diff --git a/Flappy Bird/highscoresflappy.sc b/Flappy Bird/highscoresflappy.sc new file mode 100644 index 0000000..c9d1fba --- /dev/null +++ b/Flappy Bird/highscoresflappy.sc @@ -0,0 +1,9 @@ +0 +0 +0 +0 +0 +0 +0 +0 +0 \ No newline at end of file diff --git a/Starship/highscoresstarship.sc b/Starship/highscoresstarship.sc new file mode 100644 index 0000000..c9d1fba --- /dev/null +++ b/Starship/highscoresstarship.sc @@ -0,0 +1,9 @@ +0 +0 +0 +0 +0 +0 +0 +0 +0 \ No newline at end of file diff --git a/Starship/starship.py b/Starship/starship.py index 674740e..c9470f3 100644 --- a/Starship/starship.py +++ b/Starship/starship.py @@ -231,6 +231,39 @@ def update(self): bullets.append( newB ) self.counter=self.counter+1 +def append_to_board(score): + with open("highscoresstarship.sc", "r") as s: + scores=s.read().split("\n") + for r in range(len(scores)): + scores[r]=int(scores[r]) + newscores=scores + newscores.append(int(score)) + newscores.sort(reverse=True) + for i in range(len(newscores)): newscores[i]=str(newscores[i]) + with open("highscoresstarship.sc", "w+") as w: + w.write("\n".join(newscores[:10])) + +def view_scores(): + x=open("highscoresstarship.sc", "r") + scores=x.read() + x.close() + del x + scores=scores.split("\n") + while True: + if pgb.button_B(): + sleep(0.1) + return + if pgb.button_Home(): + pgb.fill(PicoGameBoy.color(0,0,0)) + pgb.show() + machine.reset() + break + pgb.fill(PicoGameBoy.color(0,0,0)) + pgb.create_text("High Scores:", -1, 15, PicoGameBoy.color(255,255,255)) + for i in range(len(scores)): + pgb.create_text("Score "+str(i+1)+": Level "+str(scores[i]), -1, 50+i*15, PicoGameBoy.color(255,255,255)) + pgb.create_text("Press B to exit", -1, 220, PicoGameBoy.color(255,255,255)) + pgb.show() def rem_all_active(): @@ -256,6 +289,7 @@ def game_over_screen(): currentmusic=game_over rem_all_active() lives=3 + append_to_board(level) pgb.sound(0) pgb.fill(PicoGameBoy.color(0,0,0)) pgb.rect(70,20,100,80,PicoGameBoy.color(255,255,255)) @@ -268,16 +302,31 @@ def game_over_screen(): pgb.create_text("Press home to quit.", -1, 160, PicoGameBoy.color(255,255,255)) pgb.create_text("Level: "+str(level), -1, 180, PicoGameBoy.color(255,255,255)) pgb.show() - level=0 while True: + pgb.fill(PicoGameBoy.color(0,0,0)) + pgb.rect(70,20,100,80,PicoGameBoy.color(255,255,255)) + pgb.fill_rect(90, 30,10,10,PicoGameBoy.color(255,255,255)) + pgb.fill_rect(140, 30,10,10,PicoGameBoy.color(255,255,255)) + pgb.rect(90,60,60,20,PicoGameBoy.color(255,255,255)) + pgb.line(90,79,150,79,PicoGameBoy.color(0,0,0)) + pgb.create_text("Game Over",-1,125,PicoGameBoy.color(255,255,255)) + pgb.create_text("Press A to play again.", -1, 145, PicoGameBoy.color(255,255,255)) + pgb.create_text("Press home to quit.", -1, 160, PicoGameBoy.color(255,255,255)) + pgb.create_text("Press select/start", -1, 175, PicoGameBoy.color(255,255,255)) + pgb.create_text("to view scores.", -1, 190, PicoGameBoy.color(255,255,255)) + pgb.create_text("Level: "+str(level), -1, 205, PicoGameBoy.color(255,255,255)) + pgb.show() if pgb.button_Home(): pgb.fill(PicoGameBoy.color(0,0,0)) pgb.show() machine.reset() break + if pgb.button_select() or pgb.button_start(): + view_scores() elif pgb.button_A(): + level=0 no_music() - return + break def play_music(): global midi @@ -409,7 +458,7 @@ def title_screen(): rept=True currentmusic=title_theme now = ticks_ms() - while pgb.any_button()==False: + while True: if pgb.button_Home(): pgb.fill(PicoGameBoy.color(0,0,0)) pgb.show() @@ -417,7 +466,6 @@ def title_screen(): break pgb.load_image("starship_title.bin") pgb.show() - if ticks_diff(ticks_ms(), now) > 200: now = ticks_ms() pgb.create_text("PRESS ANY BUTTON",-1,160,PicoGameBoy.color(255,255,255)) @@ -425,6 +473,10 @@ def title_screen(): while ticks_diff(ticks_ms(), now) < 200: sleep(0.020) now = ticks_ms() + if pgb.button_select() or pgb.button_start(): + view_scores() + elif pgb.button_A(): + break sleep(0.25) def new_level(): diff --git a/Tetris/highscorestetris.sc b/Tetris/highscorestetris.sc new file mode 100644 index 0000000..c9d1fba --- /dev/null +++ b/Tetris/highscorestetris.sc @@ -0,0 +1,9 @@ +0 +0 +0 +0 +0 +0 +0 +0 +0 \ No newline at end of file diff --git a/Tetris/tetris.py b/Tetris/tetris.py index ecd6023..9fa4348 100644 --- a/Tetris/tetris.py +++ b/Tetris/tetris.py @@ -142,6 +142,40 @@ def no_music(): midi.stop_all_music() midi.stop_all() +def append_to_board(score): + with open("highscorestetris.sc", "r") as s: + scores=s.read().split("\n") + for r in range(len(scores)): + scores[r]=int(scores[r]) + newscores=scores + newscores.append(int(score)) + newscores.sort(reverse=True) + for i in range(len(newscores)): newscores[i]=str(newscores[i]) + with open("highscorestetris.sc", "w+") as w: + w.write("\n".join(newscores[:10])) + +def view_scores(): + x=open("highscorestetris.sc", "r") + scores=x.read() + x.close() + del x + scores=scores.split("\n") + while True: + if pgb.button_B(): + time.sleep(0.1) + return + if pgb.button_Home(): + pgb.fill(PicoGameBoy.color(0,0,0)) + pgb.show() + machine.reset() + break + pgb.fill(PicoGameBoy.color(0,0,0)) + pgb.create_text("High Scores:", -1, 15, PicoGameBoy.color(255,255,255)) + for i in range(len(scores)): + pgb.create_text("Score "+str(i+1)+": "+str(scores[i]), -1, 50+i*15, PicoGameBoy.color(255,255,255)) + pgb.create_text("Press B to exit", -1, 220, PicoGameBoy.color(255,255,255)) + pgb.show() + def pause_screen(): global currentmusic no_music() @@ -176,7 +210,7 @@ def collision(x,y): def title_screen(): # title screen now = time.ticks_ms() - while pgb.any_button()==False: + while True: if pgb.button_Home(): pgb.fill(PicoGameBoy.color(0,0,0)) pgb.show() @@ -192,6 +226,10 @@ def title_screen(): while time.ticks_diff(time.ticks_ms(), now) < 200: time.sleep(0.020) now = time.ticks_ms() + if pgb.button_select() or pgb.button_start(): + view_scores() + elif pgb.button_A(): + break def game_over_screen(): global midi @@ -203,24 +241,37 @@ def game_over_screen(): global currentmusic no_music() currentmusic=[0xF0] - pgb.fill_rect(10,90,220,100,BLACK) - pgb.center_text("GAME OVER",WHITE) - pgb.text("Press A to play again.", 35, 125, WHITE) - pgb.text("Press home to quit.", 40, 140, WHITE) - pgb.create_text("Score: "+str(score), -1, 155, WHITE) + pgb.fill(BLACK) + pgb.create_text("GAME OVER",-1,85,WHITE) + pgb.text("Press A to play again.", 35, 105, WHITE) + pgb.text("Press home to quit.", 40, 120, WHITE) + pgb.create_text("Press select/start", -1, 135, PicoGameBoy.color(255,255,255)) + pgb.create_text("to view scores.", -1, 150, PicoGameBoy.color(255,255,255)) + pgb.create_text("Score: "+str(score), -1, 165, WHITE) pgb.show() - lines=0 - level=0 - score=0 + append_to_board(score) while True: + pgb.fill(BLACK) + pgb.create_text("GAME OVER",-1,85,WHITE) + pgb.text("Press A to play again.", 35, 105, WHITE) + pgb.text("Press home to quit.", 40, 120, WHITE) + pgb.create_text("Press select/start", -1, 135, PicoGameBoy.color(255,255,255)) + pgb.create_text("to view scores.", -1, 150, PicoGameBoy.color(255,255,255)) + pgb.create_text("Score: "+str(score), -1, 165, WHITE) + pgb.show() if pgb.button_Home(): pgb.fill(PicoGameBoy.color(0,0,0)) pgb.show() machine.reset() break + if pgb.button_select() or pgb.button_start(): + view_scores() elif pgb.button_A(): + lines=0 + level=0 + score=0 clear_lines() - return + break def draw_background(): pgb.fill(BACKGROUND_COLOR)