zjowowen commited on
Commit
3393c87
1 Parent(s): f870505

init project

Browse files
Files changed (4) hide show
  1. Dockerfile +58 -0
  2. README.md +2 -0
  3. pygame_demo/main.py +42 -0
  4. run.sh +3 -0
Dockerfile ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM pytorch/pytorch:2.0.0-cuda11.7-cudnn8-devel as base
2
+
3
+ ENV DEBIAN_FRONTEND=noninteractive
4
+ ENV LANG en_US.UTF-8
5
+ ENV LANGUAGE en_US:UTF-8
6
+ ENV LC_ALL en_US.UTF-8
7
+
8
+ RUN apt update -y \
9
+ && apt install libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 libxrender-dev swig curl git vim gcc \g++ make wget locales dnsutils zip unzip cmake nginx -y \
10
+ && curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \
11
+ && apt-get install -y nodejs \
12
+ && npm install -g npm@9.6.5 \
13
+ && npm install -g create-react-app \
14
+ && npm install typescript -g \
15
+ && npm install -g vite \
16
+ && apt clean \
17
+ && rm -rf /var/cache/apt/* \
18
+ && sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen \
19
+ && locale-gen
20
+
21
+ # ADD nginx.conf /etc/nginx/nginx.conf
22
+
23
+ # Set up a new user named "user" with user ID 1000
24
+ RUN useradd -m -u 1000 user
25
+
26
+ RUN mkdir -p /var/cache/nginx \
27
+ /var/log/nginx \
28
+ /var/lib/nginx
29
+ RUN touch /var/run/nginx.pid
30
+ RUN touch /run/nginx.pid
31
+
32
+ RUN chown -R user:user /var/cache/nginx \
33
+ /var/log/nginx \
34
+ /var/lib/nginx \
35
+ /var/run/nginx.pid \
36
+ /run/nginx.pid
37
+
38
+ # Switch to the "user" user
39
+ USER user
40
+
41
+ # Set home to the user's home directory
42
+ ENV HOME=/home/user \
43
+ PATH=/home/user/.local/bin:$PATH
44
+
45
+ WORKDIR $HOME/workspace
46
+
47
+ ADD --chown=user pygame_demo pygame_demo
48
+ ADD --chown=user run.sh run.sh
49
+
50
+ RUN python3 -m pip install --upgrade pip \
51
+ && python3 -m pip install --no-cache-dir pygbag
52
+
53
+ RUN cd $HOME/workspace \
54
+ && chmod 777 run.sh
55
+
56
+ EXPOSE 8088
57
+
58
+ CMD sh ./run.sh
README.md CHANGED
@@ -5,6 +5,8 @@ colorFrom: purple
5
  colorTo: red
6
  sdk: docker
7
  pinned: false
 
 
8
  license: apache-2.0
9
  ---
10
 
 
5
  colorTo: red
6
  sdk: docker
7
  pinned: false
8
+ python_version: 3.10
9
+ app_port: 8088
10
  license: apache-2.0
11
  ---
12
 
pygame_demo/main.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import sys module
2
+ import pygame
3
+ import sys
4
+ import asyncio
5
+
6
+
7
+ pygame.init()
8
+ clock = pygame.time.Clock()
9
+ screen = pygame.display.set_mode([600, 500])
10
+ base_font = pygame.font.Font(None, 32)
11
+
12
+ player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)
13
+
14
+
15
+ async def main():
16
+ dt = 0
17
+
18
+ while True:
19
+ for event in pygame.event.get():
20
+ if event.type == pygame.QUIT:
21
+ pygame.quit()
22
+ sys.exit()
23
+
24
+ screen.fill("white")
25
+
26
+ pygame.draw.circle(screen, "blue", player_pos, 40)
27
+ keys = pygame.key.get_pressed()
28
+ if keys[pygame.K_w]:
29
+ player_pos.y -= 300 * dt
30
+ if keys[pygame.K_s]:
31
+ player_pos.y += 300 * dt
32
+ if keys[pygame.K_a]:
33
+ player_pos.x -= 300 * dt
34
+ if keys[pygame.K_d]:
35
+ player_pos.x += 300 * dt
36
+
37
+ pygame.display.flip()
38
+ # clock.tick(60)
39
+ dt = clock.tick(60) / 1000
40
+ await asyncio.sleep(0)
41
+
42
+ asyncio.run(main())
run.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ service nginx start
2
+ cd /home/user/workspace && nohup pygbag pygame_demo &
3
+ cd /home/user/workspace/pygame_demo/build/web/ && python -m http.server 8088