Compare commits
2 Commits
2d13872feb
...
661d061bf5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
661d061bf5 | ||
|
|
748102a59c |
@@ -1,7 +1,11 @@
|
||||
# Ping Pong Game
|
||||
This ping_pong game made by frank
|
||||
|
||||
<<<<<<< HEAD
|
||||

|
||||
=======
|
||||

|
||||
>>>>>>> 2d13872febf768c59aec106182ed404dbbf57614
|
||||
|
||||
## Setup & Run
|
||||
Install the required dependency and start the game with the following commands:
|
||||
|
||||
BIN
images/t_box.png
Normal file
BIN
images/t_box.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.6 KiB |
41
main.py
41
main.py
@@ -1,4 +1,12 @@
|
||||
import pgzrun
|
||||
<<<<<<< HEAD
|
||||
import random
|
||||
|
||||
#随机数生成
|
||||
random_intX = random.randint(235, 1685)
|
||||
random_intY = random.randint(235, 845)
|
||||
=======
|
||||
>>>>>>> 2d13872febf768c59aec106182ed404dbbf57614
|
||||
|
||||
music.play('bgm')
|
||||
# 窗口参数
|
||||
@@ -16,6 +24,14 @@ paddle2 = Actor("2")
|
||||
paddle2.x = WIDTH - 80
|
||||
paddle2.y = HEIGHT / 2
|
||||
|
||||
<<<<<<< HEAD
|
||||
#box生成
|
||||
tbox = Actor("t_box")
|
||||
tbox.x = random_intX
|
||||
tbox.y = HEIGHT / 2
|
||||
|
||||
=======
|
||||
>>>>>>> 2d13872febf768c59aec106182ed404dbbf57614
|
||||
# 乒乓球
|
||||
ball = Actor("ball")
|
||||
ball.pos = (WIDTH//2, HEIGHT//2)
|
||||
@@ -39,6 +55,10 @@ def draw():
|
||||
paddle1.draw()
|
||||
paddle2.draw()
|
||||
ball.draw()
|
||||
<<<<<<< HEAD
|
||||
tbox.draw()
|
||||
=======
|
||||
>>>>>>> 2d13872febf768c59aec106182ed404dbbf57614
|
||||
|
||||
# 游戏结束提示
|
||||
if game_state == "gameover":
|
||||
@@ -74,6 +94,27 @@ def update():
|
||||
if ball.colliderect(paddle1) or ball.colliderect(paddle2):
|
||||
ball_speed_x *= -1
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user