diff --git a/pets/blu/README.md b/pets/blu/README.md new file mode 100644 index 00000000..eea1cf39 --- /dev/null +++ b/pets/blu/README.md @@ -0,0 +1,3 @@ +# Blu +## How to play? +Just press the left and right buttons to eat fishes! as of now, there isnt a function for the middle button yet. Have fun chomping! diff --git a/pets/blu/aseprite/backbackground.aseprite b/pets/blu/aseprite/backbackground.aseprite new file mode 100644 index 00000000..a68969f4 Binary files /dev/null and b/pets/blu/aseprite/backbackground.aseprite differ diff --git a/pets/blu/aseprite/blahaj.aseprite b/pets/blu/aseprite/blahaj.aseprite new file mode 100644 index 00000000..ebca6dc0 Binary files /dev/null and b/pets/blu/aseprite/blahaj.aseprite differ diff --git a/pets/blu/aseprite/blahajchomp.aseprite b/pets/blu/aseprite/blahajchomp.aseprite new file mode 100644 index 00000000..04651357 Binary files /dev/null and b/pets/blu/aseprite/blahajchomp.aseprite differ diff --git a/pets/blu/aseprite/frontbackground.aseprite b/pets/blu/aseprite/frontbackground.aseprite new file mode 100644 index 00000000..2b6bbb89 Binary files /dev/null and b/pets/blu/aseprite/frontbackground.aseprite differ diff --git a/pets/blu/code/main.py b/pets/blu/code/main.py new file mode 100644 index 00000000..43426d9b --- /dev/null +++ b/pets/blu/code/main.py @@ -0,0 +1,143 @@ +import displayio +from blinka_displayio_pygamedisplay import PyGameDisplay +import pygame +import time +from adafruit_display_text import label +import random + +pygame.init() + +display = PyGameDisplay(width=128, height=128) +splash = displayio.Group() +display.show(splash) + +ocean_background = displayio.OnDiskBitmap("resources/backbackground-Sheet.bmp") +ocean_background_width = ocean_background.width +ocean_background_height = ocean_background.height +num_frames = 6 + +bg_sprite = displayio.TileGrid( + ocean_background, + pixel_shader=ocean_background.pixel_shader, + width=1, height=1, + x=0, y=0, + tile_width=128, + tile_height=128 +) + +splash.append(bg_sprite) + +animated_bg = displayio.OnDiskBitmap("resources/frontbackground-Sheet.bmp") +animated_bg_width = animated_bg.width +animated_bg_height = animated_bg.height + +animated_bg_sprite = displayio.TileGrid( + animated_bg, + pixel_shader=animated_bg.pixel_shader, + width=1, height=1, + x=0, y=0, + tile_width=128, + tile_height=128 +) + +splash.append(animated_bg_sprite) + +blahaj_sheet = displayio.OnDiskBitmap("resources/blahaj.bmp") +blahaj_chomp = displayio.OnDiskBitmap("resources/blahajchomp.bmp") + +tile_width = 32 +tile_height = 32 + +blahaj_sprite = displayio.TileGrid( + blahaj_sheet, + pixel_shader=blahaj_sheet.pixel_shader, + width=1, + height=1, + tile_width=tile_width, + tile_height=tile_height, + default_tile=0, + x=(display.width - tile_width) // 2, + y=(display.height - tile_height) // 2 +) + +splash.append(blahaj_sprite) + +fish_bitmap = displayio.OnDiskBitmap("resources/fish.bmp") +fish_list = [] + +def spawn_fish(): + side = random.choice(["left", "right"]) + if side == "left": + x_position = -fish_bitmap.width + else: + x_position = display.width + + fish_sprite = displayio.TileGrid( + fish_bitmap, + pixel_shader=fish_bitmap.pixel_shader, + width=1, + height=1, + tile_width=fish_bitmap.width, + tile_height=fish_bitmap.height, + x=x_position, + y=random.randint(20, display.height - 20) + ) + fish_list.append(fish_sprite) + splash.append(fish_sprite) + +def check_collision(sprite1, sprite2): + return ( + sprite1.x < sprite2.x + 32 and + sprite1.x + 32 > sprite2.x and + sprite1.y < sprite2.y + 32 and + sprite1.y + 32 > sprite2.y + ) + +speed = 3 +fish_speed = 2 +running = True + +bg_frame = 0 +animated_bg_frame = 0 + +def chomp_animation(): + blahaj_sprite.bitmap = blahaj_chomp + time.sleep(0.1) + blahaj_sprite.bitmap = blahaj_sheet + +while running: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + + keys = pygame.key.get_pressed() + if keys[pygame.K_LEFT]: + blahaj_sprite.x -= speed + blahaj_sprite.flip_x = False + if keys[pygame.K_RIGHT]: + blahaj_sprite.x += speed + blahaj_sprite.flip_x = True + + if random.random() < 0.05: + spawn_fish() + + for fish in fish_list[:]: + if fish.x < blahaj_sprite.x: + fish.x += fish_speed + else: + fish.x -= fish_speed + + if check_collision(blahaj_sprite, fish): + splash.remove(fish) + fish_list.remove(fish) + chomp_animation() + + bg_frame = (bg_frame + 1) % num_frames + bg_sprite[0] = bg_frame + + animated_bg_frame = (animated_bg_frame + 1) % num_frames + animated_bg_sprite[0] = animated_bg_frame + + time.sleep(0.1) + +pygame.quit() diff --git a/pets/blu/resources/backbackground-Sheet.bmp b/pets/blu/resources/backbackground-Sheet.bmp new file mode 100644 index 00000000..9e83c304 Binary files /dev/null and b/pets/blu/resources/backbackground-Sheet.bmp differ diff --git a/pets/blu/resources/backbackground1.bmp b/pets/blu/resources/backbackground1.bmp new file mode 100644 index 00000000..e901bebf Binary files /dev/null and b/pets/blu/resources/backbackground1.bmp differ diff --git a/pets/blu/resources/backbackground2.bmp b/pets/blu/resources/backbackground2.bmp new file mode 100644 index 00000000..e901bebf Binary files /dev/null and b/pets/blu/resources/backbackground2.bmp differ diff --git a/pets/blu/resources/backbackground3.bmp b/pets/blu/resources/backbackground3.bmp new file mode 100644 index 00000000..dea0905d Binary files /dev/null and b/pets/blu/resources/backbackground3.bmp differ diff --git a/pets/blu/resources/backbackground4.bmp b/pets/blu/resources/backbackground4.bmp new file mode 100644 index 00000000..78d4524b Binary files /dev/null and b/pets/blu/resources/backbackground4.bmp differ diff --git a/pets/blu/resources/backbackground5.bmp b/pets/blu/resources/backbackground5.bmp new file mode 100644 index 00000000..19e9a423 Binary files /dev/null and b/pets/blu/resources/backbackground5.bmp differ diff --git a/pets/blu/resources/backbackground6.bmp b/pets/blu/resources/backbackground6.bmp new file mode 100644 index 00000000..19e9a423 Binary files /dev/null and b/pets/blu/resources/backbackground6.bmp differ diff --git a/pets/blu/resources/blahaj.bmp b/pets/blu/resources/blahaj.bmp new file mode 100644 index 00000000..d1932ac0 Binary files /dev/null and b/pets/blu/resources/blahaj.bmp differ diff --git a/pets/blu/resources/blahajchomp.bmp b/pets/blu/resources/blahajchomp.bmp new file mode 100644 index 00000000..efab20e5 Binary files /dev/null and b/pets/blu/resources/blahajchomp.bmp differ diff --git a/pets/blu/resources/fish.bmp b/pets/blu/resources/fish.bmp new file mode 100644 index 00000000..8c786a70 Binary files /dev/null and b/pets/blu/resources/fish.bmp differ diff --git a/pets/blu/resources/frontbackground-Sheet.bmp b/pets/blu/resources/frontbackground-Sheet.bmp new file mode 100644 index 00000000..fd94b392 Binary files /dev/null and b/pets/blu/resources/frontbackground-Sheet.bmp differ diff --git a/pets/blu/resources/frontbackground1.bmp b/pets/blu/resources/frontbackground1.bmp new file mode 100644 index 00000000..e6b1ba8a Binary files /dev/null and b/pets/blu/resources/frontbackground1.bmp differ diff --git a/pets/blu/resources/frontbackground2.bmp b/pets/blu/resources/frontbackground2.bmp new file mode 100644 index 00000000..fc012e36 Binary files /dev/null and b/pets/blu/resources/frontbackground2.bmp differ diff --git a/pets/blu/resources/frontbackground3.bmp b/pets/blu/resources/frontbackground3.bmp new file mode 100644 index 00000000..54aa2112 Binary files /dev/null and b/pets/blu/resources/frontbackground3.bmp differ diff --git a/pets/blu/resources/frontbackground4.bmp b/pets/blu/resources/frontbackground4.bmp new file mode 100644 index 00000000..2eb8fce3 Binary files /dev/null and b/pets/blu/resources/frontbackground4.bmp differ diff --git a/pets/blu/resources/frontbackground5.bmp b/pets/blu/resources/frontbackground5.bmp new file mode 100644 index 00000000..e8188398 Binary files /dev/null and b/pets/blu/resources/frontbackground5.bmp differ diff --git a/pets/blu/resources/frontbackground6.bmp b/pets/blu/resources/frontbackground6.bmp new file mode 100644 index 00000000..fca84e21 Binary files /dev/null and b/pets/blu/resources/frontbackground6.bmp differ