commit 2466f7ae0884e9bccd8087d143457c9f282fa6f3 Author: Frank <123@emial.com> Date: Mon Jun 15 09:39:21 2026 +0800 sounds diff --git a/images/1.png b/images/1.png new file mode 100644 index 0000000..ffd3348 Binary files /dev/null and b/images/1.png differ diff --git a/images/2.png b/images/2.png new file mode 100644 index 0000000..7c23654 Binary files /dev/null and b/images/2.png differ diff --git a/images/ball.png b/images/ball.png new file mode 100644 index 0000000..6893be3 Binary files /dev/null and b/images/ball.png differ diff --git a/images/bg.png b/images/bg.png new file mode 100644 index 0000000..37f9e54 Binary files /dev/null and b/images/bg.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..4af7662 --- /dev/null +++ b/index.html @@ -0,0 +1,12 @@ + + + + + + + +
+
+ + + diff --git a/main.py b/main.py new file mode 100644 index 0000000..5ac13a4 --- /dev/null +++ b/main.py @@ -0,0 +1,97 @@ +import pgzrun + +music.play('bgm') +# 窗口参数 +WIDTH = 1920 +HEIGHT = 1080 +TITLE = "Ping_Pang" + +# 左右球拍 +paddle1 = Actor("1") +paddle1.x = 80 +paddle1.y = HEIGHT / 2 +paddle_speed = 8 + +paddle2 = Actor("2") +paddle2.x = WIDTH - 80 +paddle2.y = HEIGHT / 2 + +# 乒乓球 +ball = Actor("ball") +ball.pos = (WIDTH//2, HEIGHT//2) +ball_speed_x = 7 +ball_speed_y = 7 + +# 游戏状态: playing / gameover +game_state = "playing" +lose_text = "" + +# 球拍上下限位 +half_h = paddle1.height / 2 +top = half_h +bottom = HEIGHT - half_h + +bg = Actor("bg") + +def draw(): + screen.clear() + bg.draw() + paddle1.draw() + paddle2.draw() + ball.draw() + + # 游戏结束提示 + if game_state == "gameover": + screen.draw.text(lose_text, center=(WIDTH//2, HEIGHT//2), fontsize=80, color="red") + screen.draw.text("click space to restar", center=(WIDTH//2, HEIGHT//2+80), fontsize=40, color="white") + +def update(): + global ball_speed_x, ball_speed_y, game_state, lose_text + if game_state != "playing": + return + + # 左拍 W S + if keyboard.w and paddle1.y>top: + paddle1.y -= paddle_speed + if keyboard.s and paddle1.ytop: + paddle2.y -= paddle_speed + if keyboard.down and paddle2.y= HEIGHT: + ball_speed_y *= -1 + sounds.bump.play() + + # 球拍碰撞反弹 + if ball.colliderect(paddle1) or ball.colliderect(paddle2): + ball_speed_x *= -1 + sounds.bump.play() + + # 出左右边界直接失败 + if ball.left <= 0: + game_state = "gameover" + lose_text = "Himeko win!" + sounds.zhanbai.play() + if ball.right >= WIDTH: + game_state = "gameover" + lose_text = "Theresa Apocalypse win!" + sounds.zhanbai.play() + +# 空格重新开局 +def on_key_down(key): + global game_state, ball_speed_x, ball_speed_y + if key == keys.SPACE and game_state == "gameover": + game_state = "playing" + ball.pos = (WIDTH//2, HEIGHT//2) + ball_speed_x = 7 + ball_speed_y = 7 + +pgzrun.go() diff --git a/music/bgm.mp3 b/music/bgm.mp3 new file mode 100644 index 0000000..d402fd6 Binary files /dev/null and b/music/bgm.mp3 differ diff --git a/sounds/bump.wav b/sounds/bump.wav new file mode 100644 index 0000000..d43298c Binary files /dev/null and b/sounds/bump.wav differ diff --git a/sounds/zhanbai.wav b/sounds/zhanbai.wav new file mode 100644 index 0000000..2d305f9 Binary files /dev/null and b/sounds/zhanbai.wav differ