This project introduces a rhythm-based piano game designed to support hand rehabilitation for stroke patients. By combining interactive gameplay with precise finger joint tracking, the system transforms traditional therapy into an engaging experience. The game uses a smart wearable device that monitors finger movement in real time, allowing patients to play virtual piano keys through rhythm-matching exercises. This approach leverages the therapeutic power of music and repetition to promote neuroplasticity and encourages consistent, meaningful movement. By gamifying the recovery process, this system not only improves motor function but also boosts motivation, helping patients take an active role in their rehabilitation journey.
Game Manager
Users interact with falling tiles using either mouse clicks or keyboard keys (Q, W, E, R). The GameManager class tracks the player's score and provides immediate audio-visual feedback based on correct or incorrect inputs. It references a SpawnManager to access and manage the current list of active tiles, checking whether the player hits the correct tile in sequence. When a user clicks on a tile or presses a key, the script determines whether it corresponds to the leading (first) tile in the queue. If correct, the score increases and a "correct" sound plays; if incorrect, the score decreases and a "wrong" sound plays. It also updates the on-screen score in real time using a TextMeshPro UI element. The script ensures player engagement by integrating real-time feedback, intuitive controls, and a simple but responsive input system that rewards accuracy and timing, all essential for a rehabilitation-focused game design.
Tile
This script defines the behavior of a falling tile in the game. Each tile has a tileSpeed variable that controls how fast it moves downward, creating a dynamic and time-sensitive challenge for the player. The Update() method is called every frame and moves the tile straight down using transform.Translate, simulating gravity or motion in rhythm games. The script also contains a columnNumber property, which represents the column that the tile belongs to (used to detect input from the corresponding keyboard key). The ColumnNumber is made public through a property to allow controlled access and modification by other scripts like the SpawnManager or GameManager. Overall, this script provides the essential movement and identification logic for the tiles, making it possible to track their position and match them with user inputs in real time.
Spawn Manager
The SpawnManager script handles the generation and management of falling tiles in a rhythm-based game. At the start, it locates four designated spawn points (spawnA, spawnB, spawnC, spawnD), each representing a unique column. Using a coroutine called RandomSpawnTile(), the script spawns a tile every second at a random column. Each tile is created from a predefined prefab, assigned a unique column number (0–3), and named sequentially using tileNumber. These tiles are tracked in a list called tiles, allowing the game to manage their order and ensure correct interactions during gameplay. To prevent clutter, each spawned tile is automatically destroyed after five seconds via the DespawnTile() coroutine. Additionally, the method GetFirstTileWithColumnNumber() helps identify the earliest tile in a given column, which is crucial for accurate scoring. Altogether, this script ensures consistent, randomized tile spawning while maintaining performance and supporting interaction logic.
Flex Sensor Connection Code