示例#1
0
 def __init__(self, gm):
     super().__init__()
     self.button_1 = Button(50, 100, 200, 50, "960 x 540", gm)
     self.button_2 = Button(50, 200, 200, 50, "1280 x 720", gm)
     self.button_3 = Button(50, 300, 200, 50, "1920 x 1080", gm)
     self.button_4 = Button(50, 400, 200, 50, "Fullscreen", gm)
     self.mainmenu_button = Button(50, 500, 200, 50, "Main Menu", gm)
示例#2
0
def drawPlayerButton():
    playerButton = []

    playerButton.append(Button((255, 0, 0), 95, 200, 200, 35, 30, 'PLAYER 1: ' + str(players[0].balance)))
    playerButton.append(Button((255, 0, 0), 305, 200, 200, 35, 30, 'PLAYER 2: ' + str(players[1].balance)))

    if nop == 3:
        playerButton.append(Button((255, 0, 0), 200, 240, 200, 35, 30, 'PLAYER 3: ' + str(players[2].balance)))
    elif nop == 4:
        playerButton.append(Button((255, 0, 0), 95, 240, 200, 35, 30, 'PLAYER 3: ' + str(players[2].balance)))
        playerButton.append(Button((255, 0, 0), 305, 240, 200, 35, 30, 'PLAYER 4: ' + str(players[3].balance)))

    playerButton[turn].colour = (0, 255, 0)

    black = pygame.Surface((200, 35))
    black.set_alpha(200)
    black.fill((0, 0, 0))

    for i in playerButton:
        i.draw(win, (0, 0, 0))

    for i in range(nop):
        players[i].drawButton(win, (playerButton[i].x, playerButton[i].y))

    for i in range(nop):
        if players[i].bankrupt:
            win.blit(black, (playerButton[i].x, playerButton[i].y))
示例#3
0
 def eInit(self):
     edit.init(self)
     self.oldProjects = pickletest.loadAll()
     self.projectButtons = []
     for i in range(len(self.oldProjects)):
         project = self.oldProjects[i]
         y0 = self.height / 2 + 20
         x0 = self.width / 5
         space = 20
         maxProjectsX = 5
         maxProjectsY = 2
         width = ((self.width * 3 / 5) -
                  (space * (maxProjectsX - 1))) / maxProjectsX
         height = ((self.height / 2) -
                   (space * maxProjectsY)) / maxProjectsY
         x = x0 + i % maxProjectsX * (space + width)
         y = y0 if i < maxProjectsX else y0 + height + space
         rect = (x, y, width, height)
         text = project.scoreTitle
         button = Button(rect, text, (159, 182, 205))
         self.projectButtons.append(button)
     if len(self.oldProjects) == 0:
         text = "No Old Projects"
         button = Button((self.width / 4, 2 * self.height / 3,
                          self.width / 2, self.height / 4), text,
                         (198, 226, 255), 0, False)
         self.buttons.append(button)
示例#4
0
class WinScreen(Screen):
    def __init__(self, gm):
        super().__init__()
        self.mainmenu_button = Button(50, 100, 200, 50, "Main Menu", gm)
        self.quit_button = Button(300, 100, 200, 50, 'Quit Game', gm)

    def run(self, gm):

        click = False
        running = True
        pygame.mixer.Channel(0).play(pygame.mixer.Sound("sounds/Win.ogg"))

        while running:
            gm.clock.tick(60)
            gm.fake_screen.blit(gm.game_screen.background,
                                gm.game_screen.background.get_rect())
            gm.game_screen.hero.draw(gm)
            self.draw_text('You win', gm.font_big, (255, 255, 255),
                           gm.fake_screen, (960, 350))
            self.draw_text('Score: {}'.format(int(gm.game_screen.score)),
                           gm.font_med, (255, 255, 255), gm.fake_screen,
                           (960, 550))

            mx, my = gm.mousepos

            #Avalia botão quit
            if self.quit_button.contour.collidepoint((mx, my)):
                self.quit_button.draw(True, gm)
                if click:
                    gm.actual_screen = gm.quit_confirmation_screen
                    running = False
            else:
                self.quit_button.draw(False, gm)

            #Avalia botão menu
            if self.mainmenu_button.contour.collidepoint((mx, my)):
                self.mainmenu_button.draw(True, gm)
                if click:
                    gm.game_screen.new_game(gm)
                    gm.actual_screen = gm.menu_screen
                    running = False
            else:
                self.mainmenu_button.draw(False, gm)

            click = False

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    gm.game_screen.onCleanup(gm)

                if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                    gm.actual_screen = gm.quit_confirmation_screen
                    running = False

                if event.type == pygame.MOUSEBUTTONDOWN:
                    if event.button == 1:
                        click = True

            self.run_screen(gm)
class QuitConfirmationScreen(Screen):
    def __init__(self, gm):
        super().__init__()
        self.button_1 = Button(50, 100, 200, 50, "Cancel", gm)
        self.button_2 = Button(350, 100, 200, 50, "Quit", gm)

    def run(self, gm):

        running = True
        click = False

        while running:
            gm.clock.tick(60)
            gm.fake_screen.fill((0, 0, 0))
            self.draw_text('Do you really want to quit?', gm.font,
                           (255, 255, 255), gm.fake_screen, (960, 20))

            mx, my = gm.mousepos

            if self.button_1.contour.collidepoint((mx, my)):
                self.button_1.draw(True, gm)
                if click:
                    running = False
                    gm.game_screen.endGame(gm)
                    gm.actual_screen = gm.menu_screen
            else:
                self.button_1.draw(False, gm)

            if self.button_2.contour.collidepoint((mx, my)):
                self.button_2.draw(True, gm)
                if click:
                    gm.game_screen.endGame(gm)
                    gm.game_screen.onCleanup(gm)
            else:
                self.button_2.draw(False, gm)

            click = False

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    gm.game_screen.endGame(gm)
                    gm.game_screen.onCleanup(gm)

                if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                    running = False
                    gm.actual_screen = gm.menu_screen

                if event.type == pygame.MOUSEBUTTONDOWN:
                    if event.button == 1:
                        click = True

            self.run_screen(gm)
示例#6
0
class PauseScreen(Screen):
    def __init__(self, gm):
        super().__init__()
        self.resume_button = Button(50, 100, 200, 50, "Resume", gm)
        self.mainmenu_button = Button(50, 200, 200, 50, "Main Menu", gm)
    
    def run(self, gm):

        click=False
        running = True
        
        while running:

            gm.clock.tick(60)
            gm.fake_screen.fill((0,0,0))
            self.draw_text('Pause Menu', gm.font, (255, 255, 255), gm.fake_screen, (960,20))
    
            mx, my = gm.mousepos

            #Seleciona botões
            if self.resume_button.contour.collidepoint((mx, my)):
                self.resume_button.draw(True, gm)
                if click:
                    gm.actual_screen = gm.game_screen
                    running = False 
            else:
                self.resume_button.draw(False, gm)

            if self.mainmenu_button.contour.collidepoint((mx, my)):
                self.mainmenu_button.draw(True, gm)
                if click:
                    gm.game_screen.new_game(gm)
                    gm.actual_screen = gm.menu_screen 
                    running = False
            else:
                self.mainmenu_button.draw(False, gm)

            click = False
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    gm.game_screen.onCleanup()
                
                if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                    running = False

                if event.type == pygame.MOUSEBUTTONDOWN:
                    if event.button == 1:
                        click = True

            self.run_screen(gm)
示例#7
0
 def load_data(self):
     self.font = pygame.font.Font(None, 34)
     self.yes1 = pygame.image.load("rec/yes.png")
     self.yes2 = pygame.image.load("rec/yes2.png")
     self.no1 = pygame.image.load("rec/no.png")
     self.no2 = pygame.image.load("rec/no2.png")
     self.localPvP_button = Button("LocalPvP", 10, 10, RED)
     self.localPvE_button = Button("LocalPvE", 170, 10, RED)
     self.onlinePvP_button = Button("OnlinePvP", 330, 10, RED)
 def eInit(self):
     edit.init(self)
     projects = pickletest.loadAll()
     self.projectButtons = []
     for i in range(len(projects)):
         project = projects[i]
         y0 = self.height/2 + 20
         x0 = self.width/5
         space = 20
         maxProjectsX = 5
         maxProjectsY = 2
         width = ((self.width*3/5) - (space*(maxProjectsX-1)))/maxProjectsX
         height = ((self.height/2) - (space*maxProjectsY))/maxProjectsY
         x = x0 + i%maxProjectsX*(space + width)
         y = y0 if i < maxProjectsX else y0 + height + space
         rect = (x, y, width, height)
         text = str(projects[i])
         # text = project.scoreTitle
         button = Button(rect, text, (40,50,60))
         self.projectButtons.append(button)
示例#9
0
    def __init__(self):

        # Set current game mode
        self.singleplayer = False

        # Creating the window
        self.win = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT))
        pygame.display.set_caption("Football")

        # setting the favicon
        self.favicon = pygame.image.load("data/img/favicon.png")
        pygame.display.set_icon(self.favicon)

        # loading the bg image
        self.bgimg = pygame.image.load("data/img/background.png")

        # loading ball image
        self.ball = pygame.image.load("data/img/ball.png")

        # loading the net image
        self.netimg1 = pygame.image.load("data/img/net1.png")
        self.netimg2 = pygame.image.load("data/img/net2.png")

        # loading fonts
        self.font = pygame.font.SysFont('courier', 40, True)
        self.buttonFont = pygame.font.SysFont('Ariel', 25, False)

        # loading the sound files
        self.goalSound = pygame.mixer.Sound("data/wav/goal.wav")
        self.selectSound = pygame.mixer.Sound("data/wav/select.wav")

        self.clock = pygame.time.Clock()

        # Player Instances
        self.player1 = Player(100, SCREENHEIGHT - PLAYERHEIGHT, RED,
                              PLAYERWIDTH, PLAYERHEIGHT, PLAYERSPEED, self.win)

        self.player2 = Player(SCREENWIDTH - 100 - PLAYERWIDTH,
                              SCREENHEIGHT - PLAYERHEIGHT, BLUE, PLAYERWIDTH,
                              PLAYERHEIGHT, PLAYERSPEED, self.win)

        # Ball Instance
        self.ball = Ball((SCREENWIDTH // 2) - (BALLRADIUS // 2),
                         (SCREENHEIGHT // 2) - BALLRADIUS, self.ball,
                         BALLRADIUS, BALLSPEED, self.win)
        self.ball.randDirec(False, True)

        # Net Instances
        self.net1 = Net(20, SCREENHEIGHT - NETHEIGHT, self.netimg1, NETWIDTH,
                        NETHEIGHT, self.win)

        self.net2 = Net(SCREENWIDTH - 20 - NETWIDTH, SCREENHEIGHT - NETHEIGHT,
                        self.netimg2, NETWIDTH, NETHEIGHT, self.win)

        # Crossbar Instances
        self.net1Top = ColliderBox(0, SCREENHEIGHT - NETHEIGHT - 10,
                                   NETWIDTH + 21, 10, self.win)

        self.net2Top = ColliderBox(SCREENWIDTH - 20 - NETWIDTH,
                                   SCREENHEIGHT - NETHEIGHT - 10,
                                   NETWIDTH + 20, 10, self.win)

        # Buttons to change gamemode

        # NOT SINGLEPLAYER MEANS SINGLEPLAYER BUTTON IS OFF
        # SINGLEPLAYER == TRUE MEANS SINGLEPLAYER BUTTON IS ON
        self.spButton = Button(MODE_BUTTONS_X, MODE_BUTTONS_Y,
                               MODE_BUTTON_WIDTH, MODE_BUTTON_HEIGHT, self.win,
                               lambda: self.switchMode("singleplayer"), GREEN,
                               RED, not self.singleplayer, self.buttonFont,
                               "Singleplayer")

        self.mpButton = Button(MODE_BUTTONS_X + MODE_BUTTON_WIDTH + 20,
                               MODE_BUTTONS_Y, MODE_BUTTON_WIDTH,
                               MODE_BUTTON_HEIGHT, self.win,
                               lambda: self.switchMode("multiplayer"), GREEN,
                               RED, self.singleplayer, self.buttonFont,
                               "Multiplayer")

        # Array of all items
        self.items = [
            self.ball, self.player1, self.player2, self.net1, self.net1Top,
            self.net2, self.net2Top, self.spButton, self.mpButton
        ]
示例#10
0
class Game(object):

    # Start of shit
    def __init__(self):

        # Set current game mode
        self.singleplayer = False

        # Creating the window
        self.win = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT))
        pygame.display.set_caption("Football")

        # setting the favicon
        self.favicon = pygame.image.load("data/img/favicon.png")
        pygame.display.set_icon(self.favicon)

        # loading the bg image
        self.bgimg = pygame.image.load("data/img/background.png")

        # loading ball image
        self.ball = pygame.image.load("data/img/ball.png")

        # loading the net image
        self.netimg1 = pygame.image.load("data/img/net1.png")
        self.netimg2 = pygame.image.load("data/img/net2.png")

        # loading fonts
        self.font = pygame.font.SysFont('courier', 40, True)
        self.buttonFont = pygame.font.SysFont('Ariel', 25, False)

        # loading the sound files
        self.goalSound = pygame.mixer.Sound("data/wav/goal.wav")
        self.selectSound = pygame.mixer.Sound("data/wav/select.wav")

        self.clock = pygame.time.Clock()

        # Player Instances
        self.player1 = Player(100, SCREENHEIGHT - PLAYERHEIGHT, RED,
                              PLAYERWIDTH, PLAYERHEIGHT, PLAYERSPEED, self.win)

        self.player2 = Player(SCREENWIDTH - 100 - PLAYERWIDTH,
                              SCREENHEIGHT - PLAYERHEIGHT, BLUE, PLAYERWIDTH,
                              PLAYERHEIGHT, PLAYERSPEED, self.win)

        # Ball Instance
        self.ball = Ball((SCREENWIDTH // 2) - (BALLRADIUS // 2),
                         (SCREENHEIGHT // 2) - BALLRADIUS, self.ball,
                         BALLRADIUS, BALLSPEED, self.win)
        self.ball.randDirec(False, True)

        # Net Instances
        self.net1 = Net(20, SCREENHEIGHT - NETHEIGHT, self.netimg1, NETWIDTH,
                        NETHEIGHT, self.win)

        self.net2 = Net(SCREENWIDTH - 20 - NETWIDTH, SCREENHEIGHT - NETHEIGHT,
                        self.netimg2, NETWIDTH, NETHEIGHT, self.win)

        # Crossbar Instances
        self.net1Top = ColliderBox(0, SCREENHEIGHT - NETHEIGHT - 10,
                                   NETWIDTH + 21, 10, self.win)

        self.net2Top = ColliderBox(SCREENWIDTH - 20 - NETWIDTH,
                                   SCREENHEIGHT - NETHEIGHT - 10,
                                   NETWIDTH + 20, 10, self.win)

        # Buttons to change gamemode

        # NOT SINGLEPLAYER MEANS SINGLEPLAYER BUTTON IS OFF
        # SINGLEPLAYER == TRUE MEANS SINGLEPLAYER BUTTON IS ON
        self.spButton = Button(MODE_BUTTONS_X, MODE_BUTTONS_Y,
                               MODE_BUTTON_WIDTH, MODE_BUTTON_HEIGHT, self.win,
                               lambda: self.switchMode("singleplayer"), GREEN,
                               RED, not self.singleplayer, self.buttonFont,
                               "Singleplayer")

        self.mpButton = Button(MODE_BUTTONS_X + MODE_BUTTON_WIDTH + 20,
                               MODE_BUTTONS_Y, MODE_BUTTON_WIDTH,
                               MODE_BUTTON_HEIGHT, self.win,
                               lambda: self.switchMode("multiplayer"), GREEN,
                               RED, self.singleplayer, self.buttonFont,
                               "Multiplayer")

        # Array of all items
        self.items = [
            self.ball, self.player1, self.player2, self.net1, self.net1Top,
            self.net2, self.net2Top, self.spButton, self.mpButton
        ]

    # Button to change gamemode func
    def switchMode(self, mode):

        self.selectSound.play()

        if mode == "multiplayer":
            self.singleplayer = False
            self.spButton.active = True
            self.mpButton.active = False

        elif mode == "singleplayer":
            self.singleplayer = True
            self.mpButton.active = True
            self.spButton.active = False

    # Function to reset and play the score sound
    def onScore(self):
        self.goalSound.play()

        for player in (self.player1, self.player2):
            player.jumpCount = 10
            player.isJump = False
        for item in self.items:
            item.x = item.initx
            item.y = item.inity

    # Function to draw the next frame
    def drawNewFrame(self):
        self.win.blit(self.bgimg, (0, 0))

        scr1 = self.font.render(str(self.player1.score), 1, RED)
        self.win.blit(scr1, (10, 10))
        scr2 = self.font.render(str(self.player2.score), 1, BLUE)
        self.win.blit(scr2, ((SCREENWIDTH - scr2.get_width() - 10), 10))

        for item in self.items:
            item.draw()

        pygame.display.update()

    # Function that processes the events of the game on each frame
    def update(self):

        # Check if the user wants to change the game mode
        self.spButton.check_pressed()
        self.mpButton.check_pressed()

        # Get a list of the currently selected keyboard keys
        keys = pygame.key.get_pressed()

        # Check if the user wants to jump
        if keys[pygame.K_a] and self.player1.x > 0:
            self.player1.x -= self.player1.vel
        if keys[pygame.K_d] and self.player1.x < (SCREENWIDTH - PLAYERWIDTH):
            self.player1.x += self.player1.vel
        self.player1.jumpLoop(keys[pygame.K_w])

        # Run the AI frame if it is singleplayer
        if self.singleplayer:
            if self.ball.x + 20 < self.player2.x:
                self.player2.x -= self.player2.vel // 1.5
            if self.ball.x + 20 > self.player2.x:
                self.player2.x += self.player2.vel // 1.5
            self.player2.jumpLoop((self.player2.x - self.ball.x) > -40
                                  and (self.player2.x - self.ball.x) < 40
                                  and self.player2.y > self.ball.y)
        else:  # If not, allow player 2 to move should they choose to
            if keys[pygame.K_LEFT] and self.player2.x > 0:
                self.player2.x -= self.player2.vel
            if keys[pygame.K_RIGHT] and self.player2.x < (SCREENWIDTH -
                                                          PLAYERWIDTH):
                self.player2.x += self.player2.vel
            self.player2.jumpLoop(keys[pygame.K_UP])

        # 0 = Up, 1 = Left, 2 = Down, 3 = Right
        if 0 in self.ball.direc:
            self.ball.y -= self.ball.vel // self.ball.div
        if 1 in self.ball.direc:
            self.ball.x -= self.ball.vel
        if 2 in self.ball.direc:
            self.ball.y += self.ball.vel // self.ball.div
        if 3 in self.ball.direc:
            self.ball.x += self.ball.vel
        if self.ball.x <= (0 + self.ball.radius):
            self.ball.bounceHorz()
            self.ball.x = 1 + self.ball.radius
        if self.ball.x >= (SCREENWIDTH - (self.ball.radius // 2)):
            self.ball.bounceHorz()
            self.ball.x = (SCREENWIDTH - (self.ball.radius // 2)) - 1
        if self.ball.y <= (0 + self.ball.radius):
            self.ball.bounceVert()
            self.ball.y = 1 + self.ball.radius
        if self.ball.y >= (SCREENHEIGHT - (self.ball.radius // 2)):
            self.ball.bounceVert()
            self.ball.y = (SCREENHEIGHT - (self.ball.radius // 2)) - 1

        if self.ball.collisionCooldown > 0:
            self.ball.collisionCooldown -= 1
        else:
            for colliderHit in (self.player1, self.player2, self.net1,
                                self.net1Top, self.net2, self.net2Top):
                if self.ball.y - self.ball.radius < colliderHit.hitbox[
                        1] + colliderHit.hitbox[3]:
                    if self.ball.y + self.ball.radius > colliderHit.hitbox[1]:
                        if self.ball.x + self.ball.radius > colliderHit.hitbox[
                                0]:
                            if self.ball.x - self.ball.radius < colliderHit.hitbox[
                                    0] + colliderHit.hitbox[2]:
                                if colliderHit == self.net1:
                                    self.player2.score += 1
                                    self.ball.setDiv()
                                    self.onScore()
                                elif colliderHit == self.net2:
                                    self.player1.score += 1
                                    self.ball.setDiv()
                                    self.onScore()
                                else:
                                    self.ball.bounceHorz()
                                    self.ball.bounceVert()
                                    self.ball.collisionCooldown = 10

    # Function to poll necessary pygame events
    def pollEvents(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.run = False

    # Main Program Loop
    def mainloop(self):

        self.run = True
        while self.run:

            self.drawNewFrame()  # Draw next frame

            self.clock.tick(60)  # Delay by 1 60th of a second

            self.update()  # Process current frame

            self.pollEvents()  # Poll events
示例#11
0
#intialize framerate
clock = pygame.time.Clock()
FPS = 60

#initialize display
dislen = 1000
diswid = 600
gamewindow = pygame.display.set_mode((dislen, diswid))
pygame.display.set_caption("Pong+")

#intialize fonts
titlefont = pygame.font.SysFont("arial", 50)
buttonfont = pygame.font.SysFont("arial", 30)

#initializes text
title = Button("Pong+", titlefont, 425, 100)
singleplayerbutton = Button("Volley Mode", buttonfont, 225, 300)
multiplayerbutton = Button("VS Match", buttonfont, 600, 300)
hstext = buttonfont.render("High Score: " + hs, 1, (0,0,0,))


game = True
while game == True:

    #update mouse position
    mouse = pygame.mouse.get_pos()

    #event queue
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            game = False
示例#12
0
 def __init__(self, gm):
     super().__init__()
     self.mainmenu_button = Button(50, 900, 200, 50, "Main Menu", gm)
     self.keys_image = pygame.image.load('imgs/teclas.png')
     self.mouse_image = pygame.image.load('imgs/mouse_click.png')
     self.esc_image = pygame.image.load('imgs/esc.png')
示例#13
0
class InstructionsScreen(Screen):
    def __init__(self, gm):
        super().__init__()
        self.mainmenu_button = Button(50, 900, 200, 50, "Main Menu", gm)
        self.keys_image = pygame.image.load('imgs/teclas.png')
        self.mouse_image = pygame.image.load('imgs/mouse_click.png')
        self.esc_image = pygame.image.load('imgs/esc.png')

    def run(self, gm):

        running = True
        click = False

        while running:
            gm.clock.tick(60)
            gm.fake_screen.fill((0, 0, 0))
            self.draw_text('Instructions', gm.font, (255, 255, 255),
                           gm.fake_screen, ((960, 20)))
            gm.fake_screen.blit(self.keys_image, [100, 150])
            self.draw_text('Movimentar jogador', gm.font_p, (255, 255, 255),
                           gm.fake_screen, ((1100, 200)))
            gm.fake_screen.blit(self.mouse_image, [200, 380])
            self.draw_text('Atirar', gm.font_p, (255, 255, 255),
                           gm.fake_screen, ((1100, 480)))
            gm.fake_screen.blit(self.esc_image, [200, 650])
            self.draw_text('Pausar', gm.font_p, (255, 255, 255),
                           gm.fake_screen, ((1100, 750)))

            mx, my = gm.mousepos

            #Selecionar botão
            if self.mainmenu_button.contour.collidepoint((mx, my)):
                self.mainmenu_button.draw(True, gm)
                if click:
                    gm.actual_screen = gm.menu_screen
                    running = False
            else:
                self.mainmenu_button.draw(False, gm)

            click = False

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    gm.game_screen.onCleanup(gm)

                if event.type == pygame.MOUSEBUTTONDOWN:
                    if event.button == 1:
                        click = True

                if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                    running = False

                if event.type == pygame.VIDEORESIZE:
                    if gm.window_resolution != event.size:
                        gm.fullscreen = False
                        gm.window_resolution = event.size
                        gm.screen = pygame.display.set_mode(event.size)
                        gm.screen.blit(
                            pygame.transform.scale(gm.fake_screen,
                                                   gm.window_resolution),
                            (0, 0))
                        pygame.display.flip()

                if event.type == pygame.USEREVENT + 1:
                    if not gm.fullscreen:
                        gm.fullscreen = True
                        gm.window_resolution = gm.monitor_resolution
                        gm.screen = pygame.display.set_mode(
                            gm.window_resolution, pygame.FULLSCREEN)
                        gm.screen.blit(
                            pygame.transform.scale(gm.fake_screen,
                                                   gm.window_resolution),
                            (0, 0))
                        pygame.display.flip()

            self.run_screen(gm)
示例#14
0
 def __init__(self, gm):
     super().__init__()
     self.mainmenu_button = Button(50, 100, 200, 50, "Main Menu", gm)
     self.quit_button = Button(300, 100, 200, 50, 'Quit Game', gm)
示例#15
0
文件: menu.py 项目: dancool5/checkers
screen_saver_im = functions.load_image('screen_saver1.png')
s.height = s.width * s.height // screen_saver_im.get_rect().size[0]
size = (s.width, s.height)
screen_saver = pygame.transform.scale(screen_saver_im, (s.width, s.height))
# screen_saver = screen_saver_im
screen = pygame.display.set_mode(size)

pygame.display.set_caption('Checkers')
pygame.display.set_icon(
    pygame.transform.scale(functions.load_image('icon.ico'), (32, 32)))

buttons_sprites = pygame.sprite.Group()
buttons = []

if s.state == 'main_menu':
    button_new_game = Button(functions.load_image('button_newgame.png'),
                             buttons_sprites)
    button_new_game.set_pos(s.width // 2 - button_new_game.rect.width // 2,
                            s.height // 4)
    buttons.append(button_new_game)

    button_download = Button(functions.load_image('button_download.png'),
                             buttons_sprites)
    button_download.set_pos(s.width // 2 - button_download.rect.width // 2,
                            s.height // 2)
    buttons.append(button_download)

    button_exit = Button(functions.load_image('button_exit.png'),
                         buttons_sprites)
    button_exit.set_pos(s.width // 2 - button_exit.rect.width // 2,
                        s.height - button_exit.rect.height - s.height // 11)
    buttons.append(button_exit)
示例#16
0
 def __init__(self, gm):
     super().__init__()
     self.button_1 = Button(50, 100, 200, 50, "Cancel", gm)
     self.button_2 = Button(350, 100, 200, 50, "Quit", gm)
示例#17
0
class OptionsScreen(Screen):
    def __init__(self, gm):
        super().__init__()
        self.button_1 = Button(50, 100, 200, 50, "960 x 540", gm)
        self.button_2 = Button(50, 200, 200, 50, "1280 x 720", gm)
        self.button_3 = Button(50, 300, 200, 50, "1920 x 1080", gm)
        self.button_4 = Button(50, 400, 200, 50, "Fullscreen", gm)
        self.mainmenu_button = Button(50, 500, 200, 50, "Main Menu", gm)

    def run(self, gm):

        running = True
        click = False

        while running:
            gm.clock.tick(60)
            gm.fake_screen.fill((0, 0, 0))
            self.draw_text('Options', gm.font, (255, 255, 255), gm.fake_screen,
                           ((960, 20)))

            mx, my = gm.mousepos

            #Selecionar botão
            if self.button_1.contour.collidepoint((mx, my)):
                self.button_1.draw(True, gm)
                if click:
                    self.post_resize_event((960, 540))
            else:
                self.button_1.draw(False, gm)

            if self.button_2.contour.collidepoint((mx, my)):
                self.button_2.draw(True, gm)
                if click:
                    self.post_resize_event((1280, 720))
            else:
                self.button_2.draw(False, gm)

            if self.button_3.contour.collidepoint((mx, my)):
                self.button_3.draw(True, gm)
                if click:
                    self.post_resize_event((1920, 1080))
            else:
                self.button_3.draw(False, gm)

            if self.button_4.contour.collidepoint((mx, my)):
                self.button_4.draw(True, gm)
                if click:
                    self.post_fullscreen()
            else:
                self.button_4.draw(False, gm)

            if self.mainmenu_button.contour.collidepoint((mx, my)):
                self.mainmenu_button.draw(True, gm)
                if click:
                    gm.actual_screen = gm.menu_screen
                    running = False
            else:
                self.mainmenu_button.draw(False, gm)

            click = False

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    gm.game_screen.onCleanup(gm)

                if event.type == pygame.MOUSEBUTTONDOWN:
                    if event.button == 1:
                        click = True

                if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                    running = False

                if event.type == pygame.VIDEORESIZE:
                    if gm.window_resolution != event.size:
                        gm.fullscreen = False
                        gm.window_resolution = event.size
                        gm.screen = pygame.display.set_mode(event.size)
                        gm.screen.blit(
                            pygame.transform.scale(gm.fake_screen,
                                                   gm.window_resolution),
                            (0, 0))
                        pygame.display.flip()

                if event.type == pygame.USEREVENT + 1:
                    if not gm.fullscreen:
                        gm.fullscreen = True
                        gm.window_resolution = gm.monitor_resolution
                        gm.screen = pygame.display.set_mode(
                            gm.window_resolution, pygame.FULLSCREEN)
                        gm.screen.blit(
                            pygame.transform.scale(gm.fake_screen,
                                                   gm.window_resolution),
                            (0, 0))
                        pygame.display.flip()

            self.run_screen(gm)
示例#18
0
def main():
    pg.init()
    screen = display("Drawing", size(), Color('white'), fullscreen=True)
    width, height = size()
    playing = True

    #Color buttons
    black = Button(Color('black'), 10, 10, 50, 50)
    black.draw(screen, outline=Color('black'))
    white = Button(Color('white'), 10, 60, 50, 50)
    white.draw(screen, outline=Color('black'))
    red = Button(Color('red'), 10, 110, 50, 50)
    red.draw(screen, outline=Color('black'))
    blue = Button(Color('blue'), 10, 160, 50, 50)
    blue.draw(screen, outline=Color('black'))
    green = Button(Color('green'), 10, 210, 50, 50)
    green.draw(screen, outline=Color('black'))
    yellow = Button(Color('yellow'), 10, 260, 50, 50)
    yellow.draw(screen, outline=Color('black'))
    magenta = Button(Color('magenta'), 10, 310, 50, 50)
    magenta.draw(screen, outline=Color('black'))
    cyan = Button(Color('cyan'), 10, 360, 50, 50)
    cyan.draw(screen, outline=Color('black'))

    quit_button = Button(Color('red'), (width - 300), (height - 150),
                         200,
                         75,
                         text='Quit')
    quit_button.draw(screen)
    pg.display.flip()

    color = 'black'

    while playing:
        left_pressed, middle_pressed, right_pressed = pg.mouse.get_pressed()

        events = pg.event.get()
        for event in events:
            if event.type == pg.QUIT:
                exit(0)
            if event.type == pg.KEYDOWN:
                if event.key == pg.K_g:
                    playing = False
            if event.type == pg.MOUSEBUTTONDOWN:
                pos = pg.mouse.get_pos()
                if black.is_over(pos):
                    color = 'black'
                if white.is_over(pos):
                    color = 'white'
                if red.is_over(pos):
                    color = 'red'
                if green.is_over(pos):
                    color = 'green'
                if blue.is_over(pos):
                    color = 'blue'
                if yellow.is_over(pos):
                    color = 'yellow'
                if magenta.is_over(pos):
                    color = 'magenta'
                if cyan.is_over(pos):
                    color = 'cyan'
                if quit_button.is_over(pos):
                    playing = False
            if left_pressed:
                pg.draw.circle(screen, Color(color), (pg.mouse.get_pos()), 5)
        pg.display.flip()
示例#19
0
GRAY = (128, 128, 128)
YELLOW = (255, 255, 0)
BROWN = (0, 100, 51)
DARKGREEN = (0, 64, 0)
win.fill(GREEN1)
bull_lvl = []
txt = open("money.txt", "r")
money = int(txt.readline())
bull_lvl.append(min(int(txt.readline()), 15))
bull_lvl.append(min(int(txt.readline()), 15))
bull_lvl.append(min(int(txt.readline()), 15))
hp_lvl = int(txt.readline())
speed_lvl = int(txt.readline())
level = int(txt.readline())
txt.close()
start_but = Button(int(screen_width / 10), int(screen_width / 20),
                   (100, 255, 0), GREEN)
b_s = int(screen_height / 200)
bullet = [
    Bullet(0, b_s, b_s, BROWN, 1, (5 * screen_height) * delay_time / 1000, 0.5,
           None),
    Bullet(10, 2 * b_s, 2 * b_s, BLACK, 2,
           (3 * screen_height) * delay_time / 1000, 1.5, None, 1, True,
           int(screen_width / 12)),
    Bullet(1, b_s, 2 * b_s, RED, 0.5, (6 * screen_height) * delay_time / 1000,
           0.1, None)
]

for i in range(3):
    for _ in range(bull_lvl[i] - 1):
        bullet[i].lvlup()
sel_bull = 0
示例#20
0
START_Y_CARDS = TITLE_FONT.get_height() + 2 * PADDING_V
START_X_PLAYER = START_X_CARDS
START_Y_PLAYER = START_Y_CARDS + 7 * PADDING_V + 7 * RADIUS_RESOURCES
START_Y_PLAYER_CARDS = START_Y_PLAYER + PADDING_V + LETTER_FONT.get_height()
START_X_PLAYER_RS = START_X_CARDS + int(RECTSQUARE_PLAYER_CARDS / 2)
START_Y_PLAYER_RS = START_Y_PLAYER_CARDS + RECTSQUARE_PLAYER_CARDS + PADDING_V * 2 + RADIUS_PLAYER_RS
START_X_BONI = START_X_CARDS + (RECTWIDTH_CARDDECK +
                                PADDING_H) * 4 + PADDING_H * 2
START_Y_BONI = START_Y_CARDS
START_X_RS = START_X_BONI + RECTWIDTHBONI + 4 * PADDING_H + int(
    RADIUS_RESOURCES / 2) + (int(REDUCED_WIDTH / 10) - int(REDUCED_WIDTH / 11))
START_Y_RS = START_Y_CARDS + 2 * RADIUS_RESOURCES

#in-gamebuttons
help_button = Button(
    LETTER_FONT,
    g.Rect(WIDTH - 2 * INGAME_BUTTON, 20, INGAME_BUTTON,
           LETTER_FONT.get_height() + 15), "Help")
help_button.colour = BLACK

exit_button = Button(
    LETTER_FONT,
    g.Rect(WIDTH - 4 * INGAME_BUTTON + PADDING_H, 20, INGAME_BUTTON,
           LETTER_FONT.get_height() + 15), "Exit")
exit_button.colour = BLACK

#setup game loop
FPS = 60
clock = g.time.Clock()

#setting up start menu:
start_b = Button(
示例#21
0
import pygame
from classes import Button, board
from lists import trade_list

bg = pygame.image.load('Images//Trade//bg.jpg')
up = pygame.image.load('Images//Trade//up.png')
down = pygame.image.load('Images//Trade//down.png')
p1Button = Button((255, 0, 0), 150, 275, 150, 40, 30, 'PLAYER 1')
p2Button = Button((255, 0, 0), 325, 275, 150, 40, 30, 'PLAYER 2')
p3Button = Button((255, 0, 0), 150, 325, 150, 40, 30, 'PLAYER 3')
p4Button = Button((255, 0, 0), 325, 325, 150, 40, 30, 'PLAYER 4')
cancelButton = Button((0, 0, 255), 420, 470, 75, 30, 25, 'CANCEL')
cash1Button = Button((128, 128, 128), 153, 450, 75, 40, 30, '0')
cash2Button = Button((128, 128, 128), 373, 450, 75, 40, 30, '0')
offerButton = Button((0, 255, 170), 80, 495, 100, 25, 20, 'OFFER')
cancelOfferButton = Button((0, 255, 170), 420, 495, 100, 25, 20, 'CANCEL')
acceptButton = Button((0, 255, 170), 80, 495, 100, 25, 20, 'ACCEPT')
rejectButton = Button((0, 255, 170), 420, 495, 100, 25, 20, 'REJECT')

p = [p1Button, p2Button, p3Button, p4Button]
chosen = offered = False
give = []
take = []
player_2 = ''

blackSurface = pygame.Surface((600, 600))
blackSurface.set_alpha(200)
blackSurface.fill((0, 0, 0))

blackCard = pygame.Surface((150, 40))
blackCard.set_alpha(200)
示例#22
0
def main():
    pg.init()

    bgcolor = color['white']
    screen = display("Relationship To Person",
                     size(),
                     bgcolor,
                     fullscreen=True)

    width, height = size()
    clock = pg.time.Clock()

    data = get_database('family.db', 'family_info',
                        ('rowid', 'name', 'gender', 'relation', 'image'))

    relations = [
        'aunt', 'uncle', 'cousin', 'grandma', 'grandpa', 'sister', 'mom', 'dad'
    ]

    lastans = 'Filler'

    quit_button = Button(color['red'], (width - 300), (height - 150),
                         200,
                         75,
                         text='Quit')

    playing = True

    while playing:
        correct = False
        spoken = False
        shuffle(data)

        person = data[0]
        while person['relation'] == lastans:
            shuffle(data)
            person = data[0]

        image = pg.image.load(f'img/{person["image"]}')
        ans = person['relation']

        guesses = [person['relation']]
        for i in range(2):
            select = choice(relations)
            while select in guesses:
                select = choice(relations)
            guesses.append(select)

        shuffle(guesses)

        height_div = [4, 2, 1.3]

        font = pg.font.SysFont('quicksandmedium', 80)

        while not correct and playing:

            events = pg.event.get()
            for event in events:
                if event.type == pg.QUIT:
                    exit()
                if event.type == pg.MOUSEBUTTONDOWN:
                    pos = pg.mouse.get_pos()
                    if locals()[ans].is_over(pos):
                        speak(f'{locals()[ans].text} is the correct answer')
                        correct = True
                if event.type == pg.KEYDOWN:
                    if event.key == pg.K_g:
                        playing = False
                if event.type == pg.MOUSEBUTTONDOWN:
                    pos = pg.mouse.get_pos()
                    if quit_button.is_over(pos):
                        playing = False

            screen.fill(bgcolor)
            font = pg.font.SysFont('quicksandmedium', 60)
            text = font.render(
                f'This is {person["name"].capitalize()}. {"He" if person["gender"]=="boy" else "She"} is your... ',
                1, color['black'])

            screen.blit(text, (width // 10, height // 10))

            show_img(screen, image, width // 4, height // 2)
            quit_button.draw(screen)
            for x, guess in enumerate(guesses):
                locals()[guess] = Button(color['magenta'], (width // 1.3),
                                         (height // height_div[x]),
                                         300,
                                         75,
                                         text=guess)
                locals()[guess].draw(screen)
            pg.display.flip()
            while not spoken:
                speak(
                    f'This is {person["name"].capitalize()}. {"He" if person["gender"]=="boy" else "She"} is your... '
                )
                spoken = True
            lastans = ans
示例#23
0
GRID_WIDTH = 425
GRID_POS = (25, 25)
grid = Grid(GRID_POS, GRID_WIDTH, 'easy', win)
grid.draw('default')

# setup button
BUTTON_START_X = 475
BUTTON_START_Y = 120
LARGE_WIDTH = 129
LARGE_HEIGHT = 50
LARGE_FONT = 28
SMALL_WIDTH = 40
SMALL_HEIGHT = 25
SMALL_FONT = 18
GAP = 8
newGameButton = Button((BUTTON_START_X, BUTTON_START_Y),
        LARGE_WIDTH, LARGE_HEIGHT, LARGE_FONT, "New Game", GRID_WIDTH, win)
easyButton = Button((BUTTON_START_X, BUTTON_START_Y + LARGE_HEIGHT),
        SMALL_WIDTH, SMALL_HEIGHT, SMALL_FONT, "Easy", GRID_WIDTH, win)
easyButton.clicked = True
mediumButton = Button((BUTTON_START_X + SMALL_WIDTH, BUTTON_START_Y + LARGE_HEIGHT),
        SMALL_WIDTH + 9, SMALL_HEIGHT, SMALL_FONT, "Medium", GRID_WIDTH, win)
hardButton = Button((BUTTON_START_X + 2*SMALL_WIDTH + 9, BUTTON_START_Y + LARGE_HEIGHT),
        SMALL_WIDTH, SMALL_HEIGHT, SMALL_FONT, "Hard", GRID_WIDTH, win)
checkBoardButton = Button((BUTTON_START_X, BUTTON_START_Y + LARGE_HEIGHT + SMALL_HEIGHT + GAP),
        LARGE_WIDTH, LARGE_HEIGHT, LARGE_FONT, "Check Board", GRID_WIDTH, win)
checkMoveButton = Button((BUTTON_START_X, BUTTON_START_Y + 2*LARGE_HEIGHT + SMALL_HEIGHT + 2*GAP),
        LARGE_WIDTH, LARGE_HEIGHT, LARGE_FONT, "Check Move", GRID_WIDTH, win)
solveButton = Button((BUTTON_START_X, BUTTON_START_Y + 3*LARGE_HEIGHT + SMALL_HEIGHT + 3*GAP),
        LARGE_WIDTH, LARGE_HEIGHT, LARGE_FONT, "Solve", GRID_WIDTH, win)
clearButton = Button((BUTTON_START_X, BUTTON_START_Y + 4*LARGE_HEIGHT + SMALL_HEIGHT + 4*GAP),
        LARGE_WIDTH, LARGE_HEIGHT, LARGE_FONT, "Clear", GRID_WIDTH, win)
示例#24
0
def main():
    '''
    Function containing the game loop, no returns or parameters. 
'''

    #Begins by loading the data from the data file
    with open(r"assets/data.json") as file:
        data = json.load(file)
        print(f"Information in settings: {data}")
        file.close()
    #if the window is set to fullscreen in the data, file create a fullscreen pygame window
    if data["resolution"] == [0, 0]:
        mainGame = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        resolution = pygame.display.get_window_size()
    else:
        resolution = data["resolution"]
        mainGame = pygame.display.set_mode(resolution)
    #scaling stores the scaling factor for the width of the screen and the length/height
    scaling = (resolution[0] / 1280, resolution[1] / 720)
    #world object is the surface that the game is rendered to
    world = pygame.Surface((1150, 720))
    player = Ball(world, (30, 360), ballColorIn=data["ballcolor"])
    clock = pygame.time.Clock()

    #gameState of 0 is the intro screen, following code setups the intro screen and and other variables in the game
    gameState = 0
    buttons = [
        Button("QUIT",
               textIn="QUIT",
               posIn=(700 * scaling[0], 500 * scaling[1])),
        Button("PLAY",
               textIn="Play",
               posIn=(500 * scaling[0], 500 * scaling[1])),
        Button("TUTORIAL",
               textIn="How to Play",
               posIn=(575 * scaling[0], 600 * scaling[1])),
        Button("SETTINGS",
               textIn="Settings",
               posIn=(1200 * scaling[0], 680 * scaling[1]),
               fontSizeIn=14)
    ]
    if data["highscore"] == -1:
        highScore = None
    else:
        highScore = data["highscore"]
    score = 0
    startTimer = 0
    #scales backgrounds to the screen resolution
    backgrounds = (pygame.transform.scale(
        pygame.image.load(r"assets/background.jpg"),
        pygame.display.get_window_size()),
                   pygame.transform.scale(
                       pygame.image.load(r"assets/backgroundTwo.jpg"),
                       pygame.display.get_window_size()))
    while True:
        ev = pygame.event.poll()
        if ev.type == pygame.QUIT or gameState == -1:
            #if the user clicks the x button or the gameState is -1, it breaks from the main loop and closes game
            break
        if gameState == 0:
            mainGame.blit(backgrounds[0], (0, 0))
            for button in buttons:
                if ev.type == pygame.MOUSEBUTTONDOWN:
                    if button.buttonHit() == "PLAY":
                        #if the player clicks the play button the gameState is set to 1.
                        #setsup map and buttons needed for the game, also creates a variable called starTimer which is used for the timer
                        gameState = 1
                        walls = generateMap(world)
                        mazeExit = walls[len(walls) - 1]
                        del walls[len(walls) - 1]
                        buttons = [
                            Button("QUIT",
                                   textIn="QUIT",
                                   posIn=(630 * scaling[0], 650 * scaling[1]))
                        ]
                        texts = [
                            TextBox(textIn="Score:",
                                    posIn=(1000 * scaling[0],
                                           100 * scaling[1])),
                            TextBox(textIn=f"{score}",
                                    posIn=(1000 * scaling[0],
                                           160 * scaling[1]))
                        ]
                        startTimer = time.time()
                        break
                    elif button.buttonHit() == "QUIT":
                        #gameState of -1 is the default gamestate which is called when the user clicks the quit button on any screen
                        gameState = -1
                        break
                    elif button.buttonHit() == "TUTORIAL":
                        #if the user clicks how to play, it opens a link to a google doc with instructions on how to play
                        webbrowser.open(
                            "https://docs.google.com/document/d/10sVfS0pjQY3BrWsw5jMPi9ZBJNQ-JpQf02bXztE-rAk/edit?usp=sharing"
                        )
                    elif button.buttonHit() == "SETTINGS":
                        #if the user clicks the settings button, then it sets up the setting screen (gameState = 3)
                        buttons = [
                            MultiButton(keyIn="RESOLUTION",
                                        textIn=("1280x720", "1920x1080",
                                                "Fullscreen"),
                                        posIn=(700 * scaling[0],
                                               350 * scaling[1])),
                            MultiButton(keyIn="BALLCOLOR",
                                        textIn=("Red", "Blue", "Green"),
                                        posIn=(700 * scaling[0],
                                               400 * scaling[1])),
                            Button("QUIT",
                                   textIn="QUIT",
                                   posIn=(630 * scaling[0], 650 * scaling[1])),
                            Button("BACK",
                                   textIn="Back",
                                   posIn=(200 * scaling[0], 650 * scaling[1])),
                            Button("RESET",
                                   textIn="Reset Settings and HighScore",
                                   posIn=(500 * scaling[0], 550 * scaling[1]))
                        ]
                        texts = [
                            TextBox(textIn="Resolution",
                                    textBoxColorIn=(30, 30, 30),
                                    posIn=(500 * scaling[0],
                                           350 * scaling[1])),
                            TextBox(textIn="Ball Color",
                                    textBoxColorIn=(30, 30, 30),
                                    posIn=(500 * scaling[0],
                                           400 * scaling[1])),
                            TextBox(textIn="Settings",
                                    textBoxColorIn=(30, 30, 30),
                                    fontSizeIn=40,
                                    posIn=(550 * scaling[0],
                                           100 * scaling[1])),
                            TextBox(textIn=
                                    "Restart Game for Changes to Take Effect",
                                    textBoxColorIn=(30, 30, 30),
                                    fontSizeIn=14,
                                    posIn=(500 * scaling[0], 200 * scaling[1]))
                        ]
                        gameState = 3
                button.draw(mainGame)
        elif gameState == 1:
            #this gamestate is for when the user is actually playing the game
            #fills the background for the world and blits the background for the display surface
            world.fill((255, 255, 255))
            mainGame.blit(backgrounds[0], (0, 0))

            #depending on which direction the player wants to move in, it checks if the player is allowed to move in that direction
            #if yes, then it moves the player in that direction.
            keyPressed = pygame.key.get_pressed()
            if keyPressed[pygame.K_w]:
                if permissionToMove("UP", walls, player.getPoints()):
                    player.moveUp()
            if keyPressed[pygame.K_s]:
                if permissionToMove("DOWN", walls, player.getPoints()):
                    player.moveDown()
            if keyPressed[pygame.K_a]:
                if permissionToMove("LEFT", walls, player.getPoints()):
                    player.moveLeft()
            if keyPressed[pygame.K_d]:
                if permissionToMove("RIGHT", walls, player.getPoints()):
                    player.moveRight()
            if (mazeExit.pos[0] <= player.pos[0] <=
                (mazeExit.pos[0] + mazeExit.wallDimensions[0])
                    and mazeExit.pos[1] <= player.pos[1] <=
                (mazeExit.pos[1] + mazeExit.wallDimensions[1])):
                #if the player goes into the maze exit, it setsup the win screen (gameState = 2)
                gameState = 2
                score = round((time.time() - startTimer) * 100) / 100
                if highScore == None or score < highScore:
                    #if the highscore is not set yet or if the score is less than high score then it updates the highscore
                    #also saves highscore to file
                    highScore = score
                    data["highscore"] = highScore
                    with open(r"assets/data.json", "w") as file:
                        json.dump(data, file)
                        file.close()

                buttons = [
                    Button("QUIT",
                           textIn="QUIT",
                           posIn=(620 * scaling[0], 650 * scaling[1])),
                    Button("PLAY",
                           textIn="Play Again",
                           posIn=(600 * scaling[0], 500 * scaling[1]))
                ]
                texts = [
                    TextBox(textIn="You Win!",
                            fontSizeIn=40,
                            posIn=(560 * scaling[0], 150 * scaling[1])),
                    TextBox(textIn="Your score is:",
                            fontSizeIn=20,
                            posIn=(525 * scaling[0], 300 * scaling[1])),
                    TextBox(textIn=f"{score}",
                            fontSizeIn=20,
                            posIn=(700 * scaling[0], 300 * scaling[1])),
                    TextBox(textIn="Your highscore is:",
                            fontSizeIn=14,
                            posIn=(545 * scaling[0], 400 * scaling[1])),
                    TextBox(textIn=f"{highScore}",
                            fontSizeIn=14,
                            posIn=(700 * scaling[0], 400 * scaling[1]))
                ]
                continue
            if ev.type == pygame.MOUSEBUTTONDOWN and buttons[0].buttonHit(
            ) == "QUIT":
                gameState = -1
            #draws all elements on screen
            mazeExit.drawWall()
            player.drawBall()
            for wall in walls:
                wall.drawWall()
            buttons[0].draw(mainGame)
            for text in texts:
                text.draw(mainGame)
            score = round((time.time() - startTimer) * 100) / 100
            texts[1].changeText(score)
            #This is where the camera is created
            #The camera works by creating a surface, and blitting a small portion of the rendered world
            #to the camera surface, then blitting the camera surface onto the main display surface
            camera = pygame.Surface((100, 100))
            camera.blit(world, (0, 0),
                        (player.pos[0] - 50, player.pos[1] - 50, 100, 100))
            camera = pygame.transform.scale(
                camera, (round(500 * scaling[0]), round(500 * scaling[1])))
            mainGame.blit(camera, (390 * scaling[0], 110 * scaling[1]))
        elif gameState == 2:
            #gamestate for the win screen
            mainGame.blit(backgrounds[1], (0, 0))
            for button in buttons:
                button.draw(mainGame)
                if ev.type == pygame.MOUSEBUTTONDOWN:
                    if button.buttonHit() == "QUIT":
                        gameState = -1
                        break
                    if button.buttonHit() == "PLAY":
                        #sets the game up again if the user wants to play again
                        gameState = 1
                        walls = generateMap(world)
                        mazeExit = walls[len(walls) - 1]
                        del walls[len(walls) - 1]
                        buttons = [
                            Button("QUIT",
                                   textIn="QUIT",
                                   posIn=(630 * scaling[0], 650 * scaling[1]))
                        ]
                        texts = [
                            TextBox(textIn="Score:",
                                    posIn=(1000 * scaling[0],
                                           100 * scaling[1])),
                            TextBox(textIn=f"{score}",
                                    posIn=(1000 * scaling[0],
                                           160 * scaling[1]))
                        ]
                        player.setPos((30, 360))
                        startTimer = time.time()
            for text in texts:
                text.draw(mainGame)
        elif gameState == 3:
            #gameState for the settings screen
            mainGame.blit(backgrounds[1], (0, 0))
            for button in buttons:
                button.draw(mainGame)
                if ev.type == pygame.MOUSEBUTTONDOWN:
                    if button.buttonHit() == "RESOLUTION":
                        #if the user clicks on the resolution button, it cycles to the next text in the multibutton,
                        #then it stores the selected resolution into the json file
                        #restarting the game is needed to changes to take effect
                        button.changeState()
                        if button.getText() == "1280x720":
                            data["resolution"] = [1280, 720]
                        elif button.getText() == "1920x1080":
                            data["resolution"] = [1920, 1080]
                        elif button.getText() == "Fullscreen":
                            data["resolution"] = [0, 0]
                        with open(r"assets/data.json", "w") as file:
                            json.dump(data, file)
                            file.close()
                    elif button.buttonHit() == "BALLCOLOR":
                        #if the user clicks on the ballcolor button, it cycles to the next option in the multibutton
                        #stores the color into the json file
                        button.changeState()
                        if button.getText() == "Red":
                            data["ballcolor"] = [255, 0, 0]
                        elif button.getText() == "Green":
                            data["ballcolor"] = [0, 255, 0]
                        elif button.getText() == "Blue":
                            data["ballcolor"] = [0, 0, 255]
                        with open(r"assets/data.json", "w") as file:
                            json.dump(data, file)
                            file.close()
                    elif button.buttonHit() == "RESET":
                        #if the user clicks the reset button, it resets all the data in the data file back to original settings
                        #and clears highscore
                        data["resolution"] = [1280, 720]
                        data["highscore"] = -1
                        data["ballcolor"] = [255, 0, 0]
                        with open(r"assets/data.json", "w") as file:
                            json.dump(data, file)
                            file.close()
                    elif button.buttonHit() == "QUIT":
                        gameState = -1
                        break
                    elif button.buttonHit() == "BACK":
                        gameState = 0
                        buttons = [
                            Button("QUIT",
                                   textIn="QUIT",
                                   posIn=(700 * scaling[0], 500 * scaling[1])),
                            Button("PLAY",
                                   textIn="Play",
                                   posIn=(500 * scaling[0], 500 * scaling[1])),
                            Button("TUTORIAL",
                                   textIn="How to Play",
                                   posIn=(575 * scaling[0], 600 * scaling[1])),
                            Button("SETTINGS",
                                   textIn="Settings",
                                   posIn=(1200 * scaling[0], 680 * scaling[1]),
                                   fontSizeIn=14)
                        ]
            for text in texts:
                text.draw(mainGame)
        #framerate
        clock.tick(60)
        mainGame.blit(updateFps(clock), (0, 0))
        pygame.display.update()
    pygame.quit()
示例#25
0
board = board
rolled = 0
nop = 0
roll = diceCount = times = 0
dice1, dice2 = 1, 2
isEnd = endTurn = isPay = isRoll = isBank = False
isSpin = isChance = isComm = True
players = [None] * 4
playerButton = []
turn = 0
isTrade = True
isBuild = isMort = isUnmort = False
isBuilding = isTrading = isMorting = isUnmorting = False
clock = pygame.time.Clock()

startButton = Button((0, 0, 255), 250, 375, 100, 50, 35, 'START')
twoButton = Button((0, 0, 255), 133.75, 400, 75, 40, 30, 'TWO')
threeButton = Button((0, 0, 255), 262.5, 400, 75, 40, 30, 'THREE')
fourButton = Button((0, 0, 255), 391.25, 400, 75, 40, 30, 'FOUR')
tradeButton = Button((255, 255, 0), 88, 90, 100, 30, 20, 'TRADE')
buildButton = Button((255, 255, 0), 196, 90, 100, 30, 20, 'BUILD')
mortButton = Button((255, 255, 0), 304, 90, 100, 30, 20, 'MORTGAGE')
unmortButton = Button((255, 255, 0), 412, 90, 100, 30, 20, 'UNMORTGAGE')
doneButton = Button((0, 0, 255), 410, 480, 100, 30, 30, 'DONE')
spinButton = Button((0, 0, 255), 250, 375, 100, 50, 35, 'SPIN')
spinAgainButton = Button((0, 0, 255), 250, 375, 100, 50, 25, 'SPIN AGAIN')
buyButton = Button((0, 0, 255), 150, 350, 125, 35, 25, 'BUY FOR ')
ignoreButton = Button((0, 0, 255), 150, 400, 125, 35, 25, 'IGNORE')
endTurnButton = Button((0, 0, 255), 415, 490, 100, 25, 25, 'END TURN')
rollJailButton = Button((0, 0, 255), 238, 400, 125, 35, 25, 'ROLL')
payJailButton = Button((0, 0, 255), 238, 450, 125, 35, 25, 'PAY 100 M')
示例#26
0
 def __init__(self, gm):
     super().__init__()
     self.resume_button = Button(50, 100, 200, 50, "Resume", gm)
     self.mainmenu_button = Button(50, 200, 200, 50, "Main Menu", gm)
示例#27
0
# Game variables
walls = []
rays = []
drawing = False
wall_starting_pos = (0, 0)
play = False
carryOn = True
clock = pygame.time.Clock()
givenangle = 3
prev = False

# --- INITIAL SETUP ---

# Buttons
resetButton = Button(size[0]-menuSize[0]+10,10, 70, 25, 'Reset', RED)
playButton = Button(size[0]-menuSize[0]+10, resetButton.y+10+resetButton.height, 70, 25, 'Play', GREEN)

#Text box
font1 = pygame.font.Font('freesansbold.ttf', 15)
text1 = font1.render('Angle(in degrees):',True,WHITE,None)
textRect = text1.get_rect()
textRect.center = (boundarySpacing+70,50)
text2 = font1.render('Range of rays(0-250m):',True,WHITE,None)
text2Rect = text2.get_rect()
text2Rect.center = (boundarySpacing+90,textRect.centery+50)
input_box = InputBox(textRect.right+10, boundarySpacing+10, 60, 32)
input_box2 = InputBox(text2Rect.right+10,80,60,32)
input_boxes = [input_box,input_box2]
#Text box for graph edges in x axis
graphbox1 = font1.render('0 m ',True,WHITE,None)
示例#28
0
    while ins_run:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                ins_run = False
                menu()

        instructions_win.blit(instructions_image, (0, 0))
        pygame.display.update()


def create_main_win():
    global main_win
    main_win = pygame.display.set_mode((1200, 750))


try_again_button = Button((100, 230, 53), 0, 0, 150, 40, "Try again", 36)
play_button = Button((255, 255, 255), 170, 150, 300, 75, 'PLAY!', 72)
easy_diff = Button((98, 253, 135), 10, 400, 150, 42, 'EASY', 40)
normal_diff = Button((0, 179, 255), 170, 400, 150, 42, 'NORMAL', 40)
hard_diff = Button((255, 222, 0), 330, 400, 150, 42, 'HARD', 40)
master_diff = Button((225, 0, 77), 490, 400, 150, 42, 'MASTER', 40)
ins_button = Button((255, 255, 255), 600, 5, 45, 45, '?', 30)


def menu():

    global running
    global DracoVel
    global SnitchSpeed
    global BludgerX_change
示例#29
0
import draw_game
from classes import Button
from variable import color
from helper_functions import speak, display
import pygame as pg
from pyautogui import size

pg.init()

bgcolor = color['black']
screen = display("Mahala's Games", size(), bgcolor, fullscreen=True)

width, height = size()
clock = pg.time.Clock()

n2p_button = Button(color['green'], 25, 100, 400, 75, text='Name 2 Person')
r2p_button = Button(color['yellow'],
                    25,
                    200,
                    450,
                    75,
                    text='Relationship 2 Person')
ng_button = Button(color['blue'], 25, 300, 400, 75, text='Name Guessing')
draw_button = Button(color['magenta'], 25, 400, 400, 75, text='Drawing Fun')
quit_button = Button(color['red'], (width - 300), (height - 150),
                     200,
                     75,
                     text='Quit')

playing = True
示例#30
0
    '\"Pi Calculator\"?')  # Sets the text at the top of the window

# Screen dimensions/pygame screen creation
dimensions = screenW, screenH = 1024, 576
screen = pygame.display.set_mode(dimensions)

# Global for timesteps/frame
timesteps = 15000

# Text/button objects
prompt = Text("Digits of pi to calculate: ", "Prototype.ttf", 32, screenW / 3,
              screenH / 2)
textbox = InputBox(screenW / 3 * 2, screenH / 2, 180, 40, "Prototype.ttf", 32)
prompt2 = Text("Press ENTER to start", "Prototype.ttf", 16,
               textbox.box.x + textbox.box.width / 2, textbox.box.y + 50)
menuButton = Button(screenW - 80, 5, 75, 30, "Menu", "Prototype.ttf", 16)
quitButton = Button(screenW / 2 - 75 / 2, 5, 75, 30, "Quit", "Prototype.ttf",
                    16)
count = Count("Prototype.ttf", 32, 5, 5)

# "Props"
floor = Floor(screenH - 50, screenW, screenH)
small = Square(x=screenW / 5, y=screenH - 50, width=50, mass=1)
large = Square(x=screenW / 2,
               y=screenH - 50,
               width=100,
               mass=1,
               vel=-1 / timesteps)


# Displays the main menu, where the game doesn't update and the user picks how many digits of pi to find