Skip to content

Commit 0b22f67

Browse files
authored
TamaTac & SfxEngine + Sprite tools (#24)
1 parent 9ba1d46 commit 0b22f67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+8282
-0
lines changed

Apps/TamaTac/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
3+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
4+
5+
if (DEFINED ENV{TACTILITY_SDK_PATH})
6+
set(TACTILITY_SDK_PATH $ENV{TACTILITY_SDK_PATH})
7+
else()
8+
set(TACTILITY_SDK_PATH "../../release/TactilitySDK")
9+
message(WARNING "⚠️ TACTILITY_SDK_PATH environment variable is not set, defaulting to ${TACTILITY_SDK_PATH}")
10+
endif()
11+
12+
include("${TACTILITY_SDK_PATH}/TactilitySDK.cmake")
13+
set(EXTRA_COMPONENT_DIRS ${TACTILITY_SDK_PATH})
14+
15+
project(TamaTac)
16+
tactility_project(TamaTac)

Apps/TamaTac/README.md

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
# TamaTac
2+
3+
A virtual pet game for Tactility OS, inspired by Tamagotchi and Tactiligotchi.
4+
5+
## About
6+
7+
TamaTac is a digital pet that lives in your ESP32 device. Feed it, play with it, keep it healthy, and watch it grow through different life stages. Your pet persists even when the app is closed, and stats decay while you're away.
8+
9+
## Features
10+
11+
### Core Pet System
12+
- **5 Stats**: Hunger, Happiness, Health, Energy, Cleanliness (0-100%)
13+
- **6 Life Stages**: Egg > Baby > Teen > Adult > Elder > Ghost
14+
- **5 Personalities**: Energetic, Lazy, Glutton, Cheerful, Hardy — each affects stat decay rates
15+
- **Automatic Decay**: Stats decay on a 30-second FreeRTOS timer
16+
- **Configurable Speed**: Slow (0.5x), Normal (1x), Fast (2x) decay rates
17+
- **Sickness**: Health below 20% triggers sick state
18+
- **Death**: Health reaching 0 ends the game
19+
20+
### Actions
21+
- **Feed**: Restores hunger (+30%), may cause poop (40% chance)
22+
- **Play**: Randomly launches Simon Says or Reaction Time mini-game
23+
- **Medicine**: Cures sickness (+30% health) or small boost (+5%)
24+
- **Sleep**: Restores energy (+50%)
25+
- **Clean**: Toolbar button clears all poop, restores cleanliness
26+
- **Pet**: Tap the pet sprite for a small happiness boost (+5%, 3s cooldown)
27+
28+
### Day/Night Cycle
29+
A 1-hour real-time cycle (30 min day / 30 min night):
30+
- **Day**: Increased energy drain (more active)
31+
- **Night**: Increased hunger drain (metabolism), auto-sleep when energy is critically low
32+
- **Visual indicator**: Pet area background changes color between day and night
33+
- MainView refreshes every 5 seconds to reflect changes
34+
35+
### Random Events
36+
Random events occur during timer ticks (~12% chance per tick):
37+
- **Found Treat**: +15 hunger
38+
- **Made a Friend**: +15 happiness
39+
- **Caught a Cold**: Pet gets sick, -10 health
40+
- **Got Muddy**: -20 cleanliness
41+
- **Had a Nap**: +15 energy
42+
- **Sunny Day**: +10 happiness (day only)
43+
44+
Events are contextual — only eligible events trigger based on current stats.
45+
46+
### Mini-Games
47+
48+
#### Simon Says (Pattern Game)
49+
- 4 colored buttons (red, blue, green, yellow) in a 2x2 grid
50+
- Watch the sequence flash, then repeat it
51+
- 3 rounds with increasing pattern length (starts at 3)
52+
- **Win all 3 rounds**: +30 happiness, -10 energy, -5 hunger
53+
- **Partial win (1-2 rounds)**: +10-20 happiness, -5 energy
54+
- **Lose immediately**: +5 happiness, -5 energy
55+
56+
#### Reaction Time Game
57+
- Large green circle target appears after a random delay (1-3.5 seconds)
58+
- Tap as fast as possible when it appears
59+
- Tapping too early = penalty round
60+
- 3 rounds, scored by average reaction time
61+
- Performance mapped to happiness reward
62+
63+
### Pet Cemetery
64+
When your pet dies, it's remembered in the Cemetery:
65+
- Stores up to 5 most recent pets (FIFO)
66+
- Records personality, life stage reached, and age at death
67+
- Accessible from the Menu
68+
69+
### Achievement System
70+
12 achievements to unlock, stored as a bitfield:
71+
- **First Feed**: Feed your pet
72+
- **First Play**: Play a mini-game
73+
- **First Cure**: Cure sickness
74+
- **Baby Steps**: Evolve to Baby
75+
- **Growing Up**: Evolve to Teen
76+
- **All Grown Up**: Evolve to Adult
77+
- **Wise Elder**: Evolve to Elder
78+
- **Perfect Pet**: All stats >= 90%
79+
- **Survivor**: Pet lives 24 hours
80+
- **Pro Gamer**: Perfect mini-game score
81+
- **Clean Freak**: Clean 10 times
82+
- **Night Owl**: Play at night
83+
84+
### Persistence
85+
- Auto-saves every 30 seconds and on every action
86+
- All stats, state flags, and timestamps preserved
87+
- **Time-Away Logic**: Calculates elapsed time since last save, applies decay (capped at ~50 minutes to prevent wipeout), ages pet, and checks evolution
88+
89+
### Sound
90+
Uses the shared SfxEngine library:
91+
- **SFX**: Unique sounds for Feed, Play, Medicine, Sleep, Clean actions; Chirp for tap-to-pet; mini-game sounds (Blip, Confirm, Error, Success)
92+
- Sound toggle in Settings
93+
94+
### Responsive Scaling
95+
Adapts to all Tactility screen sizes:
96+
- **Small** (Cardputer 240x135, T-Dongle): Compact layout, 2x sprites
97+
- **Medium** (T-Deck 320x240): Default layout, 3x sprites
98+
- **Large** (480x320 panels): Spacious layout
99+
- **XLarge** (800x480+): Full-size layout
100+
101+
### Views
102+
- **Main View**: Pet sprite, stat bars with icons, action buttons, poop display, day/night visuals
103+
- **Menu View**: Navigation to Stats, Settings, Cemetery, and Achievements
104+
- **Stats View**: Detailed stats with exact values, age, life stage, personality
105+
- **Settings View**: Sound toggle, decay speed selector
106+
- **Pattern Game**: Simon Says mini-game
107+
- **Reaction Game**: Reaction time mini-game
108+
- **Cemetery View**: Hall of fame for past pets
109+
- **Achievements View**: Progress tracker for all 12 achievements
110+
111+
### Animated Sprites
112+
- 24x24 RGB565 full-color sprites with transparency (magenta color key)
113+
- 12 animated pet sprites (2-3 frames each) for all life stages and states
114+
- 9 monochrome 8x8 UI icons for stats and action buttons
115+
- Canvas-rendered with responsive scaling (2x on small screens, 3x on medium+)
116+
- Animation timer at ~5fps for smooth frame cycling
117+
118+
#### Sprite Preview
119+
120+
| Life Stages | | | | |
121+
|:-:|:-:|:-:|:-:|:-:|
122+
| ![Egg](sprites/egg_idle.png) | ![Baby](sprites/baby_idle.png) | ![Teen](sprites/teen_idle.png) | ![Adult](sprites/adult_idle.png) | ![Elder](sprites/elder_idle.png) |
123+
| Egg (cream) | Baby (pink) | Teen (blue) | Adult (green) | Elder (purple) |
124+
125+
| States | | | | | | |
126+
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
127+
| ![Happy](sprites/happy.png) | ![Sad](sprites/sad.png) | ![Sick](sprites/sick.png) | ![Eating](sprites/eating.png) | ![Playing](sprites/playing.png) | ![Sleeping](sprites/sleeping.png) | ![Ghost](sprites/ghost.png) |
128+
| Happy | Sad | Sick | Eating | Playing | Sleeping | Ghost |
129+
130+
### Visual Polish
131+
- **Evolution flash**: Brief white flash when pet evolves to a new life stage
132+
- **Night sky**: Twinkling star dots in the pet area during night phase
133+
- **Sleep Z's**: Floating animated Z characters while pet sleeps
134+
- **Mood indicator**: Colored dot in pet area corner (green = happy, orange = warning, red = sick)
135+
136+
## How to Play
137+
138+
### Starting Out
139+
- Your pet starts as an Egg with healthy stats
140+
- After 1 hour it evolves to Baby, then Teen (8h), Adult (24h), Elder (72h)
141+
- Keep stats above 30% to prevent sickness
142+
- Tap the pet sprite anytime for a small happiness boost
143+
144+
### Daily Care
145+
1. **Feed** when hunger drops below 50%
146+
2. **Play** the mini-game to boost happiness
147+
3. **Sleep** when energy is low
148+
4. **Medicine** if pet gets sick
149+
5. **Clean** poop from the toolbar button
150+
151+
### Evolution Timeline
152+
153+
| Stage | Age |
154+
|-------|-----|
155+
| Egg | 0-1 hour |
156+
| Baby | 1-8 hours |
157+
| Teen | 8-24 hours |
158+
| Adult | 24-72 hours |
159+
| Elder | 72+ hours |
160+
161+
## Building
162+
163+
```bash
164+
cd Apps/TamaTac
165+
166+
# Build
167+
python tactility.py build
168+
169+
# Build, install, and run
170+
python tactility.py bir <device-ip>
171+
```
172+
173+
## Project Structure
174+
175+
```text
176+
TamaTac/
177+
CMakeLists.txt
178+
manifest.properties
179+
tactility.py
180+
main/
181+
CMakeLists.txt
182+
Source/
183+
main.cpp # Entry point (registerApp)
184+
TamaTac.h/cpp # Main app class, view management, action handlers
185+
MainView.h/cpp # Pet display, stat bars, action buttons, day/night
186+
MenuView.h/cpp # Navigation menu
187+
StatsView.h/cpp # Detailed stats display (incl. personality)
188+
SettingsView.h/cpp # Sound toggle and decay speed settings
189+
PatternGame.h/cpp # Simon Says mini-game
190+
ReactionGame.h/cpp # Reaction time mini-game
191+
CemeteryView.h/cpp # Pet cemetery / hall of fame
192+
Achievements.h/cpp # Achievement system (12 achievements)
193+
PetLogic.h/cpp # Game mechanics, persistence, decay, events
194+
PetStats.h # Data structures, enums, constants, thresholds
195+
Sprites.h # Sprite/icon types, enums, 8x8 icon data
196+
SpriteData.h # 24x24 RGB565 animated sprite pixel data
197+
```
198+
199+
## Architecture
200+
201+
### View Management
202+
TamaTac uses a multi-view pattern with a shared `wrapperWidget`. Views are swapped via `stopActiveView()` + `lv_obj_clean()` + `newView.onStart()`. Each view has `onStart()`/`onStop()` lifecycle methods.
203+
204+
### Key Components
205+
- **TamaTac**: App lifecycle, view routing, action handlers, achievement triggers, static game state
206+
- **PetLogic**: Stat management, decay, evolution, personality modifiers, day/night cycle, random events, save/load
207+
- **MainView**: Animated pet canvas, stat bars, action buttons, tap-to-pet, day/night visuals, polish effects, 5s refresh timer
208+
- **PatternGame**: Self-contained Simon Says with timer-based sequence display
209+
- **ReactionGame**: Phase-based state machine (wait > target > result > final)
210+
- **CemeteryView**: FIFO record storage for up to 5 past pets
211+
- **AchievementsView**: Bitfield-based achievement tracking with 12 unlockables
212+
- **SfxEngine**: Shared library for synthesized sound effects
213+
214+
### Save Data
215+
216+
| Namespace | Keys |
217+
|-----------|------|
218+
| `"TamaTac"` | `hunger`, `happiness`, `health`, `energy`, `cleanliness`, `poopCount`, `ageSeconds`, `ageHours`, `lifespan`, `isSick`, `isAsleep`, `isDead`, `stage`, `currentAnim`, `lastSaveTime`, `personality` |
219+
| `"TamaTacCfg"` | `soundEnabled`, `decaySpeed` |
220+
| `"TamaTacCem"` | `count`, `pers0..4`, `stage0..4`, `age0..4`, `valid0..4` |
221+
| `"TamaTacAch"` | `bits` (uint16 bitfield), `cleanCnt` |
222+
223+
## Screenshots
224+
225+
| | | | |
226+
|:-:|:-:|:-:|:-:|
227+
| ![Main](images/screenshot-one.tactility.tamatac.png) | ![Main with poops](images/screenshot-12.png) | ![Teen](images/screenshot-11.png) | ![Sleeping](images/screenshot-16.png) |
228+
| Main View | Poops! | Teen | Sleeping |
229+
| ![Menu](images/screenshot-13.png) | ![Stats](images/screenshot-14.png) | ![Settings](images/screenshot-15.png) | ![Achievements](images/screenshot-1.png) |
230+
| Menu | Stats | Settings | Achievements |
231+
232+
## Known Issues
233+
234+
- **Offline time not tracked across reboots**: `lastSaveTime` uses uptime milliseconds (`tt::kernel::getMillis()`), which resets to 0 on device reboot. This means stat decay during power-off periods is not applied. A proper fix would require RTC or epoch-based timestamps, which are not currently available on all Tactility devices.
235+
236+
## Credits
237+
238+
- **Inspired by**: Tamagotchi (Bandai), Tactiligotchi (NellowTCS)
239+
- **Built with**: TactilitySDK, LVGL, ESP-IDF, SfxEngine
240+
- **Platform**: Tactility OS
6.24 KB
Loading
4.61 KB
Loading
4.03 KB
Loading
3.87 KB
Loading
5.65 KB
Loading
3.64 KB
Loading
4.04 KB
Loading
4.03 KB
Loading

0 commit comments

Comments
 (0)