]> vault307.fbx.one Git - PicoTamachibi.git/blob - main.py
Nett hier aber waren Sie schon mal in Hamburg?
[PicoTamachibi.git] / main.py
1 from machine import I2C, Pin
2 from ssd1306 import SSD1306_I2C
3 from icon import Animate, Icon, Toolbar, Button, Event
4 from time import sleep
5 from sys import exit
6 import framebuf
7 import gc
8
9 # some change
10 # Hier war Roman :)
11 # some other change
12
13 sda = Pin(0)
14 scl = Pin(1)
15 id = 0
16
17 i2c = I2C(id=id, sda=sda, scl=scl)
18
19 oled = SSD1306_I2C(width=128, height=64, i2c=i2c)
20 oled.init_display()
21
22 health = 2
23 happiness = 1
24 energy = 1
25
26 # load icons
27 food = Icon('food.pbm', width=16, height=16, name="food")
28 lightbulb = Icon('lightbulb.pbm', width=16, height=16, name="lightbulb")
29 game = Icon('game.pbm', width=16, height=16, name="game")
30 firstaid = Icon('firstaid.pbm', width=16, height=16, name="firstaid")
31 toilet = Icon('toilet.pbm', width=16, height=16, name="toilet")
32 heart = Icon('heart.pbm', width=16, height=16, name="heart")
33 call = Icon('call.pbm', width=16, height=16, name="call")
34 save = Icon('disc.pbm', width=16, height=16, name="toilet")
35
36 def clear():
37 """ Clear the screen """
38 oled.fill_rect(0,0,128,64,0)
39
40 # May the Force be with you // Patrick
41
42 # def animate(frames, timer):
43 # for frame in frames:
44 # oled.blit(frame.image, frame.x, frame.y)
45 # oled.show()
46 # sleep(0.1)
47
48 def build_toolbar():
49 toolbar = Toolbar()
50 toolbar.spacer = 2
51 toolbar.additem(food)
52 toolbar.additem(lightbulb)
53 toolbar.additem(game)
54 toolbar.additem(firstaid)
55 toolbar.additem(toilet)
56 toolbar.additem(heart)
57 toolbar.additem(call)
58 toolbar.additem(save)
59 return toolbar
60
61 tb = build_toolbar()
62 poopy = Animate(x=96,y=48, width=16, height=16, filename='poop')
63 baby = Animate(x=48,y=16, width=48, height=48, filename='baby_bounce', animation_type='bounce')
64 eat = Animate(x=48,y=16, width=48, height=48, filename='eab: 20t')
65 babyzzz = Animate(animation_type="loop", x=48,y=16, width=48, height=48, filename='baby_zzz')
66 death = Animate(animation_type='bounce', x=40,y=16, width=16, height=16, filename="skull")
67 go_potty = Animate(filename="potty", animation_type='bounce',x=64,y=16, width=48, height=48)
68 call_animate = Animate(filename='call_animate', width=16, height=16, x=108, y=0)
69 call_animate.speed = 'very slow'
70
71 #button_jleft = Button(20)
72 #button_jright = Button(19)
73 #button_jup = Button(22)
74 #button_jdown = Button(21)
75 #button_jmid = Button(18)
76 #button_jset = Button(17)
77 #button_jrst = Button(16)
78
79 class ButtonConfig:
80 Configurations = {
81 "default":{
82 "left":20,
83 "right":19,
84 "action":18,
85 "cancel":16
86 },
87 "set1":{
88 "left":20,
89 "right":19,
90 "action":18
91 }
92 }
93 __ActiveConfig={}
94
95 def __init__(self, set="default"):
96 self.__ActiveConfig=self.Configurations[set]
97
98 @property
99 def ActiveConfig(self):
100 return self.__ActiveConfig
101
102
103 class controller:
104 PinObjects={}
105
106 def __init__(self,config):
107 for button in config.ActiveConfig:
108 self.PinObjects[button]=Pin(config.ActiveConfig[button])
109
110 ButtonSetup=ButtonConfig()
111 InputDevice=controller(ButtonSetup)
112
113 index = 3
114 tb.select(index, oled)
115 cancel = False
116 feeding_time = False
117 sleeping = False
118 death.set = True
119
120 # Set up Events
121 energy_increase = Event(name="Increase Energy", sprite=heart, value=1)
122 firstaid = Event(name="First Aid", sprite=firstaid, value=0)
123 toilet = Event(name="Toilet", sprite=toilet, value=0)
124 greatgame = Event(name="Gaming", sprite=game, value=0)
125 # poop_event = Event(name="poop time", sprite=poop_sprite, callback=poop_check())
126 sleep_time = Event(name="sleep time", sprite=lightbulb, value=1)
127 heart_status = Event(name="Status", sprite=heart)
128 # poop_event.timer = 3
129 # poop_event.timer_ms = 1
130
131 baby.bounce()
132 poopy.bounce()
133 death.loop(no=-1)
134 death.speed='slow'
135 babyzzz.speed = 'very slow'
136 go_potty.loop(no=1)
137 go_potty.set = True
138 poopy.set = False
139 go_potty.load()
140
141 while True:
142 if not cancel:
143 tb.unselect(index, oled)
144 if InputDevice.PinObjects["left"].value():
145 index -= 1
146 if index < 0:
147 index = tb.getlength()-1
148 cancel = False
149 if InputDevice.PinObjects["right"].value():
150 index += 1
151 if index == tb.getlength():
152 index = 0
153 cancel = False
154 if InputDevice.PinObjects["cancel"].value():
155 cancel = True
156 index = -1
157
158 if not cancel:
159 tb.select(index, oled)
160
161 if InputDevice.PinObjects["action"].value():
162 if tb.selected_item == "food":
163 feeding_time = True
164 sleeping = False
165 baby.unload()
166
167 if tb.selected_item == "game":
168 greatgame.message = "Gaming!!!"
169 greatgame.popup(oled=oled)
170 happiness += 1
171 energy -= 1
172 greatgame.message = "happy = " + str(happiness)
173 greatgame.popup(oled)
174 greatgame.message = "energy = " + str(energy)
175 greatgame.popup(oled)
176 clear()
177 print("game:\n energy = " + str(energy)+"\n happy = " + str(happiness))
178 if tb.selected_item == "toilet":
179 toilet.message = "Cleaning..."
180 toilet.popup(oled=oled)
181 poopy.set = False
182 baby.set = True
183 happiness += 1
184 clear()
185 poopy.unload()
186 if tb.selected_item == "lightbulb":
187 if not sleeping:
188 sleeping = True
189 babyzzz.load()
190 sleep_time.message = "Night Night"
191 sleep_time.popup(oled)
192 clear()
193 # need to add an event that increases energy level after sleeping for 1 minute
194 else:
195 sleeping = False
196 babyzzz.unload()
197 print("lightbulb")
198 if tb.selected_item == "firstaid":
199 firstaid.message = "Vitamins"
200 firstaid.popup(oled=oled)
201 health += 1
202
203 clear()
204 if tb.selected_item == "heart":
205 heart_status.message = "health = " + str(health)
206 heart_status.popup(oled)
207 heart_status.message = "happy = " + str(happiness)
208 heart_status.popup(oled)
209 heart_status.message = "energy = " + str(energy)
210 heart_status.popup(oled)
211 clear()
212 if tb.selected_item == "call":
213 # call_animate.animate(oled)
214 # call_animate.set = False
215 print("call")
216
217 # Time for Poop?
218 # poop_check()
219 # poop_event.tick()
220
221 if feeding_time:
222 eat.load()
223 if not eat.done:
224 eat.animate(oled)
225 if feeding_time and eat.done:
226 feeding_time = False
227 energy_increase.message = "ENERGY + 1"
228 energy_increase.popup(oled=oled)
229 energy += 1
230
231 clear()
232 eat.unload()
233 baby.load()
234 else:
235 if sleeping:
236 babyzzz.animate(oled)
237 else:
238 if baby.set:
239 baby.load()
240 baby.animate(oled)
241 if go_potty.set:
242 go_potty.animate(oled)
243 if go_potty.done:
244 print("potty done")
245 go_potty.set = False
246 poopy.set = True
247 baby.load()
248 baby.bounce(no=-1)
249 baby.set = True
250 if (energy <= 1) and (happiness <= 1) and (health <=1):
251 death.set = True
252 else:
253 death.set = False
254
255 #if (energy <= 1) or (happiness <= 1) or (health <= 1):
256 # set the toolbar call icon to flash
257 # call_animate.set = True
258 #else:
259 # call_animate.set = False
260
261 if poopy.set:
262 poopy.load()
263 poopy.animate(oled)
264 if death.set:
265 death.animate(oled)
266 tb.show(oled)
267 if index == 6:
268 tb.select(index, oled)
269 #else:
270 # if call_animate.set:
271 # call_animate.animate(oled)
272
273 oled.show()
274 sleep(0.05)
275