You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
1.0 KiB
29 lines
1.0 KiB
from typing import Any
|
|
|
|
import pygame
|
|
from pygame.sprite import Sprite
|
|
|
|
|
|
class BackGround(Sprite):
|
|
def __init__(self, ai_game):
|
|
super().__init__()
|
|
# 屏幕设置
|
|
self.screen = ai_game.screen
|
|
self.screen_rect = ai_game.screen.get_rect()
|
|
self.settings = ai_game.settings
|
|
|
|
# 获取背景
|
|
self.image = pygame.image.load("resource/image/space-2.png").convert()
|
|
self.image = pygame.transform.scale(self.image, (self.settings.screen_width, self.settings.screen_height))
|
|
self.rect = self.image.get_rect()
|
|
self.rect.bottom = self.screen_rect.bottom
|
|
self.rect_height = self.rect.height
|
|
# 背景移动设置
|
|
self.ready_to_mov = 0
|
|
|
|
def update(self, *args: Any, **kwargs: Any) -> None:
|
|
if self.ready_to_mov == 0:
|
|
self.rect.bottom += self.settings.bg_speed
|
|
if self.rect.top >= self.screen_rect.bottom:
|
|
self.rect.bottom = self.screen_rect.bottom - self.rect_height
|