File size: 1,572 Bytes
95d1b0c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import streamlit as st
import time

# Game settings
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
CAR_WIDTH = 50
CAR_HEIGHT = 100
CAR_COLOR = "red"
car_x = SCREEN_WIDTH // 2 - CAR_WIDTH // 2
car_y = SCREEN_HEIGHT - CAR_HEIGHT - 10

# Streamlit Interface
def streamlit_interface():
    st.title("Racing Game")
    
    st.write("Control the red car using arrow buttons.")
    
    # Create sliders for controlling the car
    move_left = st.button("Move Left")
    move_right = st.button("Move Right")
    
    # Simple car movement logic
    global car_x
    if move_left and car_x > 0:
        car_x -= 10
    if move_right and car_x < SCREEN_WIDTH - CAR_WIDTH:
        car_x += 10

    # Drawing the car as a rectangle
    st.markdown(
        f"""
        <style>
            .game-canvas {{
                width: {SCREEN_WIDTH}px;
                height: {SCREEN_HEIGHT}px;
                background-color: white;
                position: relative;
            }}
            .car {{
                width: {CAR_WIDTH}px;
                height: {CAR_HEIGHT}px;
                background-color: {CAR_COLOR};
                position: absolute;
                top: {car_y}px;
                left: {car_x}px;
            }}
        </style>
        <div class="game-canvas">
            <div class="car"></div>
        </div>
        """,
        unsafe_allow_html=True
    )

    st.write("Use the buttons to move the car.")

    time.sleep(0.1)  # Add a small delay for better interaction

# Run Streamlit interface
if __name__ == "__main__":
    streamlit_interface()