diff --git a/pets/companionOS/README.md b/pets/companionOS/README.md new file mode 100644 index 00000000..035305f9 --- /dev/null +++ b/pets/companionOS/README.md @@ -0,0 +1,25 @@ +# Welcome to CompanionOS - by @Briyan Dyju! + +Here is a quick how-to for you across the entire program! + +## 1 - First things first: +**NOTE: Since this program was made on my device, I request you to please swap out all the directories and locations of the bmp files to your own device's** + +## The Launcher: +Use the down arrow key to go between options and use the up arrow key to select an option + +## The Dice: +Use the up arrow key to get a random dice face! (More dice options from 3 sides to 20 sides (D20) coming soon!!) + +## The Coin: +Use the up arrow key to flip a coin (No animation currently) + +## The Cookie Clicker MiniGame: +Use Space to get a score (please ignore screen flickering while I find a fix =( + +# Coming Soon Features: (After my exams!): +- More Mini Games!! +- More Dice options like promised! (Already working on it) +- A coin fliping animation +- upgrades and bonuses for the cookie clicker minigame +- A Hackapet pet =) diff --git a/pets/companionOS/coin.py b/pets/companionOS/coin.py new file mode 100644 index 00000000..d710ca39 --- /dev/null +++ b/pets/companionOS/coin.py @@ -0,0 +1,48 @@ +import displayio +from blinka_displayio_pygamedisplay import PyGameDisplay +import pygame +import time +import random +import os + +script_dir = os.path.dirname(__file__) +coin_img_dir = os.path.join(script_dir, "coin") + +# Display +pygame.init() +display = PyGameDisplay(width=128, height=128) +splash = displayio.Group() +display.show(splash) + +# Initial Plain Screen +start_path = os.path.join(coin_img_dir, "coin.bmp") +start = displayio.OnDiskBitmap(start_path) +bg_sprite = displayio.TileGrid( + start, + pixel_shader=start.pixel_shader +) +splash.append(bg_sprite) + +# Update Display +def update_coin_image(coin_side): + coin_path = os.path.join(coin_img_dir, f"coin{coin_side}.bmp") + new_coin = displayio.OnDiskBitmap(coin_path) + splash.pop() # Remove the old sprite + new_sprite = displayio.TileGrid(new_coin, pixel_shader=new_coin.pixel_shader) + splash.append(new_sprite) # Add the new sprite + +# Main loop +while True: + time.sleep(0.1) + display.refresh() + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + exit() + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_UP: + # Flip the coin (assuming 1 = heads, 2 = tails) + coin_side = random.randint(1, 2) + update_coin_image(coin_side) + elif event.key == pygame.K_DOWN: + print("Down key pressed") diff --git a/pets/companionOS/coin/coin.bmp b/pets/companionOS/coin/coin.bmp new file mode 100644 index 00000000..cad9cc35 Binary files /dev/null and b/pets/companionOS/coin/coin.bmp differ diff --git a/pets/companionOS/coin/coin1.bmp b/pets/companionOS/coin/coin1.bmp new file mode 100644 index 00000000..20cfcff1 Binary files /dev/null and b/pets/companionOS/coin/coin1.bmp differ diff --git a/pets/companionOS/coin/coin2.bmp b/pets/companionOS/coin/coin2.bmp new file mode 100644 index 00000000..83351c66 Binary files /dev/null and b/pets/companionOS/coin/coin2.bmp differ diff --git a/pets/companionOS/coin/coin3.bmp b/pets/companionOS/coin/coin3.bmp new file mode 100644 index 00000000..83351c66 Binary files /dev/null and b/pets/companionOS/coin/coin3.bmp differ diff --git a/pets/companionOS/coin/coin4.bmp b/pets/companionOS/coin/coin4.bmp new file mode 100644 index 00000000..20cfcff1 Binary files /dev/null and b/pets/companionOS/coin/coin4.bmp differ diff --git a/pets/companionOS/coin/e b/pets/companionOS/coin/e new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/pets/companionOS/coin/e @@ -0,0 +1 @@ + diff --git a/pets/companionOS/cookie.py b/pets/companionOS/cookie.py new file mode 100644 index 00000000..f16b6fdd --- /dev/null +++ b/pets/companionOS/cookie.py @@ -0,0 +1,63 @@ +import displayio +from blinka_displayio_pygamedisplay import PyGameDisplay +import pygame +import time +import os + +# Get the directory of the current script +script_dir = os.path.dirname(__file__) +cookie_img_dir = os.path.join(script_dir, "cookie") + +# Initialize the display +pygame.init() +display = PyGameDisplay(width=128, height=128) +splash = displayio.Group() +display.show(splash) + +# Score variable +score = 0 + +# Initial cookie images +cookie1_path = os.path.join(cookie_img_dir, "cookie1.bmp") +cookie2_path = os.path.join(cookie_img_dir, "cookie2.bmp") +cookie1 = displayio.OnDiskBitmap(cookie1_path) +bg_sprite = displayio.TileGrid( + cookie1, + pixel_shader=cookie1.pixel_shader +) +splash.append(bg_sprite) + +pygame_screen = pygame.display.set_mode((128, 128)) +font = pygame.font.Font(None, 24) + +def update_cookie_image(image_path): + new_cookie = displayio.OnDiskBitmap(image_path) + splash.pop() # Remove the old sprite + new_sprite = displayio.TileGrid(new_cookie, pixel_shader=new_cookie.pixel_shader) + splash.append(new_sprite) + +def render_score_text(): + pygame_screen.fill((0, 0, 0)) + text_surface = font.render(f"Score: {score}", True, (255, 255, 255)) + text_rect = text_surface.get_rect(center=(64, 110)) + pygame_screen.blit(text_surface, text_rect) + pygame.display.flip() + +# Main loop +running = True +render_score_text() # Initial score display +while running: + time.sleep(0.1) + display.refresh() + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + exit() + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_SPACE: + update_cookie_image(cookie2_path) + elif event.type == pygame.KEYUP: + if event.key == pygame.K_SPACE: + update_cookie_image(cookie1_path) + score += 1 + render_score_text() diff --git a/pets/companionOS/cookie/cookie.aseprite b/pets/companionOS/cookie/cookie.aseprite new file mode 100644 index 00000000..b23c91bf Binary files /dev/null and b/pets/companionOS/cookie/cookie.aseprite differ diff --git a/pets/companionOS/cookie/cookie1.bmp b/pets/companionOS/cookie/cookie1.bmp new file mode 100644 index 00000000..29b8f927 Binary files /dev/null and b/pets/companionOS/cookie/cookie1.bmp differ diff --git a/pets/companionOS/cookie/cookie2.bmp b/pets/companionOS/cookie/cookie2.bmp new file mode 100644 index 00000000..30f9b042 Binary files /dev/null and b/pets/companionOS/cookie/cookie2.bmp differ diff --git a/pets/companionOS/cookie/e b/pets/companionOS/cookie/e new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/pets/companionOS/cookie/e @@ -0,0 +1 @@ + diff --git a/pets/companionOS/dice.py b/pets/companionOS/dice.py new file mode 100644 index 00000000..a53cb5c7 --- /dev/null +++ b/pets/companionOS/dice.py @@ -0,0 +1,48 @@ +import displayio +from blinka_displayio_pygamedisplay import PyGameDisplay +import pygame +import time +import random +import os + +script_dir = os.path.dirname(__file__) +dice_img_dir = os.path.join(script_dir, "diceimg") + +# Display +pygame.init() +display = PyGameDisplay(width=128, height=128) +splash = displayio.Group() +display.show(splash) + +# Initial Plain Screen +start_path = os.path.join(dice_img_dir, "Dice.bmp") +start = displayio.OnDiskBitmap(start_path) +bg_sprite = displayio.TileGrid( + start, + pixel_shader=start.pixel_shader +) +splash.append(bg_sprite) + +# Update Display +def update_dice_image(diceno): + dice_path = os.path.join(dice_img_dir, f"Diceof{diceno}.bmp") + new_dice = displayio.OnDiskBitmap(dice_path) + splash.pop() # Remove the old sprite + new_sprite = displayio.TileGrid(new_dice, pixel_shader=new_dice.pixel_shader) + splash.append(new_sprite) # Add the new sprite + +# Main loop +while True: + time.sleep(0.1) + display.refresh() + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + exit() + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_UP: + # Roll the dice + diceno = random.randint(1, 6) + update_dice_image(diceno) + elif event.key == pygame.K_DOWN: + print("Down key pressed") diff --git a/pets/companionOS/diceimg/Dice.bmp b/pets/companionOS/diceimg/Dice.bmp new file mode 100644 index 00000000..bf2185db Binary files /dev/null and b/pets/companionOS/diceimg/Dice.bmp differ diff --git a/pets/companionOS/diceimg/Diceof1.bmp b/pets/companionOS/diceimg/Diceof1.bmp new file mode 100644 index 00000000..9577ed8c Binary files /dev/null and b/pets/companionOS/diceimg/Diceof1.bmp differ diff --git a/pets/companionOS/diceimg/Diceof2.bmp b/pets/companionOS/diceimg/Diceof2.bmp new file mode 100644 index 00000000..6a4bca4c Binary files /dev/null and b/pets/companionOS/diceimg/Diceof2.bmp differ diff --git a/pets/companionOS/diceimg/Diceof3.bmp b/pets/companionOS/diceimg/Diceof3.bmp new file mode 100644 index 00000000..54a7f36e Binary files /dev/null and b/pets/companionOS/diceimg/Diceof3.bmp differ diff --git a/pets/companionOS/diceimg/Diceof4.bmp b/pets/companionOS/diceimg/Diceof4.bmp new file mode 100644 index 00000000..d7cc1cba Binary files /dev/null and b/pets/companionOS/diceimg/Diceof4.bmp differ diff --git a/pets/companionOS/diceimg/Diceof5.bmp b/pets/companionOS/diceimg/Diceof5.bmp new file mode 100644 index 00000000..ec21df6d Binary files /dev/null and b/pets/companionOS/diceimg/Diceof5.bmp differ diff --git a/pets/companionOS/diceimg/Diceof6.bmp b/pets/companionOS/diceimg/Diceof6.bmp new file mode 100644 index 00000000..36f72f56 Binary files /dev/null and b/pets/companionOS/diceimg/Diceof6.bmp differ diff --git a/pets/companionOS/diceimg/e b/pets/companionOS/diceimg/e new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/pets/companionOS/diceimg/e @@ -0,0 +1 @@ + diff --git a/pets/companionOS/hackapet.py b/pets/companionOS/hackapet.py new file mode 100644 index 00000000..3623936b --- /dev/null +++ b/pets/companionOS/hackapet.py @@ -0,0 +1,31 @@ +import displayio +from blinka_displayio_pygamedisplay import PyGameDisplay +import pygame +import time +import os + +# dir path +script_dir = os.path.dirname(__file__) + +# Display +pygame.init() +display = PyGameDisplay(width=128, height=128) +splash = displayio.Group() +display.show(splash) + +# Initial Plain Screen +image_path = os.path.join(script_dir, "splash1.bmp") +start = displayio.OnDiskBitmap(image_path) +bg_sprite = displayio.TileGrid( + start, + pixel_shader=start.pixel_shader +) +splash.append(bg_sprite) + +while True: + time.sleep(0.1) + display.refresh() + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + exit() diff --git a/pets/companionOS/launcher.py b/pets/companionOS/launcher.py new file mode 100644 index 00000000..317dbc50 --- /dev/null +++ b/pets/companionOS/launcher.py @@ -0,0 +1,78 @@ +import displayio +from blinka_displayio_pygamedisplay import PyGameDisplay +import pygame +import time +import os + +# dir path +script_dir = os.path.dirname(__file__) + +# Display +pygame.init() +display = PyGameDisplay(width=128, height=128) +splash = displayio.Group() +display.show(splash) + +# UI file paths +ui_files = [ + os.path.join(script_dir, "ui", "ui1.bmp"), + os.path.join(script_dir, "ui", "ui2.bmp"), + os.path.join(script_dir, "ui", "ui3.bmp"), + os.path.join(script_dir, "ui", "ui4.bmp"), + os.path.join(script_dir, "ui", "ui5.bmp"), +] + +# Load Launcher +current_index = 0 +ui_bmp = displayio.OnDiskBitmap(ui_files[current_index]) +bg_sprite = displayio.TileGrid( + ui_bmp, + pixel_shader=ui_bmp.pixel_shader +) +splash.append(bg_sprite) +pygame_screen = pygame.display.set_mode((128, 128)) +font = pygame.font.Font(None, 24) + +# Update UI +def update_ui(index): + global bg_sprite + splash.pop() + new_ui = displayio.OnDiskBitmap(ui_files[index]) + bg_sprite = displayio.TileGrid(new_ui, pixel_shader=new_ui.pixel_shader) + splash.append(bg_sprite) + +# Show message +def show_message(message, duration=2): + pygame_screen.fill((0, 0, 0)) + text_surface = font.render(message, True, (255, 255, 255)) + text_rect = text_surface.get_rect(center=(64, 64)) + pygame_screen.blit(text_surface, text_rect) + pygame.display.flip() + time.sleep(duration) + pygame_screen.fill((0, 0, 0)) + pygame.display.flip() + +# Main loop +running = True +while running: + time.sleep(0.1) + display.refresh() + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + exit() + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_DOWN: # Down arrow key + current_index += 1 + if current_index >= len(ui_files): + current_index = 1 + update_ui(current_index) + elif event.key == pygame.K_UP: + if current_index == 1: # UI2 launches dice.py + os.system("python dice.py") + elif current_index == 3: # UI3 launches cookie.py + os.system("python cookie.py") + elif current_index == 2: # UI4 launches coin.py + os.system("python coin.py") + else: + show_message("Coming Soon") diff --git a/pets/companionOS/plain.bmp b/pets/companionOS/plain.bmp new file mode 100644 index 00000000..a02a2d97 Binary files /dev/null and b/pets/companionOS/plain.bmp differ diff --git a/pets/companionOS/requirements.txt b/pets/companionOS/requirements.txt new file mode 100644 index 00000000..c032322b --- /dev/null +++ b/pets/companionOS/requirements.txt @@ -0,0 +1,4 @@ +adafruit_blinka_displayio==0.11.1 +adafruit_circuitpython_display_text==3.2.2 +blinka_displayio_pygamedisplay==2.4.0 +pygame==2.6.1 \ No newline at end of file diff --git a/pets/companionOS/splash1.bmp b/pets/companionOS/splash1.bmp new file mode 100644 index 00000000..1194ed36 Binary files /dev/null and b/pets/companionOS/splash1.bmp differ diff --git a/pets/companionOS/ui/e b/pets/companionOS/ui/e new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/pets/companionOS/ui/e @@ -0,0 +1 @@ + diff --git a/pets/companionOS/ui/ui1.bmp b/pets/companionOS/ui/ui1.bmp new file mode 100644 index 00000000..24aee421 Binary files /dev/null and b/pets/companionOS/ui/ui1.bmp differ diff --git a/pets/companionOS/ui/ui2.bmp b/pets/companionOS/ui/ui2.bmp new file mode 100644 index 00000000..a11ace81 Binary files /dev/null and b/pets/companionOS/ui/ui2.bmp differ diff --git a/pets/companionOS/ui/ui3.bmp b/pets/companionOS/ui/ui3.bmp new file mode 100644 index 00000000..b46f98c2 Binary files /dev/null and b/pets/companionOS/ui/ui3.bmp differ diff --git a/pets/companionOS/ui/ui4.bmp b/pets/companionOS/ui/ui4.bmp new file mode 100644 index 00000000..e6c9c8d4 Binary files /dev/null and b/pets/companionOS/ui/ui4.bmp differ diff --git a/pets/companionOS/ui/ui5.bmp b/pets/companionOS/ui/ui5.bmp new file mode 100644 index 00000000..d09e4b86 Binary files /dev/null and b/pets/companionOS/ui/ui5.bmp differ