]>
vault307.fbx.one Git - PicoTamachibi.git/blob - main.py
1 # from icons import food_icon
2 from machine
import I2C
, Pin
3 from ssd1306
import SSD1306_I2C
4 from icon
import Animate
, Icon
, Toolbar
, Button
, Event
14 i2c
= I2C(id=id, sda
=sda
, scl
=scl
)
16 oled
= SSD1306_I2C(width
=128, height
=64, i2c
=i2c
)
24 food
= Icon('food.pbm', width
=16, height
=16, name
="food")
25 lightbulb
= Icon('lightbulb.pbm', width
=16, height
=16, name
="lightbulb")
26 game
= Icon('game.pbm', width
=16, height
=16, name
="game")
27 firstaid
= Icon('firstaid.pbm', width
=16, height
=16, name
="firstaid")
28 toilet
= Icon('toilet.pbm', width
=16, height
=16, name
="toilet")
29 heart
= Icon('heart.pbm', width
=16, height
=16, name
="heart")
30 call
= Icon('call.pbm', width
=16, height
=16, name
="call")
31 save
= Icon('disc.pbm', width
=16, height
=16, name
="toilet")
34 """ Clear the screen """
35 oled
.fill_rect(0,0,128,64,0)
37 # def animate(frames, timer):
38 # for frame in frames:
39 # oled.blit(frame.image, frame.x, frame.y)
47 toolbar
.additem(lightbulb
)
49 toolbar
.additem(firstaid
)
50 toolbar
.additem(toilet
)
51 toolbar
.additem(heart
)
57 poopy
= Animate(x
=96,y
=48, width
=16, height
=16, filename
='poop')
58 baby
= Animate(x
=48,y
=16, width
=48, height
=48, filename
='baby_bounce', animation_type
='bounce')
59 eat
= Animate(x
=48,y
=16, width
=48, height
=48, filename
='eab: 20t')
60 babyzzz
= Animate(animation_type
="loop", x
=48,y
=16, width
=48, height
=48, filename
='baby_zzz')
61 death
= Animate(animation_type
='bounce', x
=40,y
=16, width
=16, height
=16, filename
="skull")
62 go_potty
= Animate(filename
="potty", animation_type
='bounce',x
=64,y
=16, width
=48, height
=48)
63 call_animate
= Animate(filename
='call_animate', width
=16, height
=16, x
=108, y
=0)
64 call_animate
.speed
= 'very slow'
66 #button_jleft = Button(20)
67 #button_jright = Button(19)
68 #button_jup = Button(22)
69 #button_jdown = Button(21)
70 #button_jmid = Button(18)
71 #button_jset = Button(17)
72 #button_jrst = Button(16)
90 def __init__(self
, set="default"):
91 self
.__ActiveConfig
=self
.Configurations
[set]
94 def ActiveConfig(self
):
95 return self
.__ActiveConfig
101 def __init__(self
,config
):
102 for button
in config
.ActiveConfig
:
103 self
.PinObjects
[button
]=Pin(config
.ActiveConfig
[button
])
105 ButtonSetup
=ButtonConfig()
106 InputDevice
=controller(ButtonSetup
)
109 tb
.select(index
, oled
)
116 energy_increase
= Event(name
="Increase Energy", sprite
=heart
, value
=1)
117 firstaid
= Event(name
="First Aid", sprite
=firstaid
, value
=0)
118 toilet
= Event(name
="Toilet", sprite
=toilet
, value
=0)
119 greatgame
= Event(name
="Gaming", sprite
=game
, value
=0)
120 # poop_event = Event(name="poop time", sprite=poop_sprite, callback=poop_check())
121 sleep_time
= Event(name
="sleep time", sprite
=lightbulb
, value
=1)
122 heart_status
= Event(name
="Status", sprite
=heart
)
123 # poop_event.timer = 3
124 # poop_event.timer_ms = 1
130 babyzzz
.speed
= 'very slow'
138 tb
.unselect(index
, oled
)
139 if InputDevice
.PinObjects
["left"].value():
142 index
= tb
.getlength()-1
144 if InputDevice
.PinObjects
["right"].value():
146 if index
== tb
.getlength():
149 if InputDevice
.PinObjects
["cancel"].value():
154 tb
.select(index
, oled
)
156 if InputDevice
.PinObjects
["action"].value():
157 if tb
.selected_item
== "food":
162 if tb
.selected_item
== "game":
163 greatgame
.message
= "Gaming!!!"
164 greatgame
.popup(oled
=oled
)
167 greatgame
.message
= "happy = " + str(happiness
)
168 greatgame
.popup(oled
)
169 greatgame
.message
= "energy = " + str(energy
)
170 greatgame
.popup(oled
)
172 print("game:\n energy = " + str(energy
)+"\n happy = " + str(happiness
))
173 if tb
.selected_item
== "toilet":
174 toilet
.message
= "Cleaning..."
175 toilet
.popup(oled
=oled
)
181 if tb
.selected_item
== "lightbulb":
185 sleep_time
.message
= "Night Night"
186 sleep_time
.popup(oled
)
188 # need to add an event that increases energy level after sleeping for 1 minute
193 if tb
.selected_item
== "firstaid":
194 firstaid
.message
= "Vitamins"
195 firstaid
.popup(oled
=oled
)
199 if tb
.selected_item
== "heart":
200 heart_status
.message
= "health = " + str(health
)
201 heart_status
.popup(oled
)
202 heart_status
.message
= "happy = " + str(happiness
)
203 heart_status
.popup(oled
)
204 heart_status
.message
= "energy = " + str(energy
)
205 heart_status
.popup(oled
)
207 if tb
.selected_item
== "call":
208 # call_animate.animate(oled)
209 # call_animate.set = False
220 if feeding_time
and eat
.done
:
222 energy_increase
.message
= "ENERGY + 1"
223 energy_increase
.popup(oled
=oled
)
231 babyzzz
.animate(oled
)
237 go_potty
.animate(oled
)
245 if (energy
<= 1) and (happiness
<= 1) and (health
<=1):
250 #if (energy <= 1) or (happiness <= 1) or (health <= 1):
251 # set the toolbar call icon to flash
252 # call_animate.set = True
254 # call_animate.set = False
263 tb
.select(index
, oled
)
265 # if call_animate.set:
266 # call_animate.animate(oled)