利用pygame实现大鱼吃小鱼游戏
游戏运行界面
初始界面
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/2eeef7f8f0dcc080d06ea87845ccdf2d.png)
吃东西加分界面
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/75ea0fd3a11c7d55431c59c5cee55bfe.png)
游戏结束界面
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c71da18cf0c69f8d5658923c9faaa96c.png)
代码示例
初始化创建游戏角色
from load import *
import random
bg_w=bg_img.get_rect().width
bg_h=bg_img.get_rect().height
def get_xy():
x=xy_img.get_rect().width
y=xy_img.get_rect().height
xy={
'x':-x,
'y':random.randint(0,bg_h-y),
'image':xy_img,
'w':x,
'h':y,
'step':1
}
return xy
def get_dy():
x=dy_img.get_rect().width
y=dy_img.get_rect().height
dy={
'x':bg_w,
'y':random.randint(0,bg_h-y),
'image':dy_img,
'w':x,
'h':y,
'step':1
}
return dy
加载所需素材
import pygame
bg_img=pygame.image.load('imageF/Image 112.jpg')
sh_img=pygame.image