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