Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Meta Meta
Created July 28, 2024

Metaverse Mobility: Enhancing Accessibility for All

Transforming minimal movements into meaningful actions for metaverse accessibility

18
Metaverse Mobility: Enhancing Accessibility for All

Things used in this project

Hardware components

Seeed Studio XIAO ESP32S3 Sense
Seeed Studio XIAO ESP32S3 Sense
×1
nRF52840 Development Kit
Nordic Semiconductor nRF52840 Development Kit
×1
Blues Notecard (Cellular)
Blues Notecard (Cellular)
×1

Software apps and online services

Supercomputer

Story

Read more

Code

Code for the Unique Metaverse for Mobility Impaired People

Python
Translate small movements into large ones for the Metaverse
import pygame
import sys

# Constants
WIDTH, HEIGHT = 800, 600
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
BLUE = (0, 0, 255)
FPS = 30

# User data
users = {"admin": "password123"}

# Initialize Pygame
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Metaverse Mobility")
clock = pygame.time.Clock()

# Load assets
font = pygame.font.Font(None, 36)

# Authentication
def login():
    user_input = ""
    password_input = ""
    user_box = pygame.Rect(100, 100, 140, 32)
    password_box = pygame.Rect(100, 150, 140, 32)
    active_user = False
    active_password = False
    color_inactive = pygame.Color('lightskyblue3')
    color_active = pygame.Color('dodgerblue2')
    color_user = color_inactive
    color_password = color_inactive
    logged_in = False
    
    while not logged_in:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            if event.type == pygame.MOUSEBUTTONDOWN:
                if user_box.collidepoint(event.pos):
                    active_user = True
                    active_password = False
                elif password_box.collidepoint(event.pos):
                    active_password = True
                    active_user = False
                else:
                    active_user = False
                    active_password = False
                color_user = color_active if active_user else color_inactive
                color_password = color_active if active_password else color_inactive
            if event.type == pygame.KEYDOWN:
                if active_user:
                    if event.key == pygame.K_RETURN:
                        active_user = False
                        color_user = color_inactive
                    elif event.key == pygame.K_BACKSPACE:
                        user_input = user_input[:-1]
                    else:
                        user_input += event.unicode
                elif active_password:
                    if event.key == pygame.K_RETURN:
                        active_password = False
                        color_password = color_inactive
                    elif event.key == pygame.K_BACKSPACE:
                        password_input = password_input[:-1]
                    else:
                        password_input += event.unicode
        
        screen.fill((30, 30, 30))
        user_surface = font.render(user_input, True, WHITE)
        password_surface = font.render('*' * len(password_input), True, WHITE)
        screen.blit(user_surface, (user_box.x + 5, user_box.y + 5))
        screen.blit(password_surface, (password_box.x + 5, password_box.y + 5))
        pygame.draw.rect(screen, color_user, user_box, 2)
        pygame.draw.rect(screen, color_password, password_box, 2)
        
        pygame.display.flip()
        clock.tick(FPS)
        
        if not active_user and not active_password:
            if user_input in users and users[user_input] == password_input:
                logged_in = True
                print("Login successful!")
            else:
                user_input = ""
                password_input = ""
                print("Invalid credentials, try again.")
                
    return True

# Function to translate minimal movements into bigger actions
def amplify_movement(dx, dy, scale=5):
    return dx * scale, dy * scale

# VR Environment
def vr_environment():
    player_pos = [WIDTH // 2, HEIGHT // 2]
    base_move_step = 1
    scale_factor = 5  # Scale factor to amplify movements
    
    running = True
    while running:
        dx, dy = 0, 0
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
        
        keys = pygame.key.get_pressed()
        if keys[pygame.K_LEFT] or keys[pygame.K_a]:
            dx = -base_move_step
        if keys[pygame.K_RIGHT] or keys[pygame.K_d]:
            dx = base_move_step
        if keys[pygame.K_UP] or keys[pygame.K_w]:
            dy = -base_move_step
        if keys[pygame.K_DOWN] or keys[pygame.K_s]:
            dy = base_move_step
        
        # Amplify the movement
        dx, dy = amplify_movement(dx, dy, scale_factor)
        player_pos[0] += dx
        player_pos[1] += dy
        
        # Ensure player stays within bounds
        player_pos[0] = max(0, min(WIDTH, player_pos[0]))
        player_pos[1] = max(0, min(HEIGHT, player_pos[1]))
        
        screen.fill(BLACK)
        pygame.draw.circle(screen, BLUE, player_pos, 20)
        
        pygame.display.flip()
        clock.tick(FPS)

# Main function
def main():
    if login():
        vr_environment()
    pygame.quit()

if __name__ == "__main__":
    main()

Credits

Meta Meta

Meta Meta

1 project • 1 follower

Comments