Compare commits

...

2 Commits

Author SHA1 Message Date
Frank
661d061bf5 merge local and remote repo 2026-06-17 14:46:36 +08:00
Frank
748102a59c fix and add t_box bug 2026-06-17 14:41:53 +08:00
3 changed files with 45 additions and 0 deletions

View File

@@ -1,7 +1,11 @@
# Ping Pong Game # Ping Pong Game
This ping_pong game made by frank This ping_pong game made by frank
<<<<<<< HEAD
![Game Cover](https://api.yppp.net/pc.php)
=======
![Game Cover](https://cocktailhourentertainment.com/wp-content/uploads/2022/07/atari-pong-arcade-1920x1080-3.jpg) ![Game Cover](https://cocktailhourentertainment.com/wp-content/uploads/2022/07/atari-pong-arcade-1920x1080-3.jpg)
>>>>>>> 2d13872febf768c59aec106182ed404dbbf57614
## Setup & Run ## Setup & Run
Install the required dependency and start the game with the following commands: Install the required dependency and start the game with the following commands:

BIN
images/t_box.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

41
main.py
View File

@@ -1,4 +1,12 @@
import pgzrun import pgzrun
<<<<<<< HEAD
import random
#随机数生成
random_intX = random.randint(235, 1685)
random_intY = random.randint(235, 845)
=======
>>>>>>> 2d13872febf768c59aec106182ed404dbbf57614
music.play('bgm') music.play('bgm')
# 窗口参数 # 窗口参数
@@ -16,6 +24,14 @@ paddle2 = Actor("2")
paddle2.x = WIDTH - 80 paddle2.x = WIDTH - 80
paddle2.y = HEIGHT / 2 paddle2.y = HEIGHT / 2
<<<<<<< HEAD
#box生成
tbox = Actor("t_box")
tbox.x = random_intX
tbox.y = HEIGHT / 2
=======
>>>>>>> 2d13872febf768c59aec106182ed404dbbf57614
# 乒乓球 # 乒乓球
ball = Actor("ball") ball = Actor("ball")
ball.pos = (WIDTH//2, HEIGHT//2) ball.pos = (WIDTH//2, HEIGHT//2)
@@ -39,6 +55,10 @@ def draw():
paddle1.draw() paddle1.draw()
paddle2.draw() paddle2.draw()
ball.draw() ball.draw()
<<<<<<< HEAD
tbox.draw()
=======
>>>>>>> 2d13872febf768c59aec106182ed404dbbf57614
# 游戏结束提示 # 游戏结束提示
if game_state == "gameover": if game_state == "gameover":
@@ -74,6 +94,27 @@ def update():
if ball.colliderect(paddle1) or ball.colliderect(paddle2): if ball.colliderect(paddle1) or ball.colliderect(paddle2):
ball_speed_x *= -1 ball_speed_x *= -1
sounds.bump.play() sounds.bump.play()
<<<<<<< HEAD
#方块实现
if ball.colliderect(tbox):
sounds.bump.play()
# 判断撞方块左侧/右侧翻转X速度
if ball.centerx < tbox.x:
ball_speed_x = -abs(ball_speed_x) - 1
else:
ball_speed_x = abs(ball_speed_x) + 1
# 判断撞方块上侧/下侧翻转Y速度
if ball.centery < tbox.y:
ball_speed_y = -abs(ball_speed_y)
else:
ball_speed_y = abs(ball_speed_y)
# 重新生成方块坐标(现在能修改全局变量)
random_intX = random.randint(235, 1685)
random_intY = random.randint(235, 845)
tbox.x = random_intX
tbox.y = random_intY
=======
>>>>>>> 2d13872febf768c59aec106182ed404dbbf57614
# 出左右边界直接失败 # 出左右边界直接失败
if ball.left <= 0: if ball.left <= 0: