Skip to content

Commit

Permalink
Revised to add a score board
Browse files Browse the repository at this point in the history
  • Loading branch information
HalloSpaceBoy5 authored Apr 28, 2023
1 parent 51a50f0 commit 9b861f7
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 31 deletions.
63 changes: 53 additions & 10 deletions Breakout/breakout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions Breakout/highscoresbreakout.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
0
0
0
0
0
0
0
0
0
0
68 changes: 61 additions & 7 deletions Flappy Bird/flappybird.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,55 @@ 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()
machine.reset()
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))
Expand Down Expand Up @@ -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)
Expand All @@ -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()

Expand Down
9 changes: 9 additions & 0 deletions Flappy Bird/highscoresflappy.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
0
0
0
0
0
0
0
0
0
9 changes: 9 additions & 0 deletions Starship/highscoresstarship.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
0
0
0
0
0
0
0
0
0
60 changes: 56 additions & 4 deletions Starship/starship.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -409,22 +458,25 @@ 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()
machine.reset()
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))
pgb.show()
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():
Expand Down
9 changes: 9 additions & 0 deletions Tetris/highscorestetris.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
0
0
0
0
0
0
0
0
0
Loading

0 comments on commit 9b861f7

Please sign in to comment.