TamaLife is a virtual pet web application built with Flask and SQLite for CS50. The user can create a pet, interact with it, and keep it alive by maintaining four core stats: Hunger, Happiness, Cleanliness, and Health.
The project includes:
- User registration and login system
- A virtual pet associated with each user
- Automatic stat decay over time
- Evolution system based on pet age
- Interactive actions to restore stats
- Dynamic updates on the homepage using JavaScript polling
Users can register, log in, and log out. Passwords are hashed using Werkzeug and stored securely in the database.
Each user can create a single pet. The initial pet starts at full health and evolves over time.
The pet evolves according to its age in minutes. Stages include: Egg → Baby → Child → Teen → Adult → Elder → Dead.
Stats automatically change over time depending on the last update timestamp. If a stat reaches a critical threshold, the pet will die.
Users can improve their pet's stats through four actions:
- Feed
- Play
- Clean
- Heal
These actions update the database and refresh the UI.
The homepage polls the /pet-status route every second.
The frontend updates the pet sprite, animations, and progress bars without reloading the page.
Main Flask application:
- Route definitions
- User authentication
- Pet creation
- Pet actions
- Rendering templates
Contains helper functions:
login_requireddecoratorcompute_stage(evolution logic)update_needs(stat decay system)
Contains:
- CSS files
- Pet sprite images
- Backgrounds and UI assets
Contains Jinja templates:
layout.htmlindex.htmlcreate_pet.htmllogin.htmlregister.htmldead.html
SQLite database storing:
- Users
- Pets
- All associated stats
-
Install dependencies:
pip install -r requirements.txt -
Run Flask:
flask run -
Access the app in your browser at:
http://127.0.0.1:5000/
id(INTEGER PRIMARY KEY)username(TEXT UNIQUE)hash(TEXT)
iduser_idnamehealthhungerhappinesshygienebirthlast_update
This project was created as part of Harvard's CS50. Frameworks and libraries used:
- Flask
- SQLite
- Jinja
- CS50 Library for Python
This project also used GPT-5 for image generation and for code suggestions during the development process.