]> vault307.fbx.one Git - PicoTamachibi.git/blob - main.py
6091df6861448529f1e14bca21fb073ecf219e1c
[PicoTamachibi.git] / 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
5 from time import sleep
6 from sys import exit
7 import framebuf
8 import gc
9
10 # some change
11
12 sda = Pin(0)
13 scl = Pin(1)
14 id = 0
15
16 i2c = I2C(id=id, sda=sda, scl=scl)
17
18 oled = SSD1306_I2C(width=128, height=64, i2c=i2c)
19 oled.init_display()
20
21 health = 2
22 happiness = 1
23 energy = 1
24
25 # load icons
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")
34
35 def clear():
36 """ Clear the screen """
37 oled.fill_rect(0,0,128,64,0)
38
39 # def animate(frames, timer):
40 # for frame in frames:
41 # oled.blit(frame.image, frame.x, frame.y)
42 # oled.show()
43 # sleep(0.1)
44
45 def build_toolbar():
46 toolbar = Toolbar()
47 toolbar.spacer = 2
48 toolbar.additem(food)
49 toolbar.additem(lightbulb)
50 toolbar.additem(game)
51 toolbar.additem(firstaid)
52 toolbar.additem(toilet)
53 toolbar.additem(heart)
54 toolbar.additem(call)
55 toolbar.additem(save)
56 return toolbar
57
58 tb = build_toolbar()
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'
67
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)
75
76 class ButtonConfig:
77 Configurations = {
78 "default":{
79 "left":20,
80 "right":19,
81 "action":18,
82 "cancel":16
83 },
84 "set1":{
85 "left":20,
86 "right":19,
87 "action":18
88 }
89 }
90 __ActiveConfig={}
91
92 def __init__(self, set="default"):
93 self.__ActiveConfig=self.Configurations[set]
94
95 @property
96 def ActiveConfig(self):
97 return self.__ActiveConfig
98
99
100 class controller:
101 PinObjects={}
102
103 def __init__(self,config):
104 for button in config.ActiveConfig:
105 self.PinObjects[button]=Pin(config.ActiveConfig[button])
106
107 ButtonSetup=ButtonConfig()
108 InputDevice=controller(ButtonSetup)
109
110 index = 3
111 tb.select(index, oled)
112 cancel = False
113 feeding_time = False
114 sleeping = False
115 death.set = True
116
117 # Set up Events
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
127
128 baby.bounce()
129 poopy.bounce()
130 death.loop(no=-1)
131 death.speed='slow'
132 babyzzz.speed = 'very slow'
133 go_potty.loop(no=1)
134 go_potty.set = True
135 poopy.set = False
136 go_potty.load()
137
138 while True:
139 if not cancel:
140 tb.unselect(index, oled)
141 if InputDevice.PinObjects["left"].value():
142 index -= 1
143 if index < 0:
144 index = tb.getlength()-1
145 cancel = False
146 if InputDevice.PinObjects["right"].value():
147 index += 1
148 if index == tb.getlength():
149 index = 0
150 cancel = False
151 if InputDevice.PinObjects["cancel"].value():
152 cancel = True
153 index = -1
154
155 if not cancel:
156 tb.select(index, oled)
157
158 if InputDevice.PinObjects["action"].value():
159 if tb.selected_item == "food":
160 feeding_time = True
161 sleeping = False
162 baby.unload()
163
164 if tb.selected_item == "game":
165 greatgame.message = "Gaming!!!"
166 greatgame.popup(oled=oled)
167 happiness += 1
168 energy -= 1
169 greatgame.message = "happy = " + str(happiness)
170 greatgame.popup(oled)
171 greatgame.message = "energy = " + str(energy)
172 greatgame.popup(oled)
173 clear()
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)
178 poopy.set = False
179 baby.set = True
180 happiness += 1
181 clear()
182 poopy.unload()
183 if tb.selected_item == "lightbulb":
184 if not sleeping:
185 sleeping = True
186 babyzzz.load()
187 sleep_time.message = "Night Night"
188 sleep_time.popup(oled)
189 clear()
190 # need to add an event that increases energy level after sleeping for 1 minute
191 else:
192 sleeping = False
193 babyzzz.unload()
194 print("lightbulb")
195 if tb.selected_item == "firstaid":
196 firstaid.message = "Vitamins"
197 firstaid.popup(oled=oled)
198 health += 1
199
200 clear()
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)
208 clear()
209 if tb.selected_item == "call":
210 # call_animate.animate(oled)
211 # call_animate.set = False
212 print("call")
213
214 # Time for Poop?
215 # poop_check()
216 # poop_event.tick()
217
218 if feeding_time:
219 eat.load()
220 if not eat.done:
221 eat.animate(oled)
222 if feeding_time and eat.done:
223 feeding_time = False
224 energy_increase.message = "ENERGY + 1"
225 energy_increase.popup(oled=oled)
226 energy += 1
227
228 clear()
229 eat.unload()
230 baby.load()
231 else:
232 if sleeping:
233 babyzzz.animate(oled)
234 else:
235 if baby.set:
236 baby.load()
237 baby.animate(oled)
238 if go_potty.set:
239 go_potty.animate(oled)
240 if go_potty.done:
241 print("potty done")
242 go_potty.set = False
243 poopy.set = True
244 baby.load()
245 baby.bounce(no=-1)
246 baby.set = True
247 if (energy <= 1) and (happiness <= 1) and (health <=1):
248 death.set = True
249 else:
250 death.set = False
251
252 #if (energy <= 1) or (happiness <= 1) or (health <= 1):
253 # set the toolbar call icon to flash
254 # call_animate.set = True
255 #else:
256 # call_animate.set = False
257
258 if poopy.set:
259 poopy.load()
260 poopy.animate(oled)
261 if death.set:
262 death.animate(oled)
263 tb.show(oled)
264 if index == 6:
265 tb.select(index, oled)
266 #else:
267 # if call_animate.set:
268 # call_animate.animate(oled)
269
270 oled.show()
271 sleep(0.05)
272