Example #1
0
    def __init__(self):
        super().__init__()

        # embedded game
        self.gameState: GameState = makeState(99, 0, 2)
        self.gameState.paused = False
        self.gameController: GameController = GameController(self.gameState)
        self.paddleTarget: int = random.randint(GC_WALL_SIZE,
                                                GC_WORLD_WIDTH - GC_WALL_SIZE)

        # enable screenshake
        if GC_SCREENSHAKE:
            Graphics.camera.enable()

        beginCoords = 0.5, 0.72
        helpCoords = 0.25, 0.86
        highscoresCoords = 0.75, 0.86

        self.begin: bool = False

        self.buttons.append(
            Button(
                "exit",
                PosRect(GC_WORLD_WIDTH - GC_SMALL_BUTTON_SIZE, 0,
                        GC_SMALL_BUTTON_SIZE, GC_SMALL_BUTTON_SIZE),
                Assets.I_BTN_MAINMENU_EXIT, Assets.I_BTN_MAINMENU_EXIT_H))

        fullscreenImg = Assets.I_BTN_UNFULLSCREEN if Graphics.isFullscreen(
        ) else Assets.I_BTN_FULLSCREEN
        fullscreenImgH = Assets.I_BTN_UNFULLSCREEN_H if Graphics.isFullscreen(
        ) else Assets.I_BTN_FULLSCREEN_H
        self.buttons.append(
            Button(
                "fullscreen",
                PosRect(GC_WORLD_WIDTH - GC_SMALL_BUTTON_SIZE,
                        GC_WORLD_HEIGHT - GC_SMALL_BUTTON_SIZE,
                        GC_SMALL_BUTTON_SIZE, GC_SMALL_BUTTON_SIZE),
                fullscreenImg, fullscreenImgH))
        self.buttons.append(
            Button(
                "begin",
                self.getButtonRect(beginCoords, Assets.I_BTN_MAINMENU_BEGIN),
                Assets.I_BTN_MAINMENU_BEGIN, Assets.I_BTN_MAINMENU_BEGIN_H))
        self.buttons.append(
            Button("help",
                   self.getButtonRect(helpCoords, Assets.I_BTN_MAINMENU_HELP),
                   Assets.I_BTN_MAINMENU_HELP, Assets.I_BTN_MAINMENU_HELP_H))
        self.buttons.append(
            Button(
                "highscores",
                self.getButtonRect(highscoresCoords,
                                   Assets.I_BTN_MAINMENU_HIGHSCORES),
                Assets.I_BTN_MAINMENU_HIGHSCORES,
                Assets.I_BTN_MAINMENU_HIGHSCORES_H))
Example #2
0
 def buttonClicked(self, buttonName):
     if buttonName == "exit":
         ScreenManager.exit()
     if buttonName == "begin":
         Graphics.camera.reset()
         ScreenManager.setScreen(NewGameLoaderScreen())
     if buttonName == "highscores":
         Graphics.camera.disable()
         from screens.HighscoreDisplayScreen import HighscoreDisplayScreen
         ScreenManager.setScreen(HighscoreDisplayScreen())
     if buttonName == "help":
         Graphics.camera.disable()
         from screens.InstructionsScreen import InstructionsScreen
         ScreenManager.setScreen(InstructionsScreen())
     if buttonName == "fullscreen":
         Graphics.swapWindowMode()
         # also need to switch the 'go fullscreen' button to a 'go windowed' button and vice versa
         # get the right image (go fullscreen or go windowed)
         fullscreenImg = Assets.I_BTN_UNFULLSCREEN if Graphics.isFullscreen(
         ) else Assets.I_BTN_FULLSCREEN
         fullscreenImgH = Assets.I_BTN_UNFULLSCREEN_H if Graphics.isFullscreen(
         ) else Assets.I_BTN_FULLSCREEN_H
         # remove the fullscreen button
         self.buttons = list(
             filter(lambda b: b.name != "fullscreen", self.buttons))
         # add a fullscreen button with the right image
         self.buttons.append(
             Button(
                 "fullscreen",
                 PosRect(GC_WORLD_WIDTH - GC_SMALL_BUTTON_SIZE,
                         GC_WORLD_HEIGHT - GC_SMALL_BUTTON_SIZE,
                         GC_SMALL_BUTTON_SIZE, GC_SMALL_BUTTON_SIZE),
                 fullscreenImg, fullscreenImgH))
	def getButtonRect(locationPercentage: tuple, image: pygame.Surface) -> PosRect:
		xPercent = locationPercentage[0]
		yPercent = locationPercentage[1]
		return PosRect((GC_WORLD_WIDTH * xPercent - image.get_width() / 2),
					   (GC_WORLD_HEIGHT * yPercent - image.get_height() / 2),
					   image.get_width(),
					   image.get_height())
 def __init__(self):
     super().__init__()
     self.buttons.append(
         Button(
             "back",
             PosRect(GC_WORLD_WIDTH - GC_SMALL_BUTTON_SIZE, 0,
                     GC_SMALL_BUTTON_SIZE, GC_SMALL_BUTTON_SIZE),
             Assets.I_BTN_BACK, Assets.I_BTN_BACK_H))
Example #5
0
	def __init__(self):
		super().__init__()
		if GC_GRAB_MOUSE:
			pygame.event.set_grab(False)
		self.buttons.append(
			Button("back",
				   PosRect(GC_WORLD_WIDTH - GC_SMALL_BUTTON_SIZE, 0, GC_SMALL_BUTTON_SIZE, GC_SMALL_BUTTON_SIZE),
				   Assets.I_BTN_BACK, Assets.I_BTN_BACK_H))
Example #6
0
    def __init__(self):
        PaddleAssetCopy = Animation(Assets.A_PADDLE.images,
                                    Assets.A_PADDLE.frameTime,
                                    Assets.A_PADDLE.beginFrame,
                                    Assets.A_PADDLE.next)
        super().__init__(PaddleAssetCopy)
        self.velocity: Velocity = Velocity(0, 0)

        x = GC_WORLD_WIDTH / 2 - GC_PADDLE_WIDTH // 2
        self.rect: PosRect = PosRect(x, GC_PADDLE_TOP_HEIGHT, GC_PADDLE_WIDTH,
                                     GC_PADDLE_HEIGHT)
Example #7
0
    def __init__(self, pos: PosRect, maxHP: int, powerUP):
        self.rect: PosRect = PosRect(pos.x, pos.y, GC_BRICK_WIDTH,
                                     GC_BRICK_HEIGHT)
        super().__init__(self.getImageFromHP(maxHP, maxHP, powerUP))
        self.maxHP: int = maxHP
        self.hp: int = maxHP
        self.powerUp = powerUP

        # set brick score based on values in GameConstants
        if maxHP == -1:
            self.score: int = GC_BRICK_SCORES[3]
        else:
            self.score: int = GC_BRICK_SCORES[maxHP - 1]
Example #8
0
def makeBricks(level: int) -> List[Brick]:
    bricks = []

    if GC_BRICK_GEN_MODE == "random":
        maxHP = 1
        for i in range(33):
            brickX = random.randint(
                GC_WALL_SIZE, GC_WORLD_WIDTH - GC_WALL_SIZE - GC_BRICK_WIDTH)
            brickY = random.randint(GC_BRICK_TOP_HEIGHT,
                                    GC_BRICK_BOTTOM_HEIGHT -
                                    GC_BRICK_HEIGHT)  # top-down coordinates
            bricks.append(
                Brick(PosRect(brickX, brickY, GC_BRICK_WIDTH, GC_BRICK_HEIGHT),
                      maxHP, ''))
            maxHP += 1
            if maxHP == 4:
                maxHP = -1
            if maxHP == 0:
                maxHP = 1

    if GC_BRICK_GEN_MODE == "filled":
        for i in range(GC_BRICK_COLUMNS):
            for j in range(GC_BRICK_LAYERS):
                brickX = i * GC_BRICK_WIDTH + GC_WALL_SIZE
                brickY = j * GC_BRICK_HEIGHT + GC_BRICK_TOP_HEIGHT
                brickHP = random.randint(1, 4)
                if brickHP == 4:
                    brickHP = -1
                bricks.append(
                    Brick(
                        PosRect(brickX, brickY, GC_BRICK_WIDTH,
                                GC_BRICK_HEIGHT), brickHP, ''))

    if GC_BRICK_GEN_MODE == "manual":
        f = open("assets/levels/level" + str(level) + ".txt")
        for i in range(GC_BRICK_LAYERS):
            line = f.readline()
            for j in range(GC_BRICK_COLUMNS):
                character = line[j:j + 1]
                brickX = j * GC_BRICK_WIDTH + GC_WALL_SIZE
                brickY = i * GC_BRICK_HEIGHT + GC_BRICK_TOP_HEIGHT
                if character.isupper():
                    if character == 'A':
                        bricks.append(
                            Brick(
                                PosRect(brickX, brickY, GC_BRICK_WIDTH,
                                        GC_BRICK_HEIGHT), 2, 'extraBall'))
                    if character == 'C':
                        bricks.append(
                            Brick(
                                PosRect(brickX, brickY, GC_BRICK_WIDTH,
                                        GC_BRICK_HEIGHT), 2, 'clearRow'))
                else:
                    brickHP = int(character)
                    if brickHP != 0:  # if shouldn't be empty, add a brick
                        if brickHP == 4:
                            brickHP = -1  # convert invincible brick from 4 (in file) to -1 (in code)
                        bricks.append(
                            Brick(
                                PosRect(brickX, brickY, GC_BRICK_WIDTH,
                                        GC_BRICK_HEIGHT), brickHP, ''))

    return bricks