From 3880ab054bd838577afa1936c021ec4718335cf1 Mon Sep 17 00:00:00 2001 From: pnjiwsfv3 <3147226574@qq.com> Date: Sat, 1 Jun 2024 23:25:36 +0800 Subject: [PATCH] ADD file via upload --- cloud.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 cloud.py diff --git a/cloud.py b/cloud.py new file mode 100644 index 0000000..a6111c8 --- /dev/null +++ b/cloud.py @@ -0,0 +1,20 @@ +from settings import * +import random + +class Cloud: + def __init__(self, game_speed): + # 随机设定云的x,y坐标 + self.x = SCREEN_WIDTH + random.randint(200, 500) # 云先出现在游戏画面外,然后飞入 + self.y = random.randint(50, 200) # 云的y坐标,即离上部分区域的距离 + self.image = CLOUD # image 保存云的图片 + self.width = self.image.get_width() + self.game_speed = game_speed + + def update(self): + self.x -= self.game_speed + if self.x < -self.width: # 当云从左边出界后又从右边出来 + self.x = SCREEN_WIDTH + random.randint(200, 500) + self.y = random.randint(50, 200) + + def draw(self, SCREEN): + SCREEN.blit(self.image, (self.x, self.y)) \ No newline at end of file