Skip to content
/ tamaR Public

An R app to play the original Tamagotchi online

License

Notifications You must be signed in to change notification settings

Almarch/tamaR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TaMaGoTcHi The Tamagotchi is live on R

This is a package allowing the emulation of a P1 Tamagotchi in R using TamaLIB.

R is a scripting language, allowing either a live interaction or the elaboration of custom programs.

A web app can be launched online using the R library shiny. The online app can be installed either with R, either without, using docker.

311432812-dbf7285f-a233-4667-8983-b687dc40f67d

Installation

Start by cloning the git repository. A ROM named "rom.bin" must then be placed into the src directory.

git clone https://github.almarch/tamaR.git
cp rom.bin tamaR/src/

Installation as a docker container

tamaR can be installed and launched as a docker container. As such, R installation is not required.

cd tamaR
docker build -t tama .

The container can now be run:

docker run -d -p 1996:80 tama

The shiny app is directly available at http://127.0.0.1:1996/

Installation as an R package

tamaR can be installed as an R package. To do so, the first step is to convert the ROM into 12 bits. Then the package can be built with Rcpp and installed.

Rscript tamaR/src/TamaRomConvert.r
R -e "install.packages(c('Rcpp','shiny','png','shinyjs','bsplus'))"
R CMD INSTALL tamaR

The package tamaR can now be called from an R console.

library(tamaR)

image

Use as an R package

The instanciation of an object of class Tama prepares a Tamagotchi and provides an R interface for it. The start method launches the real-time emulation. A single Tamagotchi can be alive on a given R session: instancing several Tama's will crash them. If you need several pets, run several R sessions.

guizmo = Tama()
guizmo$start()

The screen can be plotted via the display method. A custom background can be provided as a square-ish png, imported using png::readPNG.

guizmo$display()

Buttons (A, B and C) can be controlled using the click method. The delay argument tells how long the click should last:

guizmo$click("B")
Sys.sleep(3)
guizmo$click(c("A","C"),delay=2)

The state can be saved anytime using the corresponding method:

guizmo$save("myTama.txt")

However, you cannot load a state into a running Tama (the result may be glitched). Stop the emulation first using stop:

guizmo$stop()
guizmo$load("myTama.txt")
guizmo$start()

Finally, you can launch the shiny app from a running Tamagotchi using the go function.

go(guizmo, port = 1996)

The app is now available locally at http://127.0.0.1:1996/

Web deployment

Now that the app is available at port 1996, it may be deployed online. The server will be assumed to be a linux computer behind a router with a fixed public IP.

First of all, you need the public IP of your network and the private IP of your server. The public IP can be accessed from one of the many benevolent website, for instance this one. The private IP can be accessed with the command:

hostname -I

Router

The router configuration depends on the internet supplier. The router configuration page may for instance be reached from within the network at http://<public ip>:80. Because port 80 might be in competition with other resources, for instance the internet supplier configuration page, we will set up the application to listen to port 8000, which is less commonly used.

The router should be parameterized as such:

  • port 8000 should be open to TCP ;

  • port 8000 should redirect to your linux server, identified with its private IP.

Firewall

Using a firewall is a first security step for a web server. For instance, ufw does the job and is easy to use.

sudo apt install ufw
sudo ufw enable
sudo systemctl enable ufw

Port 8000 should be open to TCP. After configuring the router it may be checked and it has to be restarted.

sudo ufw allow 8000/tcp
sudo ufw status
sudo systemctl restart ufw

Web server

A web server software is required to deploy the shiny app with its functionalities. For instance, nginx is a popular solution.

sudo apt install nginx
sudo systemctl enable nginx

A configuration file should be provided for the app. Place the following configuration in an app file in the /etc/nginx/sites-available/ folder:

server {
        listen 8000;
        server_name _;

        location / {
                proxy_pass http://localhost:1996;
                proxy_redirect http://localhost:1996/ $scheme://$http_host/;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_read_timeout 20d;
                proxy_buffering off;
        }
}

Create a symlink in the /etc/nginx/sites-enabled/ folder, and restard nginx:

sudo ln -s /etc/nginx/sites-available/app /etc/nginx/sites-enabled/app
sudo systemctl restart nginx

Connection

The app is now available world-wide at http://<public ip>:8000

It can be played from a smartphone. A shortcut to the webpage may be added to the home screen.

The Tamagotchi runs backend, so it remains alive when the user disconnects.

Use as a web app

Passwords

At first connection, the app requires the set-up of an administrator password. This password allows reaching the administrator board, from which the game can be parameterized. The administrator must define an user password. The user password cannot be null and should be different from the administrator password. The user password may be changed from the administrator board, whereas the administrator password cannot be changed further. At each future connection, it is possible to connect either with the administrator password to reach the administrator board ; either with the user password to play the game.

pwd

For optimal security, provide strong passwords. At each log in, a 2 seconds delay is observed to hamper brute force cracking attempts. Tamagotchi has not been designed as a multi-player game. Several users attempting to interact simultaneously with the toy will not work well.

Administration

The following settings are available from the administrator board:

  • Stop or resume the emulation ;

  • Go back to the log-in screen ;

  • User settings:

    • Set or modify the user password ;

    • Enable the use of the automatic care feature.

  • Play as admin (the game must be running):

    • Click A+C buttons simultaneously to turn the sound on or off, or to set up the clock.
  • Aesthetics (the game must be stopped):

    • Change the background for a light, square png ;

    • Switch the sprites to the P2 ones ;

    • Dump the ROM or load a new, customized one ;

    • Reset all aesthetics.

  • Game state (the game must be stopped):

    • Save the game or load a previously saved one ;

    • Reset the game state (as the back button from the original toy).

Original gameplay

The original gameplay is available when the user is connected using the user password.

The 3 buttons (left, middle, right) are mapped as for the original toy.

game

The jungle background comes from this collection. It has been cropped to a square, resized to 500*500px, converted to png, and lighten to improve contrasts. Finally, it has been set as background from the administrator board.

Automatic care

The shiny app also provides the option to automatically care for the hosted pet, a feature inspired from tamatrix.

When checking the "automatic care" option, it is possible to choose whether the creature should also be disciplined. Indeed, discipline strongly impact the evolutionary pathway of Tamagotchis.

care

The automatic care process works on the frontend, so it will not support being launched from several instances. It also requires that a device (or the server itself) keeps a shiny session active.

P2 sprites

Using TamaTool ROM editor, a mod of the original P1 ROM has been provided in order to use the P2 sprites.

p2

This is not a perfect emulation of P2: some animations vary slightly, and the "number game" is not available. The P2 secret character is not available neither.

Secret Character

A new but familiar secret character has snuck in the game. Will you find out who this is ?

Several releases of P1 exist: an older one (1996) and a replica re-release. According to the fandom, replicas evolve from Maskutchi independently on the discipline level, as opposed to the original 1996 version that requires a strict 0 discipline to unlock the secret character. Testing this property led to the conclusion that the circulating ROM would be the 1996 version, not the latter replica.

Notes on the C++ structure

TamaLIB has been implemented on Arduino, with a bit of re-writing. The Arduino version is the starting point for tamaR C++ module, including the ROM conversion step. TamaLIB was converted from C to C++ in order to ensure consistency with R object-orientation. However, because Rcpp dependencies management was not trivial, I gathered all TamaLIB code into a monolithic tamalib.cpp program.

TamaLIB was adapted with attention to its platform agnosticity, so tamaR should run on any OS/architecture that supports R. So far, the package tamaR has been succesfully built, installed and locally tested on linux/amd64 and windows/amd64.

Sound

The buzzer frequency is properly fetched with the GetFreq method.

Sound implementation to the web app is being investigated in a feature branch, however, the current approach raises performance issues.

Disclaimer

Enabling the web server exposes your server to the internet. Cares have been taken to make the web server application as safe as possible; however, by utilizing this functionality, you acknowledge and agree that you are solely responsible for configuring and securing your web server. The developer and associated parties are not liable for any damages, losses, or security breaches resulting from using the web server application or from using any information found on this page.

License

This work is licensed under Attribution-NonCommercial 4.0 International.

All graphical resources come from the extraordinarily rich Tamagotchi fandom.

About

An R app to play the original Tamagotchi online

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages