Signed-off-by: xu <xyjj0819@outlook.com>

This commit is contained in:
xu 2024-07-13 09:55:55 +08:00
commit 63eba9d183
7 changed files with 139 additions and 0 deletions

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.10" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/绪鸣远.iml" filepath="$PROJECT_DIR$/.idea/绪鸣远.iml" />
</modules>
</component>
</project>

8
.idea/绪鸣远.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

73
240615 移动控制.py Normal file
View File

@ -0,0 +1,73 @@
import pygame,sys
pygame.init()
window_size = (260,300)
sc = pygame.display.set_mode(window_size)
pygame.display.set_caption('反弹的小球')
ball_xy = [110,175]
ball_r = 10
ball_speed = [3,3]
box = pygame.Rect(115,290,50,15)
zk_lst = []
zk_x = 10
zk_y = 10
for i in range(5):
for j in range(5):
zk_rect = pygame.Rect(zk_x,zk_y,40,20)
zk_lst.append(zk_rect)
zk_x += 50
zk_x = 10
zk_y += 30
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
sc.fill('white')
ball = pygame.draw.circle(sc, 'black', ball_xy, ball_r)
if ball_xy[0] - ball_r < 0 or ball_xy[0] + ball_r > window_size[0]:
ball_speed[0] = -ball_speed[0]
if ball_xy[1] - ball_r < 0 or ball_xy[1] + ball_r > window_size[1]:
ball_speed[1] = -ball_speed[1]
if ball_xy[1] + ball_r > 300 and not ball.colliderect(box):
running = False
if ball.colliderect(box):
ball_speed[1] = -ball_speed[1]
for i in zk_lst:
if ball.colliderect(i):
zk_lst.remove(i)
if zk_lst == []:
running = False
ball_xy[0] += ball_speed[0]
ball_xy[1] += ball_speed[1]
pygame.draw.rect(sc, (0, 0, 0), rect=box)
for i in zk_lst:
pygame.draw.rect(sc, 'blue', rect=i)
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
if box.x <= 0:
continue
else:
box.x += -2
if keys[pygame.K_RIGHT]:
if box.x >= 260:
continue
else:
box.x += 2
pygame.display.flip()
pygame.time.Clock().tick(35)
pygame.quit()
sys.exit()

34
240622 反弹的小球.py Normal file
View File

@ -0,0 +1,34 @@
import pygame,sys
pygame.init()
window_size = (800,600)
sc = pygame.display.set_mode(window_size)
pygame.display.set_caption('反弹的小球')
ball_xy = [400,300]
ball_r = 20
ball_speed = [5,5]
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
ball_xy[0] += ball_speed[0]
ball_xy[1] += ball_speed[1]
if ball_xy[0] - ball_r < 0 or ball_xy[0] + ball_r > window_size[0]:
ball_speed[0] = -ball_speed[0]
if ball_xy[1] - ball_r < 0 or ball_xy[1] + ball_r > window_size[1]:
ball_speed[1] = -ball_speed[1]
sc.fill('white')
pygame.draw.circle(sc,'black',ball_xy,ball_r)
pygame.display.flip()
pygame.time.Clock().tick(60)
pygame.quit()
sys.exit()