diff --git a/pets/sparky/README.md b/pets/sparky/README.md new file mode 100644 index 00000000..6778cefd --- /dev/null +++ b/pets/sparky/README.md @@ -0,0 +1,3 @@ +this is a google dino game inspired game!! +use up arrow to interact and jump +thanks for playing! diff --git a/pets/sparky/dead.bmp b/pets/sparky/dead.bmp new file mode 100644 index 00000000..d631bbfa Binary files /dev/null and b/pets/sparky/dead.bmp differ diff --git a/pets/sparky/loading_screen.bmp b/pets/sparky/loading_screen.bmp new file mode 100644 index 00000000..8565dc4d Binary files /dev/null and b/pets/sparky/loading_screen.bmp differ diff --git a/pets/sparky/main_game_background.bmp b/pets/sparky/main_game_background.bmp new file mode 100644 index 00000000..20004357 Binary files /dev/null and b/pets/sparky/main_game_background.bmp differ diff --git a/pets/sparky/main_menu.bmp b/pets/sparky/main_menu.bmp new file mode 100644 index 00000000..e990a72d Binary files /dev/null and b/pets/sparky/main_menu.bmp differ diff --git a/pets/sparky/main_menu_background.bmp b/pets/sparky/main_menu_background.bmp new file mode 100644 index 00000000..283a944d Binary files /dev/null and b/pets/sparky/main_menu_background.bmp differ diff --git a/pets/sparky/main_menu_decor.bmp b/pets/sparky/main_menu_decor.bmp new file mode 100644 index 00000000..eaa45794 Binary files /dev/null and b/pets/sparky/main_menu_decor.bmp differ diff --git a/pets/sparky/numbers.bmp b/pets/sparky/numbers.bmp new file mode 100644 index 00000000..be7ff501 Binary files /dev/null and b/pets/sparky/numbers.bmp differ diff --git a/pets/sparky/obis.bmp b/pets/sparky/obis.bmp new file mode 100644 index 00000000..fcd4867f Binary files /dev/null and b/pets/sparky/obis.bmp differ diff --git a/pets/sparky/player.bmp b/pets/sparky/player.bmp new file mode 100644 index 00000000..7abcbbdf Binary files /dev/null and b/pets/sparky/player.bmp differ diff --git a/pets/sparky/score_labels.bmp b/pets/sparky/score_labels.bmp new file mode 100644 index 00000000..d25fe08a Binary files /dev/null and b/pets/sparky/score_labels.bmp differ diff --git a/pets/sparky/sparky.py b/pets/sparky/sparky.py new file mode 100644 index 00000000..2c73cb62 --- /dev/null +++ b/pets/sparky/sparky.py @@ -0,0 +1,268 @@ +import displayio +from blinka_displayio_pygamedisplay import PyGameDisplay +import pygame +import time +import random + +pygame.init() +display = PyGameDisplay(width=128, height=128) +splash = displayio.Group() +display.show(splash) + +#===MAIN MENU===# +main_menu_background_bmp = displayio.OnDiskBitmap("main_menu_background.bmp") +main_menu_bmp = displayio.OnDiskBitmap("main_menu.bmp") +main_menu_decor_bmp = displayio.OnDiskBitmap("main_menu_decor.bmp") + + + +main_menu_background = displayio.TileGrid(main_menu_background_bmp, pixel_shader=main_menu_background_bmp.pixel_shader) +main_menu = displayio.TileGrid( main_menu_bmp, pixel_shader=main_menu_bmp.pixel_shader, tile_width=128, tile_height=128) + +splash.append(main_menu_background) +splash.append(main_menu) + +decor = [] + + +def spawn_main_menu_decor(): + x_pos = random.randrange(0, 41) if random.randrange(0,2) == 1 else random.randrange(87,128) + main_menu_decor = displayio.TileGrid( + main_menu_decor_bmp, + pixel_shader=main_menu_background_bmp.pixel_shader, + width=1, + height=1, + tile_width=3, + tile_height=3, + default_tile=0, + x=x_pos, + y=display.height + ) + decor.append(main_menu_decor) + splash.insert(1,main_menu_decor) + + + +frame = 0 +fps = 30 +do_main_menu = True +while(do_main_menu): + if display.check_quit(): + break + if frame % 3 == 0: + for main_menu_decor in decor: + main_menu_decor.x += random.randrange(-1,2) + main_menu_decor.y -= 1 + if frame % 6 == 0: + spawn_main_menu_decor() + if frame % 24 == 0: + if main_menu[0] == 0: + main_menu[0] = 1 + else: + main_menu[0] = 0 + + frame += 1 + keys = pygame.key.get_pressed() + for main_menu_decor in decor: + if main_menu_decor.y <= -2: + splash.remove(main_menu_decor) + decor.remove(main_menu_decor) + + if frame == 60: + frame = 0 + if keys[pygame.K_UP]: + do_main_menu = False + if do_main_menu: + time.sleep(1 / fps) + + +#===LOADING SCREEN===# +do_loading_screen = True +loading_screen_bmp = displayio.OnDiskBitmap("loading_screen.bmp") +loading_screen = displayio.TileGrid( loading_screen_bmp, pixel_shader=loading_screen_bmp.pixel_shader, tile_width=128, tile_height=128) + +splash.append(loading_screen) +while(do_loading_screen): + if display.check_quit(): + break + + if frame % 6 == 0: + if loading_screen[0] == 11: + do_loading_screen = False + else: + loading_screen[0] +=1 + + frame+=1 + if frame == 60: + frame = 0 + if do_loading_screen: + time.sleep(1 / fps) + +play_dino_game = True +high_score = 0 +#===DINO GAME===# +while(play_dino_game): + + do_main_game = True + numbers_bmp = displayio.OnDiskBitmap("numbers.bmp") + score_labels_bmp = displayio.OnDiskBitmap("score_labels.bmp") + main_game_background_bmp = displayio.OnDiskBitmap("main_game_background.bmp") + obis_bmp = displayio.OnDiskBitmap("obis.bmp") + player_bmp = displayio.OnDiskBitmap("player.bmp") + + + high_score_number_1 = displayio.TileGrid(numbers_bmp,pixel_shader=numbers_bmp.pixel_shader,width=1,height=1,tile_width=3,tile_height= 7,default_tile=3,x = 48,y = 1) + high_score_number_2 = displayio.TileGrid(numbers_bmp,pixel_shader=numbers_bmp.pixel_shader,width=1,height=1,tile_width=3,tile_height= 7,default_tile=3,x = 52,y = 1) + high_score_number_3 = displayio.TileGrid(numbers_bmp,pixel_shader=numbers_bmp.pixel_shader,width=1,height=1,tile_width=3,tile_height= 7,default_tile=3,x = 56,y = 1) + high_score_number_4 = displayio.TileGrid(numbers_bmp,pixel_shader=numbers_bmp.pixel_shader,width=1,height=1,tile_width=3,tile_height= 7,default_tile=3,x = 60,y = 1) + high_score_number_5 = displayio.TileGrid(numbers_bmp,pixel_shader=numbers_bmp.pixel_shader,width=1,height=1,tile_width=3,tile_height= 7,default_tile=3,x = 64,y = 1) + high_score_number_6 = displayio.TileGrid(numbers_bmp,pixel_shader=numbers_bmp.pixel_shader,width=1,height=1,tile_width=3,tile_height= 7,default_tile=3,x = 68,y = 1) + + current_score_number_1 = displayio.TileGrid(numbers_bmp,pixel_shader=numbers_bmp.pixel_shader,width=1,height=1,tile_width=3,tile_height= 7,default_tile=3,x = 48,y = 8) + current_score_number_2 = displayio.TileGrid(numbers_bmp,pixel_shader=numbers_bmp.pixel_shader,width=1,height=1,tile_width=3,tile_height= 7,default_tile=3,x = 52,y = 8) + current_score_number_3 = displayio.TileGrid(numbers_bmp,pixel_shader=numbers_bmp.pixel_shader,width=1,height=1,tile_width=3,tile_height= 7,default_tile=3,x = 56,y = 8) + current_score_number_4 = displayio.TileGrid(numbers_bmp,pixel_shader=numbers_bmp.pixel_shader,width=1,height=1,tile_width=3,tile_height= 7,default_tile=3,x = 60,y = 8) + current_score_number_5 = displayio.TileGrid(numbers_bmp,pixel_shader=numbers_bmp.pixel_shader,width=1,height=1,tile_width=3,tile_height= 7,default_tile=3,x = 64,y = 8) + current_score_number_6 = displayio.TileGrid(numbers_bmp,pixel_shader=numbers_bmp.pixel_shader,width=1,height=1,tile_width=3,tile_height= 7,default_tile=3,x = 68,y = 8) + main_game_background = displayio.TileGrid(main_game_background_bmp, pixel_shader=main_game_background_bmp.pixel_shader) + + player = displayio.TileGrid( + player_bmp, + pixel_shader=player_bmp.pixel_shader, + x=10, + y=75 + ) + + score_labels = displayio.TileGrid(score_labels_bmp, pixel_shader=score_labels_bmp.pixel_shader,x=2,y=2) + + splash.append(main_game_background) + splash.append(high_score_number_1) + splash.append(high_score_number_2) + splash.append(high_score_number_3) + splash.append(high_score_number_4) + splash.append(high_score_number_5) + splash.append(high_score_number_6) + splash.append(current_score_number_1) + splash.append(current_score_number_2) + splash.append(current_score_number_3) + splash.append(current_score_number_4) + splash.append(current_score_number_5) + splash.append(current_score_number_6) + splash.append(score_labels) + splash.append(player) + + jump_timer = 0 + jump_muti = 30 + fall_muti = 1 + speed_muti = 1 + score = 0 + obis = [] + + + def get_value_at_index_of_int(int, idx) -> int: + if idx > len(str(int)) - 1: + return 0 + + str_int = str(int) + char_int = ord(str_int[idx]) + return char_int - 48 + + def spawn_obi(): + obi = displayio.TileGrid( + obis_bmp, + pixel_shader=obis_bmp.pixel_shader, + tile_width=12, + tile_height=12, + x=128 + 12, + y =71 + ) + + obis.append(obi) + splash.append( obi) + def check_collition(obj1, obj2): + return( + obj1.x < obj2.x + obj2.tile_width and + obj1.x > obj2.x-3 and + (obj1.y ==75) + ) + + while(do_main_game): + if display.check_quit(): + break + for obi in obis: + if check_collition(player,obi): + do_main_game = False + + #===SCORE===# + + if frame % 4: + score+=1 * int(speed_muti) + if score >= high_score: + high_score = score + current_score_number_1[0] = get_value_at_index_of_int(score,0) + current_score_number_2[0] = get_value_at_index_of_int(score,1) + current_score_number_3[0] = get_value_at_index_of_int(score,2) + current_score_number_4[0] = get_value_at_index_of_int(score,3) + current_score_number_5[0] = get_value_at_index_of_int(score,4) + current_score_number_6[0] = get_value_at_index_of_int(score,5) + + high_score_number_1[0] = get_value_at_index_of_int(high_score, 0) + high_score_number_2[0] = get_value_at_index_of_int(high_score, 1) + high_score_number_3[0] = get_value_at_index_of_int(high_score, 2) + high_score_number_4[0] = get_value_at_index_of_int(high_score, 3) + high_score_number_5[0] = get_value_at_index_of_int(high_score, 4) + high_score_number_6[0] = get_value_at_index_of_int(high_score, 5) + + #===PLAYER===# + + keys = pygame.key.get_pressed() + if jump_timer > 0: + player.y-=int(jump_muti) + jump_muti /= 1.6 + + jump_timer-=1 + if player.y < 75: + if player.y + fall_muti > 75: + player.y = 75 + else: + player.y+=int(fall_muti) + fall_muti *= 1.1 + else: + fall_muti = 1 + if keys[pygame.K_UP] and jump_timer == 0 and player.y == 75: + jump_muti = 16 + jump_timer = 10 + + + #===OBJECTS===# + + if frame % int(60 / int(speed_muti)) == 0: + spawn_obi() + if frame % 120 == 0: + speed_muti*=1.2 + for obi in obis: + obi.x-=int(speed_muti) + + + frame+=1 + if frame == 60: + frame = 0 + if do_main_game: + time.sleep(1 / fps) + + #===PLAY AGAIN===# + do_play_again = True + + you_died_bmp = displayio.OnDiskBitmap("dead.bmp") + main_menu_background = displayio.TileGrid(main_menu_background_bmp, pixel_shader=main_menu_background_bmp.pixel_shader) + you_died = displayio.TileGrid(you_died_bmp, pixel_shader=you_died_bmp.pixel_shader) + splash.append(main_game_background) + splash.append(you_died) + while(do_play_again): + if display.check_quit(): + break + keys = pygame.key.get_pressed() + if keys[pygame.K_UP]: + for i in splash: + splash.remove(i) + do_play_again = False \ No newline at end of file