Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompanionOS submission! #74

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
25 changes: 25 additions & 0 deletions pets/companionOS/README.md
Original file line number Diff line number Diff line change
@@ -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 =)
48 changes: 48 additions & 0 deletions pets/companionOS/coin.py
Original file line number Diff line number Diff line change
@@ -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")
Binary file added pets/companionOS/coin/coin.bmp
Binary file not shown.
Binary file added pets/companionOS/coin/coin1.bmp
Binary file not shown.
Binary file added pets/companionOS/coin/coin2.bmp
Binary file not shown.
Binary file added pets/companionOS/coin/coin3.bmp
Binary file not shown.
Binary file added pets/companionOS/coin/coin4.bmp
Binary file not shown.
1 change: 1 addition & 0 deletions pets/companionOS/coin/e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

63 changes: 63 additions & 0 deletions pets/companionOS/cookie.py
Original file line number Diff line number Diff line change
@@ -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()
Binary file added pets/companionOS/cookie/cookie.aseprite
Binary file not shown.
Binary file added pets/companionOS/cookie/cookie1.bmp
Binary file not shown.
Binary file added pets/companionOS/cookie/cookie2.bmp
Binary file not shown.
1 change: 1 addition & 0 deletions pets/companionOS/cookie/e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

48 changes: 48 additions & 0 deletions pets/companionOS/dice.py
Original file line number Diff line number Diff line change
@@ -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")
Binary file added pets/companionOS/diceimg/Dice.bmp
Binary file not shown.
Binary file added pets/companionOS/diceimg/Diceof1.bmp
Binary file not shown.
Binary file added pets/companionOS/diceimg/Diceof2.bmp
Binary file not shown.
Binary file added pets/companionOS/diceimg/Diceof3.bmp
Binary file not shown.
Binary file added pets/companionOS/diceimg/Diceof4.bmp
Binary file not shown.
Binary file added pets/companionOS/diceimg/Diceof5.bmp
Binary file not shown.
Binary file added pets/companionOS/diceimg/Diceof6.bmp
Binary file not shown.
1 change: 1 addition & 0 deletions pets/companionOS/diceimg/e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

31 changes: 31 additions & 0 deletions pets/companionOS/hackapet.py
Original file line number Diff line number Diff line change
@@ -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()
78 changes: 78 additions & 0 deletions pets/companionOS/launcher.py
Original file line number Diff line number Diff line change
@@ -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")
Binary file added pets/companionOS/plain.bmp
Binary file not shown.
4 changes: 4 additions & 0 deletions pets/companionOS/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Binary file added pets/companionOS/splash1.bmp
Binary file not shown.
1 change: 1 addition & 0 deletions pets/companionOS/ui/e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file added pets/companionOS/ui/ui1.bmp
Binary file not shown.
Binary file added pets/companionOS/ui/ui2.bmp
Binary file not shown.
Binary file added pets/companionOS/ui/ui3.bmp
Binary file not shown.
Binary file added pets/companionOS/ui/ui4.bmp
Binary file not shown.
Binary file added pets/companionOS/ui/ui5.bmp
Binary file not shown.