T-Rex Chrome Offline Game X BCIs

One of the greatest games ever made… with a twist.

Karina Kainth
4 min readDec 17, 2022

I recently had an electrifying experience when I used my mind to control a basic block game. Every time I blinked, a block of random size and colour would appear on the screen (click here to check it out). However, the excitement was short-lived, so I took it up a notch by using my brain to control the beloved Chrome T-Rex Running Game. Here is how I did it.

Hardware/Software Used

Step 1: Setting Up the Muse 2 &Outputting an LSL

If you don’t want to go into the details of my previous article on how I made the block game, here’s a quick summary of the steps I took to set up the Muse headband and start a live stream. I’ll give you an overview of what needs to be done so you can get started right away!

To create an innovative mind-controlled video game, I had to acquire a device that could provide a real-time measure of my brain activity — thus, I got myself a Muse 2 headband.

I downloaded the BlueMuse app, unzipped the file and followed the installation instructions from the GitHub page.

Finally, I opened the app and connected my Muse 2 to get live EEG data from all 5 sensors. In short, I was able to synchronize live streaming data with another device!

Step 2: Receiving Numerical EEG Data In Python

The first thing I did was install pyautogui through the following command:

pip instal pyautogui

I needed to turn raw data into numerical data to detect patterns and changes in the brain (once again, I go through this process step-by-step in my last article, so this is a short summary of it). Immediately, I downloaded the neurofeedback.py file from the examples folder on the MuseLSL GitHub page. This file classified raw EEG data from the Muse 2 into delta, theta, alpha and beta frequencies. To make the program run, I also needed the utils.py file from the same folder for lower-level epoch and buffering functions. I copied the file and tweaked it to print only the delta waves coming from the left ear sensor on the headband (T9 sensor). After computing the band powers in the original program, I edited the code so that it only outputted delta, theta and alpha waves — no beta waves.

Step 3: Computing Neurofeedback Metrics

To accurately detect disruptions in my brain waves, I created a program that prints a live reading of my delta, alpha, and theta waves. When I remain focused and avoid blinking and clenching my jaw, the values stay consistently below 1. Consequently, I incorporated code to detect blinking, as the value rises above 1 when I do so.

if  band_powers[Band.Delta] > 1 and  band_powers[Band.Theta] > 1 and band_powers[Band.Alpha] > 1:
print("THIS IS WHERE I BLINKED. YOU CAN TELL BECAUSE THE DELTA,THETA & ALPHA VALUES INCREASED GREATER THAN 1")

The following output when I ran it:

Every time I blinked, it would print “this is where I blinked. You can tell because the delta, theta & alpha values increased greater than 1”

Step 4: Incorporating the Dino Game

I wrote a command to get the T-rex in the game to jump— tricking the interface into thinking the user pressed the space key (which is how the game was originally played). To do this, I added the following code under the ‘if’ statement above:

pyautogui.press('space')

Now, every time I blinked my eyes, the T-rex would jump. Here is what the final product looked like:

Every time I blinked, the T-rex jumped.

Clearly, I suck at video games. I got the hang of it around the third try… but in my defence, it takes a lot of concentration… literally. Creating this project was an incredibly enjoyable experience as I continue to explore and develop my BCI and Neuroscience research. Be sure to follow my Medium account for more of my projects!

Credit goes to Sabeeh Hassany for the idea and code.

--

--