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.
101 lines
4.0 KiB
101 lines
4.0 KiB
3 years ago
|
import random
|
||
|
|
||
|
import pygame
|
||
|
|
||
|
|
||
|
class Settings: # 存储游戏中的所有设置
|
||
|
def __init__(self, ai_game):
|
||
|
# 预定的
|
||
|
# self.screen = pygame.display.set_mode((1024, 1024))
|
||
|
# 设置刷新率
|
||
|
self.clock = pygame.time.Clock()
|
||
|
self.clock_fps = 60
|
||
|
# 颜色设置
|
||
|
self.RED = (255, 0, 0)
|
||
|
self.BLACK = (0, 0, 0)
|
||
|
self.WHITE = (255, 255, 255)
|
||
|
self.YELLOW = (255, 255, 0)
|
||
|
# 屏幕设置
|
||
|
self.screen_width = 1024
|
||
|
self.screen_height = 1024
|
||
|
self.bg_color = (230, 230, 230)
|
||
|
|
||
|
# 飞船设置
|
||
|
self.target = pygame.sprite.Sprite
|
||
|
# 子弹设置
|
||
|
|
||
|
# 外星飞船
|
||
|
self.alien1_image = [pygame.image.load('resource/Enemies/enemyBlack' + str(i) + '.png') for i in range(1, 6)]
|
||
|
self.alien1_image1 = [pygame.image.load('resource/Enemies/enemyBlue' + str(i) + '.png') for i in range(1, 6)]
|
||
|
self.alien1_image2 = [pygame.image.load('resource/Enemies/enemyRed' + str(i) + '.png') for i in range(1, 6)]
|
||
|
self.alien1_image.extend(self.alien1_image1)
|
||
|
self.alien1_image.extend(self.alien1_image2)
|
||
|
# ufo飞船
|
||
|
self.alien2_image = [pygame.image.load("resource/Enemies/ufo" + str(i) + ".png") for i in range(1, 5)]
|
||
|
# Boss
|
||
|
self.alienBoss_images = [pygame.image.load("resource/UFO/alien" + str(i) + ".png") for i in range(1, 16)]
|
||
|
|
||
|
# 超强激光设置
|
||
|
self.light_images = [pygame.image.load("resource/light/light_glow_" + str(i) + ".png") for i in range(1, 11)]
|
||
|
# 陨石设置
|
||
|
self.rocks_images = [pygame.image.load('resource/Meteors/rock' + str(i) + '.png') for i in range(0, 10)]
|
||
|
# 背景设置
|
||
|
self.bg_speed = 1.0
|
||
|
# 爆炸设置
|
||
|
self.explosion_images = pygame.image.load('resource/Explosion/explosion 3.png')
|
||
|
self.explosion_images_rect = self.explosion_images.get_rect()
|
||
|
self.row = 8
|
||
|
self.columns = 8
|
||
|
self.frame_width = self.explosion_images_rect.width // self.columns
|
||
|
self.frame_height = self.explosion_images_rect.height // self.row
|
||
|
self.frame_image = None
|
||
|
self.frame_images = []
|
||
|
for frame in range(self.columns * self.row):
|
||
|
frame_x = (frame % self.columns) * self.frame_width
|
||
|
frame_y = (frame // self.columns) * self.frame_height
|
||
|
rect = pygame.Rect(frame_x, frame_y, self.frame_width, self.frame_height)
|
||
|
self.frame_image = self.explosion_images.subsurface(rect)
|
||
|
self.frame_images.append(self.frame_image)
|
||
|
|
||
|
# 道具设置
|
||
|
self.prop_images = {'shield': pygame.image.load("resource/Power-ups/shield_silver.png"),
|
||
|
'bolt': pygame.image.load("resource/Power-ups/bolt_gold.png")}
|
||
|
self.prop_images_list = list(self.prop_images.keys())
|
||
|
|
||
|
# -----------------精灵组---------------------
|
||
|
|
||
|
# 外星人精灵
|
||
|
self.aliens = pygame.sprite.Group()
|
||
|
|
||
|
# boss精灵
|
||
|
self.boss_aliens = pygame.sprite.Group()
|
||
|
|
||
|
# 飞船精灵
|
||
|
self.ships = pygame.sprite.Group()
|
||
|
|
||
|
# 子弹精灵
|
||
|
self.bullets = pygame.sprite.Group()
|
||
|
|
||
|
# 背景精灵
|
||
|
self.backgrounds = pygame.sprite.Group()
|
||
|
|
||
|
# 炸弹精灵
|
||
|
self.explodes = pygame.sprite.Group()
|
||
|
|
||
|
# 道具精灵
|
||
|
self.props = pygame.sprite.Group()
|
||
|
|
||
|
# 敌人子弹精灵
|
||
|
self.enemy_bullets = pygame.sprite.Group()
|
||
|
|
||
|
# boss子弹
|
||
|
self.boss_bullets = pygame.sprite.Group()
|
||
|
|
||
|
# def explode_load(self):
|
||
|
# for frame in range(self.columns * self.row):
|
||
|
# frame_x = (frame % self.columns) * self.frame_width
|
||
|
# frame_y = (frame // self.columns) * self.frame_height
|
||
|
# rect = pygame.Rect(frame_x, frame_y, self.frame_width, self.frame_height)
|
||
|
# self.frame_image = self.image.subsurface(rect)
|
||
|
# self.frame_images.append(self.frame_image)
|