0.9-Alpha
This commit is contained in:
parent
25734f5f53
commit
e981de8d9d
1
Data/Profiles/BOTORU.json
Normal file
1
Data/Profiles/BOTORU.json
Normal 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
1
Data/Profiles/MUSH.json
Normal 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}
|
||||||
@ -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
1
Save/settings.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"timeout": 1500}
|
||||||
BIN
Sprites/Characters/MUSH/ADULT/BODY.bmp
Normal file
BIN
Sprites/Characters/MUSH/ADULT/BODY.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
91
code.py
91
code.py
@ -1,12 +1,17 @@
|
|||||||
import time
|
import time
|
||||||
|
import json
|
||||||
import alarm
|
import alarm
|
||||||
import board
|
import board
|
||||||
import displayio
|
import displayio
|
||||||
import digitalio
|
|
||||||
import bitmaptools
|
import bitmaptools
|
||||||
import adafruit_imageload
|
import adafruit_imageload
|
||||||
|
import storage
|
||||||
|
import supervisor
|
||||||
|
import microcontroller
|
||||||
|
|
||||||
import menu
|
import menu
|
||||||
|
import entity
|
||||||
|
import animate
|
||||||
import selector
|
import selector
|
||||||
import buttonBus
|
import buttonBus
|
||||||
|
|
||||||
@ -15,27 +20,59 @@ import buttonBus
|
|||||||
#setup
|
#setup
|
||||||
board.DISPLAY.root_group.hidden = False
|
board.DISPLAY.root_group.hidden = False
|
||||||
board.DISPLAY.rotation = 90
|
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)
|
bg, bgPallette = adafruit_imageload.load("/Sprites/Backgrounds/bg1.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette)
|
||||||
bgTile = displayio.TileGrid(bg, pixel_shader=bgPallette)
|
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)
|
root.append(bgGroup)
|
||||||
tamaPallette.make_transparent(3)
|
root.append(bgItemGroup)
|
||||||
tamaTile = displayio.TileGrid(tama, pixel_shader=tamaPallette, x=20, y=100)
|
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)
|
#Load Settings
|
||||||
splash.append(tamaTile)
|
with open("/Save/settings.json", "r") as reader:
|
||||||
|
settings = json.loads(reader.read())
|
||||||
|
timeoutAmount = settings["timeout"]
|
||||||
|
timeout = round(time.monotonic() + timeoutAmount, 1)
|
||||||
|
|
||||||
bounce = False
|
nextWake = max(entity.character["nextEventTime"], entity.character["nextEvloutionTime"], entity.character["death"]) - entity.character["age"]
|
||||||
bounceAmount = -10
|
|
||||||
selector.showSelector(splash)
|
|
||||||
|
|
||||||
#Menu Activites
|
#Menu Activites
|
||||||
def do(x):
|
def do(x):
|
||||||
|
global wakeTime
|
||||||
if x == 0:
|
if x == 0:
|
||||||
|
entity.character["age"] += int(time.monotonic() - wakeTime)
|
||||||
|
wakeTime = time.monotonic()
|
||||||
|
print(entity.character["age"])
|
||||||
pass
|
pass
|
||||||
elif x == 1:
|
elif x == 1:
|
||||||
pass
|
pass
|
||||||
@ -44,33 +81,37 @@ def do(x):
|
|||||||
elif x == 3:
|
elif x == 3:
|
||||||
pass
|
pass
|
||||||
elif x == 4:
|
elif x == 4:
|
||||||
menu.toggleMenu(splash)
|
menu.toggleMenu(root)
|
||||||
elif x == 5:
|
elif x == 5:
|
||||||
buttonBus.button1.deinit()
|
buttonBus.button1.deinit()
|
||||||
pin_alarm = alarm.pin.PinAlarm(pin=board.D1, value=True, pull=True)
|
pin_alarm = alarm.pin.PinAlarm(pin=board.D1, value=True, pull=True)
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
alarm.exit_and_deep_sleep_until_alarms(pin_alarm)
|
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
|
#System Loop
|
||||||
while True:
|
while True:
|
||||||
|
checkTimeout()
|
||||||
if(round(time.monotonic()%0.5, 1) == 0.5):
|
animate.doAnimate(haioGroup, 0.5, 10)
|
||||||
if bounce == False:
|
|
||||||
bounce = True
|
|
||||||
bounceAmount = bounceAmount * -1
|
|
||||||
tamaTile.y += bounceAmount
|
|
||||||
else:
|
|
||||||
if bounce == True:
|
|
||||||
bounce = False
|
|
||||||
|
|
||||||
|
|
||||||
if buttonBus.getSelectedButton() == 0:
|
if buttonBus.getSelectedButton() == 0:
|
||||||
selector.lastPos()
|
select.lastPos()
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
timeout = round(time.monotonic() + timeoutAmount, 1)
|
||||||
elif buttonBus.getSelectedButton() == 1:
|
elif buttonBus.getSelectedButton() == 1:
|
||||||
do(selector.spos)
|
do(select.getSPos())
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
timeout = round(time.monotonic() + timeoutAmount, 1)
|
||||||
elif buttonBus.getSelectedButton() == 2:
|
elif buttonBus.getSelectedButton() == 2:
|
||||||
selector.nextPos()
|
select.nextPos()
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
timeout = round(time.monotonic() + timeoutAmount, 1)
|
||||||
|
|||||||
19
lib/animate.py
Normal file
19
lib/animate.py
Normal 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
53
lib/entity.py
Normal 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)
|
||||||
@ -15,7 +15,7 @@ def toggleMenu(splash):
|
|||||||
if menuToggle:
|
if menuToggle:
|
||||||
battery.reset()
|
battery.reset()
|
||||||
time.sleep(0.05)
|
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)
|
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 = displayio.Group()
|
||||||
menuGroup.append(Rect(10, 10, 115, 220, fill=0xFFFFFF, outline=0x000000, stroke=2))
|
menuGroup.append(Rect(10, 10, 115, 220, fill=0xFFFFFF, outline=0x000000, stroke=2))
|
||||||
|
|||||||
@ -1,47 +1,42 @@
|
|||||||
from adafruit_display_shapes.circle import Circle
|
from adafruit_display_shapes.circle import Circle
|
||||||
|
|
||||||
spos = -1
|
|
||||||
select = Circle(15, 10, 10, outline=0x000000, stroke=2)
|
select = Circle(15, 10, 10, outline=0x000000, stroke=2)
|
||||||
|
spos = -1
|
||||||
|
|
||||||
def showSelector(splash):
|
class selector:
|
||||||
global spos
|
|
||||||
if spos == -1:
|
|
||||||
splash.append(select)
|
|
||||||
spos += 1
|
|
||||||
print("added")
|
|
||||||
|
|
||||||
def hideSelector(splash):
|
def __init__(self, positions):
|
||||||
global spos
|
self.size = len(positions)
|
||||||
if spos != -1:
|
self.positions = positions
|
||||||
splash.pop()
|
|
||||||
|
|
||||||
def nextPos():
|
def showSelector(self, selectorGroup):
|
||||||
global spos
|
global spos
|
||||||
spos = (spos + 1) % 6
|
if spos == -1:
|
||||||
updatePos()
|
selectorGroup.insert(0,select)
|
||||||
|
spos += 1
|
||||||
|
|
||||||
def lastPos():
|
def hideSelector(self, selectorGroup):
|
||||||
global spos
|
global spos
|
||||||
spos = (spos - 1) % 6
|
if spos != -1:
|
||||||
updatePos()
|
selectorGroup.pop()
|
||||||
|
|
||||||
def updatePos():
|
def getSPos(self):
|
||||||
global select
|
return spos
|
||||||
if spos == 0:
|
|
||||||
select.x = 5
|
def getSize(self):
|
||||||
select.y = 0
|
return self.size
|
||||||
elif spos == 1:
|
|
||||||
select.x = 40
|
def nextPos(self):
|
||||||
select.y = 0
|
global spos
|
||||||
elif spos == 2:
|
spos = (spos + 1) % self.size
|
||||||
select.x = 70
|
self.updatePos()
|
||||||
select.y = 0
|
|
||||||
elif spos == 3:
|
def lastPos(self):
|
||||||
select.x = 90
|
global spos
|
||||||
select.y = 0
|
spos = (spos - 1) % self.size
|
||||||
elif spos == 4:
|
self.updatePos()
|
||||||
select.x = 0
|
|
||||||
select.y = 220
|
def updatePos(self):
|
||||||
elif spos == 5:
|
global select
|
||||||
select.x = 110
|
select.x = self.positions[spos][0]
|
||||||
select.y = 220
|
select.y = self.positions[spos][1]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user