0.9-Alpha

This commit is contained in:
Zahkc 2023-07-11 02:22:21 +10:00 committed by GitHub
parent 25734f5f53
commit e981de8d9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 177 additions and 66 deletions

View File

@ -0,0 +1 @@
{"spritePath": "/Sprites/Characters/BOTORU/ADULT/BODY.BMP", "joyMult": 1.0, "name": "BOTORU", "respectMult": 1.0, "baseJoy": 1, "evolutionInterval": 100, "baseRespect": 1, "lifespan": 1000}

1
Data/Profiles/MUSH.json Normal file
View File

@ -0,0 +1 @@
{"spritePath": "/Sprites/Characters/MUSH/ADULT/BODY.BMP", "joyMult": 1.0, "name": "MUSH", "respectMult": 1.0, "baseJoy": 1, "evolutionInterval": 100, "baseRespect": 1, "lifespan": 1000}

View File

@ -1 +1 @@
TestTestTake 2Take 2Take 2Take 2
{"profile" : "BOTORU", "age" : 205, "joy" : 2, "respect" : 3, "care" : 2, "money" : 5, "nextEventTime" : 1000, "nextEvloutionTime" : 1500, "death" : 2000}

1
Save/settings.json Normal file
View File

@ -0,0 +1 @@
{"timeout": 1500}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

91
code.py
View File

@ -1,12 +1,17 @@
import time
import json
import alarm
import board
import displayio
import digitalio
import bitmaptools
import adafruit_imageload
import storage
import supervisor
import microcontroller
import menu
import entity
import animate
import selector
import buttonBus
@ -15,27 +20,59 @@ import buttonBus
#setup
board.DISPLAY.root_group.hidden = False
board.DISPLAY.rotation = 90
splash = displayio.Group()
board.DISPLAY.show(splash)
try:
storage.remount("/", False)
except RuntimeError as E:
print("Failed Mount")
root = displayio.Group()
bgGroup = displayio.Group()
bgItemGroup = displayio.Group()
haioGroup = displayio.Group()
fgItemGroup = displayio.Group()
menuGroup = displayio.Group()
selectorGroup = displayio.Group()
board.DISPLAY.show(root)
entity = entity.entity()
entity.importSave()
entity.show(haioGroup)
bg, bgPallette = adafruit_imageload.load("/Sprites/Backgrounds/bg1.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette)
bgTile = displayio.TileGrid(bg, pixel_shader=bgPallette)
bgGroup.append(bgTile)
tama, tamaPallette = adafruit_imageload.load("/Sprites/Characters/MUSH/ADULT/BODY.BMP", bitmap=displayio.Bitmap, palette=displayio.Palette)
tamaPallette.make_transparent(3)
tamaTile = displayio.TileGrid(tama, pixel_shader=tamaPallette, x=20, y=100)
root.append(bgGroup)
root.append(bgItemGroup)
root.append(haioGroup)
root.append(fgItemGroup)
root.append(menuGroup)
root.append(selectorGroup)
select = selector.selector([[5,0],[40,0],[70,0],[90,0],[0,220],[110,220]])
select.showSelector(selectorGroup)
wakeTime = time.monotonic()
splash.append(bgTile)
splash.append(tamaTile)
#Load Settings
with open("/Save/settings.json", "r") as reader:
settings = json.loads(reader.read())
timeoutAmount = settings["timeout"]
timeout = round(time.monotonic() + timeoutAmount, 1)
bounce = False
bounceAmount = -10
selector.showSelector(splash)
nextWake = max(entity.character["nextEventTime"], entity.character["nextEvloutionTime"], entity.character["death"]) - entity.character["age"]
#Menu Activites
def do(x):
global wakeTime
if x == 0:
entity.character["age"] += int(time.monotonic() - wakeTime)
wakeTime = time.monotonic()
print(entity.character["age"])
pass
elif x == 1:
pass
@ -44,33 +81,37 @@ def do(x):
elif x == 3:
pass
elif x == 4:
menu.toggleMenu(splash)
menu.toggleMenu(root)
elif x == 5:
buttonBus.button1.deinit()
pin_alarm = alarm.pin.PinAlarm(pin=board.D1, value=True, pull=True)
time.sleep(0.5)
alarm.exit_and_deep_sleep_until_alarms(pin_alarm)
def checkTimeout():
# print("Time: " + str(round(time.monotonic(), 1)) + " Timeout: " + str(timeout))
if round(time.monotonic(), 1) == timeout:
entity.character["age"] += int(time.monotonic() - wakeTime)
# entity.update()
buttonBus.button1.deinit()
pin_alarm = alarm.pin.PinAlarm(pin=board.D1, value=True, pull=True)
time.sleep(0.5)
alarm.exit_and_deep_sleep_until_alarms(pin_alarm)
#System Loop
while True:
if(round(time.monotonic()%0.5, 1) == 0.5):
if bounce == False:
bounce = True
bounceAmount = bounceAmount * -1
tamaTile.y += bounceAmount
else:
if bounce == True:
bounce = False
checkTimeout()
animate.doAnimate(haioGroup, 0.5, 10)
if buttonBus.getSelectedButton() == 0:
selector.lastPos()
select.lastPos()
time.sleep(0.2)
timeout = round(time.monotonic() + timeoutAmount, 1)
elif buttonBus.getSelectedButton() == 1:
do(selector.spos)
do(select.getSPos())
time.sleep(0.2)
timeout = round(time.monotonic() + timeoutAmount, 1)
elif buttonBus.getSelectedButton() == 2:
selector.nextPos()
select.nextPos()
time.sleep(0.2)
timeout = round(time.monotonic() + timeoutAmount, 1)

19
lib/animate.py Normal file
View File

@ -0,0 +1,19 @@
import time
import displayio
bounce = False
bounceAmount = 0
def doAnimate(haioGroup: displayio.Group, duration: float, newBounceAmount: int):
global bounce
global bounceAmount
if bounceAmount == 0:
bounceAmount = newBounceAmount
if(round(time.monotonic()%duration, 2) == round(duration, 2)):
if bounce == False:
bounce = True
bounceAmount = bounceAmount * -1
haioGroup.y += bounceAmount
else:
if bounce == True:
bounce = False

53
lib/entity.py Normal file
View File

@ -0,0 +1,53 @@
import json
import time
import storage
import displayio
import supervisor
import microcontroller
import adafruit_imageload
class entity:
def __init__(self):
pass
profile = {
"spritePath": str(),
"joyMult": float(),
"name": str(),
"respectMult": float(),
"baseJoy": int(),
"evolutionInterval": int(),
"baseRespect": int(),
"lifespan": int()
}
character = {
"profile": str(), #Profile to load
"age": int(), #Age in seconds
"joy": float(), #happy or sad
"respect": float(), #Good or Evil
"mistakes": int(), #How many mistakes made
"money": int(), #MONEY
"nextEventTime": int(), # seconds till event
"nextEvloutionTime": int(), # seconds till
"death": int() # seconds till death
}
def importSave(self):
with open("/Save/current.json", "r") as save:
self.character = json.loads(save.read())
with open("/Data/Profiles/" + self.character["profile"] + ".json", "r") as importedProfile:
self.profile = json.loads(importedProfile.read())
def exportSave(self):
with open("/Save/current.json", "w") as save:
save.write(json.dumps(character))
save.flush()
def show(self, haioGroup: displayio.Group):
haio, haioPalette = adafruit_imageload.load(self.profile["spritePath"], bitmap=displayio.Bitmap, palette=displayio.Palette)
haioPalette.make_transparent(len(haioPalette)-1)
haioTile = displayio.TileGrid(haio, pixel_shader=haioPalette, x=20, y=100)
haioGroup.append(haioTile)

View File

@ -15,7 +15,7 @@ def toggleMenu(splash):
if menuToggle:
battery.reset()
time.sleep(0.05)
timeText = bitmap_label.Label(terminalio.FONT, text="Time: " + str(time.time() - 946684800), scale=1, color=0x000000, x=25, y=60)
timeText = bitmap_label.Label(terminalio.FONT, text="Time: " + str(time.monotonic()), scale=1, color=0x000000, x=25, y=60)
batText = bitmap_label.Label(terminalio.FONT, text="Battery: " + str(round(battery.cell_percent)) + "%", scale=1, color=0x000000, x=25, y=80)
menuGroup = displayio.Group()
menuGroup.append(Rect(10, 10, 115, 220, fill=0xFFFFFF, outline=0x000000, stroke=2))

View File

@ -1,47 +1,42 @@
from adafruit_display_shapes.circle import Circle
spos = -1
select = Circle(15, 10, 10, outline=0x000000, stroke=2)
spos = -1
def showSelector(splash):
global spos
if spos == -1:
splash.append(select)
spos += 1
print("added")
class selector:
def hideSelector(splash):
global spos
if spos != -1:
splash.pop()
def __init__(self, positions):
self.size = len(positions)
self.positions = positions
def nextPos():
global spos
spos = (spos + 1) % 6
updatePos()
def showSelector(self, selectorGroup):
global spos
if spos == -1:
selectorGroup.insert(0,select)
spos += 1
def lastPos():
global spos
spos = (spos - 1) % 6
updatePos()
def hideSelector(self, selectorGroup):
global spos
if spos != -1:
selectorGroup.pop()
def updatePos():
global select
if spos == 0:
select.x = 5
select.y = 0
elif spos == 1:
select.x = 40
select.y = 0
elif spos == 2:
select.x = 70
select.y = 0
elif spos == 3:
select.x = 90
select.y = 0
elif spos == 4:
select.x = 0
select.y = 220
elif spos == 5:
select.x = 110
select.y = 220
def getSPos(self):
return spos
def getSize(self):
return self.size
def nextPos(self):
global spos
spos = (spos + 1) % self.size
self.updatePos()
def lastPos(self):
global spos
spos = (spos - 1) % self.size
self.updatePos()
def updatePos(self):
global select
select.x = self.positions[spos][0]
select.y = self.positions[spos][1]