示例#1
0
文件: ship.py 项目: T1GIT/SpaceBattle
 def update_texture(self):
     normal = Img.get_ship(False)
     fire = Img.get_ship(True)
     w0, h0 = normal.get_size()
     scale = Conf.Ship.SIZE / max((w0, h0))
     w1, h1 = map(lambda x: round(x * scale), [w0, h0])
     self.texture_num = Conf.Image.SHIP
     self.texture_normal = pg.transform.scale(normal, (w1, h1))
     self.texture_fire = pg.transform.scale(fire, (w1, h1))
示例#2
0
 def update_texture(self):
     raw_image = Img.get_rocket()
     w0, h0 = raw_image.get_size()
     scale = Conf.Rocket.SIZE / h0
     w1, h1 = map(lambda x: round(x * scale), [w0, h0])
     self.texture = pg.transform.scale(raw_image, (w1, h1))
     self.image = self.texture
示例#3
0
文件: ship.py 项目: T1GIT/SpaceBattle
 def __init__(self):
     super().__init__()
     # Texture wearing
     normal = Img.get_ship(False)
     fire = Img.get_ship(True)
     w0, h0 = normal.get_size()
     scale = Conf.Ship.SIZE / max((w0, h0))
     w1, h1 = map(lambda x: round(x * scale), [w0, h0])
     self.texture_num = Conf.Image.SHIP
     self.texture_normal = pg.transform.scale(normal, (w1, h1))
     self.texture_fire = pg.transform.scale(fire, (w1, h1))
     # Variables
     self.half_width = self.texture_normal.get_width() / 2
     self.half_height = self.texture_normal.get_height() / 2
     self.image = self.texture_normal
     self.speed_x, self.speed_y = 0, 0
     self.pos_x, self.pos_y = 0, 0
     self.angle = 90
     self.with_fire = False
示例#4
0
 def __init__(self, name: str, size: int = Conf.Animation.DEFAULT_SIZE):
     super().__init__()
     # Texture wearing
     raw_frames = Img.get_animation(name)
     w0, h0 = raw_frames[0].get_size()
     scale = size / max(w0, h0)
     w1, h1 = map(lambda x: round(x * scale), [w0, h0])
     self.frames = []
     for frame in raw_frames:
         self.frames.append(pg.transform.scale(frame, (w1, h1)))
     self.frames = deque(self.frames)
     self.image = self.frames.popleft()
     self.skipped = 1
示例#5
0
文件: menu.py 项目: T1GIT/SpaceBattle
    def create_menu(self, settings, about):
        """
        Create menus: Main. Responsible for setting up the main menu.
        A picture is selected for the background. Customizable theme, colors, font size, etc.
        A name entry line is added, a play button that redirects to the start function of the game,
        similarly with the about and exit buttons.
        """

        # Theme
        theme = pygame_menu.themes.Theme(
            selection_color=Conf.Menu.THEME_COLOR,
            title_bar_style=pygame_menu.widgets.
            MENUBAR_STYLE_NONE,  # Separating header and body
            title_offset=(Conf.Menu.Title.X_OFFSET,
                          Conf.Menu.Title.Y_OFFSET - 20),
            title_font=self.title_font,
            title_font_color=(255, 255, 255),
            title_font_size=Conf.Menu.Title.SIZE,
            background_color=Img.get_menu(),
            widget_font=self.widget_font,
            widget_font_color=(255, 255, 255),
            widget_font_size=40,
            widget_margin=(0, 40),
            menubar_close_button=False)

        # Initialisation
        menu = pygame_menu.Menu(
            Conf.Window.HEIGHT,
            Conf.Window.WIDTH,
            title='SPACE BATTLE',
            theme=theme,
            onclose=lambda: pygame_menu.events.DISABLE_CLOSE,
            mouse_motion_selection=True)

        # Layout
        menu.add_button('     Play     ',
                        self.window.start,
                        font_size=60,
                        margin=(0, 50))
        menu.add_button('   Settings   ', settings)
        menu.add_button('     Info     ', about)
        menu.add_button('     Exit     ', lambda: exit(69))

        # Sound
        self.engine.set_sound(pygame_menu.sound.SOUND_TYPE_CLICK_MOUSE,
                              Snd.click(),
                              volume=Snd.get_volume(Conf.Sound.Volume.SFX))
        menu.set_sound(self.engine, recursive=True)

        return menu
示例#6
0
 def __init__(self):
     super().__init__()
     self.points: deque[pg.sprite.Sprite] = deque()
     self.image = pg.surface.Surface((0, 0))
     self.rect = pg.rect.Rect(0, 0, 0, 0)
     raw_image = Img.get_life()
     self.texture = pg.transform.scale(raw_image,
                                       [Conf.Overlay.Health.SIZE] * 2)
     for i in range(Conf.Rules.LIFES):
         point = pg.sprite.Sprite()
         point.image = self.texture
         point.image.set_alpha(Conf.Overlay.OPACITY)
         self.points.append(point)
         Group.ALL.add(point)
示例#7
0
 def __init__(self):
     super().__init__()
     # Settings
     self.angle = 0
     self.start_x, self.start_y = 0, 0
     self.a_x, self.a_y = 0, 0
     # Init sprite
     pg.sprite.Sprite.__init__(self)
     raw_image = Img.get_rocket()
     w0, h0 = raw_image.get_size()
     scale = Conf.Rocket.SIZE / h0
     w1, h1 = map(lambda x: round(x * scale), [w0, h0])
     self.texture_num = Conf.Image.ROCKET
     self.texture = pg.transform.scale(raw_image, (w1, h1))
     self.image = self.texture
     self.start_x, self.start_y = 0, 0
     self.speed_x, self.speed_y = 0, 0
     self.pos_x, self.pos_y = 0, 0
     self.angle = 0
示例#8
0
 def __init__(self):
     super().__init__()
     # Settings
     self.speed_x = rnd.uniform(-Conf.Piece.MAX_SPEED,
                                Conf.Piece.MAX_SPEED) * Conf.System.SCALE
     self.speed_y = rnd.uniform(-Conf.Piece.MAX_SPEED,
                                Conf.Piece.MAX_SPEED) * Conf.System.SCALE
     self.pos_x, self.pos_y = 0, 0
     # Initialising sprite
     pg.sprite.Sprite.__init__(self)
     raw_image = Img.get_pieces()
     self.amount = rnd.randint(0, len(raw_image) - 1)
     w0, h0 = raw_image[self.amount].get_size()
     scale = rnd.randint(Conf.Piece.MIN_SIZE, Conf.Piece.MAX_SIZE) / max(
         w0, h0)
     w1, h1 = map(lambda x: round(x * scale), [w0, h0])
     self.texture = pg.transform.scale(raw_image[self.amount], (w1, h1))
     self.texture.set_alpha(
         rnd.randint(Conf.Piece.MIN_OPACITY, Conf.Piece.MAX_OPACITY))
     self.image = pg.transform.rotate(self.texture, rnd.randint(0, 360))
示例#9
0
 def __init__(self, window):
     # Environment
     self.window = window
     self.running = False
     self.game_over = False
     self.clock = pg.time.Clock()
     # Components
     self.comp_overlay = Overlay(self)
     # Sprites
     self.ship = None
     # Timers
     self.meteor_timer = 0
     self.rocket_timer = 0
     self.losing_timer = 0
     # Background
     bg = Img.get_background()
     w0, h0 = bg.get_size()
     scale = max((Conf.Window.WIDTH / w0, Conf.Window.HEIGHT / h0))
     w1, h1 = map(lambda x: round(x * scale), [w0, h0])
     self.image = pg.transform.scale(bg, (w1, h1))
示例#10
0
 def __init__(self):
     super().__init__()
     # Variables
     cnf = Conf.Meteor
     self.speed_x = rnd.uniform(-cnf.MAX_SPEED,
                                cnf.MAX_SPEED) * Conf.System.SCALE
     self.speed_y = rnd.uniform(-cnf.MAX_SPEED,
                                cnf.MAX_SPEED) * Conf.System.SCALE
     self.angle_speed = rnd.uniform(
         -cnf.MAX_ROTATE_SPEED, cnf.MAX_ROTATE_SPEED) * Conf.System.SCALE
     self.pos_x, self.pos_y = 0, 0
     # Initialising
     pg.sprite.Sprite.__init__(self)
     raw_image = Img.get_meteors()
     self.amount = rnd.randint(0, len(raw_image) - 1)
     size = rnd.randint(cnf.MIN_SIZE, cnf.MAX_SIZE)
     self.lifes = ((size - cnf.MIN_SIZE) //
                   ((cnf.MAX_SIZE - cnf.MIN_SIZE) / cnf.MAX_LIFES))
     scale = size / max(raw_image[self.amount].get_size())
     w1, h1 = map(lambda x: round(x * scale),
                  raw_image[self.amount].get_size())
     self.texture = pg.transform.scale(raw_image[self.amount], (w1, h1))
     self.image = self.texture
     self.angle = 0
示例#11
0
 def show(self):
     Thread(target=lambda: (pg.time.delay(100), Img.cache())).start()
     Snd.bg_menu()
     self.comp_menu.open()