]>
vault307.fbx.one Git - PicoTamachibi.git/blob - main.py
6091df6861448529f1e14bca21fb073ecf219e1c
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
16 i2c
= I2C(id=id, sda
=sda
, scl
=scl
)
18 oled
= SSD1306_I2C(width
=128, height
=64, i2c
=i2c
)
26 food
= Icon('food.pbm', width
=16, height
=16, name
="food")
27 lightbulb
= Icon('lightbulb.pbm', width
=16, height
=16, name
="lightbulb")
28 game
= Icon('game.pbm', width
=16, height
=16, name
="game")
29 firstaid
= Icon('firstaid.pbm', width
=16, height
=16, name
="firstaid")
30 toilet
= Icon('toilet.pbm', width
=16, height
=16, name
="toilet")
31 heart
= Icon('heart.pbm', width
=16, height
=16, name
="heart")
32 call
= Icon('call.pbm', width
=16, height
=16, name
="call")
33 save
= Icon('disc.pbm', width
=16, height
=16, name
="toilet")
36 """ Clear the screen """
37 oled
.fill_rect(0,0,128,64,0)
39 # def animate(frames, timer):
40 # for frame in frames:
41 # oled.blit(frame.image, frame.x, frame.y)
49 toolbar
.additem(lightbulb
)
51 toolbar
.additem(firstaid
)
52 toolbar
.additem(toilet
)
53 toolbar
.additem(heart
)
59 poopy
= Animate(x
=96,y
=48, width
=16, height
=16, filename
='poop')
60 baby
= Animate(x
=48,y
=16, width
=48, height
=48, filename
='baby_bounce', animation_type
='bounce')
61 eat
= Animate(x
=48,y
=16, width
=48, height
=48, filename
='eab: 20t')
62 babyzzz
= Animate(animation_type
="loop", x
=48,y
=16, width
=48, height
=48, filename
='baby_zzz')
63 death
= Animate(animation_type
='bounce', x
=40,y
=16, width
=16, height
=16, filename
="skull")
64 go_potty
= Animate(filename
="potty", animation_type
='bounce',x
=64,y
=16, width
=48, height
=48)
65 call_animate
= Animate(filename
='call_animate', width
=16, height
=16, x
=108, y
=0)
66 call_animate
.speed
= 'very slow'
68 #button_jleft = Button(20)
69 #button_jright = Button(19)
70 #button_jup = Button(22)
71 #button_jdown = Button(21)
72 #button_jmid = Button(18)
73 #button_jset = Button(17)
74 #button_jrst = Button(16)
92 def __init__(self
, set="default"):
93 self
.__ActiveConfig
=self
.Configurations
[set]
96 def ActiveConfig(self
):
97 return self
.__ActiveConfig
103 def __init__(self
,config
):
104 for button
in config
.ActiveConfig
:
105 self
.PinObjects
[button
]=Pin(config
.ActiveConfig
[button
])
107 ButtonSetup
=ButtonConfig()
108 InputDevice
=controller(ButtonSetup
)
111 tb
.select(index
, oled
)
118 energy_increase
= Event(name
="Increase Energy", sprite
=heart
, value
=1)
119 firstaid
= Event(name
="First Aid", sprite
=firstaid
, value
=0)
120 toilet
= Event(name
="Toilet", sprite
=toilet
, value
=0)
121 greatgame
= Event(name
="Gaming", sprite
=game
, value
=0)
122 # poop_event = Event(name="poop time", sprite=poop_sprite, callback=poop_check())
123 sleep_time
= Event(name
="sleep time", sprite
=lightbulb
, value
=1)
124 heart_status
= Event(name
="Status", sprite
=heart
)
125 # poop_event.timer = 3
126 # poop_event.timer_ms = 1
132 babyzzz
.speed
= 'very slow'
140 tb
.unselect(index
, oled
)
141 if InputDevice
.PinObjects
["left"].value():
144 index
= tb
.getlength()-1
146 if InputDevice
.PinObjects
["right"].value():
148 if index
== tb
.getlength():
151 if InputDevice
.PinObjects
["cancel"].value():
156 tb
.select(index
, oled
)
158 if InputDevice
.PinObjects
["action"].value():
159 if tb
.selected_item
== "food":
164 if tb
.selected_item
== "game":
165 greatgame
.message
= "Gaming!!!"
166 greatgame
.popup(oled
=oled
)
169 greatgame
.message
= "happy = " + str(happiness
)
170 greatgame
.popup(oled
)
171 greatgame
.message
= "energy = " + str(energy
)
172 greatgame
.popup(oled
)
174 print("game:\n energy = " + str(energy
)+"\n happy = " + str(happiness
))
175 if tb
.selected_item
== "toilet":
176 toilet
.message
= "Cleaning..."
177 toilet
.popup(oled
=oled
)
183 if tb
.selected_item
== "lightbulb":
187 sleep_time
.message
= "Night Night"
188 sleep_time
.popup(oled
)
190 # need to add an event that increases energy level after sleeping for 1 minute
195 if tb
.selected_item
== "firstaid":
196 firstaid
.message
= "Vitamins"
197 firstaid
.popup(oled
=oled
)
201 if tb
.selected_item
== "heart":
202 heart_status
.message
= "health = " + str(health
)
203 heart_status
.popup(oled
)
204 heart_status
.message
= "happy = " + str(happiness
)
205 heart_status
.popup(oled
)
206 heart_status
.message
= "energy = " + str(energy
)
207 heart_status
.popup(oled
)
209 if tb
.selected_item
== "call":
210 # call_animate.animate(oled)
211 # call_animate.set = False
222 if feeding_time
and eat
.done
:
224 energy_increase
.message
= "ENERGY + 1"
225 energy_increase
.popup(oled
=oled
)
233 babyzzz
.animate(oled
)
239 go_potty
.animate(oled
)
247 if (energy
<= 1) and (happiness
<= 1) and (health
<=1):
252 #if (energy <= 1) or (happiness <= 1) or (health <= 1):
253 # set the toolbar call icon to flash
254 # call_animate.set = True
256 # call_animate.set = False
265 tb
.select(index
, oled
)
267 # if call_animate.set:
268 # call_animate.animate(oled)