コード例 #1
0
    def __init__(self,
                 width,
                 height,
                 x,
                 y,
                 fontName='arial',
                 fontSize=20,
                 fontColor=(0, 0, 0),
                 background=(255, 255, 255)):
        self.width = width
        #self.height = height
        self.x = x
        self.y = y
        self.text = ''
        self.fontName = fontName
        self.fontSize = fontSize
        self.fontColor = fontColor
        self.textLabel = TextLabel(self.text, self.x + 5, self.y + 2.5,
                                   self.fontName, self.fontSize,
                                   self.fontColor)
        self.height = self.textLabel.getHeight() + 5
        self.surface = pygame.Surface([self.width, self.height])
        self.rect = self.surface.get_rect(x=self.x, y=self.y)
        pygame.draw.rect(self.surface, (143, 142, 160),
                         (0, 0, self.width, self.height))  # frame
        pygame.draw.rect(self.surface, background,
                         (2, 2, self.width - 4,
                          self.height - 4))  # white board in grey frame

        self.textLabelFlag = True
コード例 #2
0
 def generate_text(self):
     textLabel = TextLabel(
         int(self.height*0.7),
         (self.x + (self.width/2), self.y + (self.height/2)),
         self.text,
         self.surface)
     textLabel.show()
コード例 #3
0
    def __init__(self, data, color_mapping):
        super(BeatMatchDisplay, self).__init__()
        self.objects = set()
        self.paused = True
        self.color_mapping = color_mapping

        self.gem_data = data.get_gems()
        self.bar_data = data.get_bars()

        self.time = 0

        self.anim_group = AnimGroup()
        self.add(self.anim_group)

        self.diagrams = []
        # creates gems
        self.gems = []
        cur_chord = None
        cur_display = None
        last_time = None
        for gem_info in self.gem_data:
            gem = GemDisplay(gem_info, self.color_mapping)
            self.gems.append(gem)
            #self.add(gem)

            if cur_chord != gem_info[1]:
                if cur_display:
                    cur_display.set_next(gem_info[0])
                cur_chord = gem_info[1]
                cur_display = ChordDisplay(gem_info[1], gem_info[0],
                                           self.color_mapping[cur_chord])
                self.diagrams.append(cur_display)
                #self.add(cur_display)

            last_time = gem_info[0]

        # creates bars
        self.bars = []
        for bar_info in self.bar_data:
            bar = BarDisplay(bar_info)
            self.bars.append(bar)
            #self.add(bar)

        # creates buttons
        pos = (100, nowbar_height)

        self.button = ButtonDisplay(pos)

        self.add(self.button)

        self.score_label = TextLabel("Score: 0",
                                     pos=(Window.width / 2 - 125,
                                          Window.height - 100),
                                     font=40)
        self.add(self.score_label)
コード例 #4
0
    def __init__(self, choose_song):
        super(MainMenuDisplay, self).__init__()
        self.label = TextLabel(
            text="Click on a song to select it, and press ENTER to confirm",
            pos=(0, 0),
            font=Window.height / 30)
        self.add(self.label)
        self.buttons = []
        self.choose_song = choose_song
        x = Window.width - 1 / 6 * Window.width
        y = 200
        i = 0
        label = CoreLabel(text="CHOOSE A SONG", font_size=Window.height / 10)
        label.refresh()
        text = label.texture

        title = Rectangle(texture=text,
                          pos=(Window.width / 2 - text.size[0] / 2,
                               Window.height * 3 / 4),
                          size=text.size)
        self.add(title)
        for song in songs:
            button = SongButtons(y=y,
                                 song=song,
                                 start_end=start_end[i],
                                 key=keys[i])
            self.buttons.append(button)
            self.add(button)
            i += 1
            y += Window.height / 7
コード例 #5
0
ファイル: App.py プロジェクト: Macias118/Blackjack
    def generate_gameboard(self):
        self.app_objects = []
        t = TextLabel(40, (self.window_width / 2, self.window_height * 0.05),
                      "Welcome!", self._display_surf)
        self.app_objects.append(t)

        card = Card((50, 100), self._display_surf, 'S', 'A')
        self.app_objects.append(card)
コード例 #6
0
 def wrong(self):
     self.change_bg((1, 0, 0))
     self.anim.add(
         TextLabel("Incorrect, try again!",
                   pos=(400, 200),
                   font=100,
                   align='center',
                   color=Color(1, 0, 0),
                   anim=KFAnim((0, 40), (1.5, 60), (1.7, 0))))
コード例 #7
0
    def listenKeyboardEvents(self):
        for event in pygame.event.get():
            if event.type == pygame.locals.QUIT:
                pygame.quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_BACKSPACE:
                    self.text = self.text[:
                                          -1]  # removing last char from string and replacing it with former
                    print('BACKSPACE!')
                elif event.key == pygame.K_RETURN:  # K_RETURN is an 'big' enter key name
                    if self.text is not '':
                        return True, True
                else:
                    char = event.unicode
                    self.text += char

                self.textLabel = TextLabel(self.text, self.x + 5, self.y + 2.5,
                                           self.fontName, self.fontSize,
                                           self.fontColor)
        return False, False
コード例 #8
0
    def show_options(self, chord, color):
        if self.move_on:
            self.remove(self.move_on)
            self.move_on = None
        self.options.add(chord)
        # print(self.allchords)
        # print("ALL CHORDS")

        while len(self.options) < 3:
            self.options.add(random.choice(self.allchords))

        x = 70
        y = Window.height / 2

        if self.label is None:
            self.label = TextLabel(
                "Which chord is the %s chord?  Strum the correct chord to move on."
                % color,
                pos=(x, y - 50),
                font=20,
                color=Color(*to_rgb[color]))
            self.add(self.label)
        else:
            self.label.update_text(
                "Which chord is the %s chord?  Strum the correct chord to move on."
                % color, to_rgb[color])
        self.diags = []
        # self.diag_labels = []
        for option in self.options:
            # label = TextLabel(option, pos=(x,y - 50), font= 20)
            # self.add(self.label)
            # self.diag_labels.append(label)

            diag = ChordDiagram(self.diagramHeight, (x, y),
                                chord=option,
                                color=self.color_mapping[chord])
            x += self.diagramWidth + self.diagramWidth / 2
            self.add(diag)
            self.optiondiags.append(diag)
            self.diags.append(diag)
コード例 #9
0
    def correct(self, chord, right):
        self.change_bg((0, 1, 0))
        self.anim.add(
            TextLabel("Correct!",
                      pos=(400, 200),
                      font=100,
                      align='center',
                      color=Color(0, 1, 0),
                      anim=KFAnim((0, 40), (1, 60), (1.2, 0))))

        if chord not in self.chords and right:
            self.draw_chord(chord)
            self.chords.append(chord)
コード例 #10
0
    def __init__(self, return_to_menu, replay_song, quit_app):
        super(EndMenuDisplay, self).__init__()
        self.label = TextLabel(
            "You finished the song!  What would you like to do next?",
            pos=(Window.width / 2, Window.height * 3 / 4),
            font=Window.height / 30,
            align='center')
        self.add(self.label)

        self.menu = GeneralButton(Window.height * 1 / 3, "Return to Main Menu",
                                  return_to_menu)
        self.add(self.menu)

        self.replay = GeneralButton(Window.height * 10 / 21, "Replay Song",
                                    replay_song)
        self.add(self.replay)

        self.quit = GeneralButton(Window.height * 13 / 21, "Quit", quit_app)
        self.add(self.quit)

        self.buttons = [self.menu, self.replay, self.quit]
コード例 #11
0
    def setGUI(self, whichGUI):
        self.TextFieldLabels.clear()
        if whichGUI is 0:
            triangleText = TextLabel('TRIANGLE', 0, 0, 'comic', 80,
                                     (255, 255, 255))
            triangleText.setPosition(
                self.width / 2 - triangleText.getWidth() / 2, 100)
            self.TextFieldLabels.append(triangleText)

            invadersText = TextLabel('INVADERS', 0, 0, 'comic', 80,
                                     (255, 255, 255))
            invadersText.setPosition(
                self.width / 2 - invadersText.getWidth() / 2,
                triangleText.getPosition()[1] + triangleText.getHeight())
            self.TextFieldLabels.append(invadersText)

            gameText = TextLabel('GAME', 0, 0, 'comic', 80, (255, 255, 255))
            gameText.setPosition(
                self.width / 2 - gameText.getWidth() / 2,
                invadersText.getPosition()[1] + invadersText.getHeight())
            self.TextFieldLabels.append(gameText)

            enter = TextLabel('Please enter your name', 0, 0, 'comic', 30,
                              (255, 255, 255))
            enter.setPosition(
                self.width / 2 - enter.getWidth() / 2,
                gameText.getPosition()[1] + gameText.getHeight() * 2)
            self.TextFieldLabels.append(enter)

            self.textBoxEnter = TextBox(
                triangleText.getWidth(), None,
                self.width / 2 - triangleText.getWidth() / 2,
                enter.getPosition()[1] + enter.getHeight() * 2)

            # checkbox info here
        elif whichGUI is 1 or whichGUI is 2:
            gameOver = TextLabel('GAME OVER!', 0, 0, 'comic', 80,
                                 (255, 255, 255))
            gameOver.setPosition(self.width / 2 - gameOver.getWidth() / 2, 100)
            self.TextFieldLabels.append(gameOver)

            score = TextLabel('Your score: {}'.format(self.level), 0, 0,
                              'comic', 80, (255, 255, 255))
            score.setPosition(self.width / 2 - score.getWidth() / 2,
                              gameOver.getPosition()[1] + gameOver.getHeight())
            self.TextFieldLabels.append(score)

            if whichGUI is 2:
                pressSpace = TextLabel('Press SPACE to restart game', 0, 0,
                                       'comic', 50, (255, 255, 255))
                pressSpace.setPosition(
                    self.width / 2 - pressSpace.getWidth() / 2,
                    self.height / 2)
                self.TextFieldLabels.append(pressSpace)

                pressTab = TextLabel('Hold TAB to see best scores', 0, 0,
                                     'comic', 50, (255, 255, 255))
                pressTab.setPosition(
                    self.width / 2 - pressTab.getWidth() / 2,
                    pressSpace.getPosition()[1] + pressSpace.getHeight() * 2)
                self.TextFieldLabels.append(pressTab)
        elif whichGUI is 3:
            bestScores = TextLabel('BEST SCORES:', 0, 0, 'comic', 60,
                                   (255, 255, 255))
            bestScores.setPosition(self.width / 2 - bestScores.getWidth() / 2,
                                   50)
            self.TextFieldLabels.append(bestScores)

            # connecting to database and reading TOP 10 scores!
            self.db.connect()
            rows = self.db.getTop10('scoresTable')
            self.db.close()
            fakeName = TextLabel(str(rows[0][1]), 0, 0, 'comic', 30,
                                 (255, 255, 255))
            fakeName.setPosition(
                bestScores.getPosition()[0],
                bestScores.getPosition()[1] + bestScores.getHeight() * 2)
            self.TextFieldLabels.append(fakeName)

            fakeScore = TextLabel(str(rows[0][2]), 0, 0, 'comic', 30,
                                  (255, 255, 255))
            fakeScore.setPosition(
                bestScores.getPosition()[0] + bestScores.getWidth() -
                fakeScore.getWidth(),
                bestScores.getPosition()[1] + bestScores.getHeight() * 2)
            self.TextFieldLabels.append(fakeScore)
            for x in range(1, len(rows)):
                previousName = fakeName
                previousScore = fakeScore
                fakeName = TextLabel(str(rows[x][1]), 0, 0, 'comic', 30,
                                     (255, 255, 255))
                fakeName.setPosition(
                    bestScores.getPosition()[0],
                    previousName.getPosition()[1] +
                    previousName.getHeight() * 2)
                self.TextFieldLabels.append(fakeName)

                fakeScore = TextLabel(str(rows[x][2]), 0, 0, 'comic', 30,
                                      (255, 255, 255))
                fakeScore.setPosition(
                    bestScores.getPosition()[0] + bestScores.getWidth() -
                    fakeScore.getWidth(),
                    previousScore.getPosition()[1] +
                    previousScore.getHeight() * 2)
                self.TextFieldLabels.append(fakeScore)
コード例 #12
0
class TextBox:
    def __init__(self,
                 width,
                 height,
                 x,
                 y,
                 fontName='arial',
                 fontSize=20,
                 fontColor=(0, 0, 0),
                 background=(255, 255, 255)):
        self.width = width
        #self.height = height
        self.x = x
        self.y = y
        self.text = ''
        self.fontName = fontName
        self.fontSize = fontSize
        self.fontColor = fontColor
        self.textLabel = TextLabel(self.text, self.x + 5, self.y + 2.5,
                                   self.fontName, self.fontSize,
                                   self.fontColor)
        self.height = self.textLabel.getHeight() + 5
        self.surface = pygame.Surface([self.width, self.height])
        self.rect = self.surface.get_rect(x=self.x, y=self.y)
        pygame.draw.rect(self.surface, (143, 142, 160),
                         (0, 0, self.width, self.height))  # frame
        pygame.draw.rect(self.surface, background,
                         (2, 2, self.width - 4,
                          self.height - 4))  # white board in grey frame

        self.textLabelFlag = True

    def getWidth(self):
        return self.width

    def getHeight(self):
        return self.height

    def drawOn(self, surface):
        surface.blit(self.surface, self.rect)
        surface.blit(self.textLabel.textLabel, self.textLabel.rect)

    def getRect(self):
        return self.rect

    def setPosition(self, x, y):
        self.x = x
        self.y = y
        # when I want to change the position i need to override the rect property
        self.rect = self.surface.get_rect(x=self.x, y=self.y)

    def getPosition(self):
        return self.x, self.y

    def getText(self):
        return self.text

    def listenKeyboardEvents(self):
        for event in pygame.event.get():
            if event.type == pygame.locals.QUIT:
                pygame.quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_BACKSPACE:
                    self.text = self.text[:
                                          -1]  # removing last char from string and replacing it with former
                    print('BACKSPACE!')
                elif event.key == pygame.K_RETURN:  # K_RETURN is an 'big' enter key name
                    if self.text is not '':
                        return True, True
                else:
                    char = event.unicode
                    self.text += char

                self.textLabel = TextLabel(self.text, self.x + 5, self.y + 2.5,
                                           self.fontName, self.fontSize,
                                           self.fontColor)
        return False, False
コード例 #13
0
class BeatMatchDisplay(InstructionGroup):
    def __init__(self, data, color_mapping):
        super(BeatMatchDisplay, self).__init__()
        self.objects = set()
        self.paused = True
        self.color_mapping = color_mapping

        self.gem_data = data.get_gems()
        self.bar_data = data.get_bars()

        self.time = 0

        self.anim_group = AnimGroup()
        self.add(self.anim_group)

        self.diagrams = []
        # creates gems
        self.gems = []
        cur_chord = None
        cur_display = None
        last_time = None
        for gem_info in self.gem_data:
            gem = GemDisplay(gem_info, self.color_mapping)
            self.gems.append(gem)
            #self.add(gem)

            if cur_chord != gem_info[1]:
                if cur_display:
                    cur_display.set_next(gem_info[0])
                cur_chord = gem_info[1]
                cur_display = ChordDisplay(gem_info[1], gem_info[0],
                                           self.color_mapping[cur_chord])
                self.diagrams.append(cur_display)
                #self.add(cur_display)

            last_time = gem_info[0]

        # creates bars
        self.bars = []
        for bar_info in self.bar_data:
            bar = BarDisplay(bar_info)
            self.bars.append(bar)
            #self.add(bar)

        # creates buttons
        pos = (100, nowbar_height)

        self.button = ButtonDisplay(pos)

        self.add(self.button)

        self.score_label = TextLabel("Score: 0",
                                     pos=(Window.width / 2 - 125,
                                          Window.height - 100),
                                     font=40)
        self.add(self.score_label)

    def set_player(self, player):
        self.player = player

    def reset(self):
        for gem in self.gems:
            gem.reset()

        for object in self.gems + self.bars + self.diagrams:
            object.added = False
            object.removed = False

    # called by Player. Causes the right thing to happen
    def gem_hit(self, gem_idx):
        self.gems[gem_idx].on_hit()

    # called by Player. Causes the right thing to happen
    def gem_pass(self, gem_idx):
        self.gems[gem_idx].on_pass()

    # called by Player. Causes the right thing to happen
    def on_button_down(self, color, hit):
        self.button.on_down(color, hit)

    # called by Player. Causes the right thing to happen
    def on_button_up(self):
        self.button.on_up()

    # call every frame to make gems and barlines flow down the screen
    def on_update(self, time):
        dt = time - self.time
        self.time = time
        continue_flag = True
        for object in self.gems + self.bars + self.diagrams:
            #object.on_update(time)
            if not object.removed:
                flag = object.on_update(time)
                if isinstance(flag, bool):
                    continue_flag = flag

            if object.on_screen and not object.added:
                self.add(object)
                self.objects.add(object)
                object.added = True
            elif object.added and not object.removed and not object.on_screen:
                self.remove(object)
                self.objects.remove(object)
                object.removed = True

        for object in self.objects | {self.button}:
            if self.paused:
                object.darken()
            else:
                object.brighten()

        self.anim_group.on_update()

        self.button.on_update(dt)
        self.score_label.update_text("Score: " + str(self.player.get_score()),
                                     (1, 1, 1))
        return continue_flag

    def toggle(self):
        self.paused = not self.paused
コード例 #14
0
    def __init__(self, color_mapping, data, controller, start, end, key):
        super(ChordMatchDisplay, self).__init__()
        self.key = key
        self.diags = []
        self.label = None

        self.color_mapping = color_mapping
        self.data = data
        self.controller = controller
        self.start = start
        self.end = end

        self.chords = []
        self.diagrams = []
        self.diagramWidth = Window.width / (len(self.color_mapping) + 1)
        self.diagramHeight = self.diagramWidth / 1.6
        self.x = 70
        self.y = 0

        self.progress_bar = ProgressBar(self.data.get_sections(), start, end,
                                        self.color_mapping, self.controller)
        self.add(self.progress_bar)
        self.chord_order = self.progress_bar.chord_order

        # Text Labels
        self.color = Color(1, 1, 1)
        self.add(self.color)
        self.instrucions1 = TextLabel(
            "Each colored section in the bar above represents a different chord.  Press P to play/pause the song!",
            pos=(50, 475),
            font=15,
            color=Color(1, 1, 1))
        self.add(self.instrucions1)
        self.instructions2 = TextLabel(
            "Press R to replay the current section!",
            pos=(50, 450),
            font=15,
            color=Color(1, 1, 1))
        self.add(self.instructions2)
        self.instrucions1 = TextLabel(
            "Click anywhere on the bar to set the cursor. This song is in %s."
            % self.key,
            pos=(50, 425),
            font=15,
            color=Color(1, 1, 1))
        self.add(self.instrucions1)

        self.move_on = TextLabel(
            "When you are ready, press the space bar to guess the chords in the song!",
            pos=(50, 375),
            font=15,
            color=Color(1, 1, 1))
        self.add(self.move_on)

        self.anim = AnimGroup()
        self.add(self.anim)

        self.options = set()
        self.optiondiags = []
        self.allchords = [
            'G', 'A', 'am', 'bm', 'C', 'D', 'D7', 'em', 'Fmaj7', 'em7'
        ]
コード例 #15
0
class ChordMatchDisplay(InstructionGroup):
    def __init__(self, color_mapping, data, controller, start, end, key):
        super(ChordMatchDisplay, self).__init__()
        self.key = key
        self.diags = []
        self.label = None

        self.color_mapping = color_mapping
        self.data = data
        self.controller = controller
        self.start = start
        self.end = end

        self.chords = []
        self.diagrams = []
        self.diagramWidth = Window.width / (len(self.color_mapping) + 1)
        self.diagramHeight = self.diagramWidth / 1.6
        self.x = 70
        self.y = 0

        self.progress_bar = ProgressBar(self.data.get_sections(), start, end,
                                        self.color_mapping, self.controller)
        self.add(self.progress_bar)
        self.chord_order = self.progress_bar.chord_order

        # Text Labels
        self.color = Color(1, 1, 1)
        self.add(self.color)
        self.instrucions1 = TextLabel(
            "Each colored section in the bar above represents a different chord.  Press P to play/pause the song!",
            pos=(50, 475),
            font=15,
            color=Color(1, 1, 1))
        self.add(self.instrucions1)
        self.instructions2 = TextLabel(
            "Press R to replay the current section!",
            pos=(50, 450),
            font=15,
            color=Color(1, 1, 1))
        self.add(self.instructions2)
        self.instrucions1 = TextLabel(
            "Click anywhere on the bar to set the cursor. This song is in %s."
            % self.key,
            pos=(50, 425),
            font=15,
            color=Color(1, 1, 1))
        self.add(self.instrucions1)

        self.move_on = TextLabel(
            "When you are ready, press the space bar to guess the chords in the song!",
            pos=(50, 375),
            font=15,
            color=Color(1, 1, 1))
        self.add(self.move_on)

        self.anim = AnimGroup()
        self.add(self.anim)

        self.options = set()
        self.optiondiags = []
        self.allchords = [
            'G', 'A', 'am', 'bm', 'C', 'D', 'D7', 'em', 'Fmaj7', 'em7'
        ]

    def show_options(self, chord, color):
        if self.move_on:
            self.remove(self.move_on)
            self.move_on = None
        self.options.add(chord)
        # print(self.allchords)
        # print("ALL CHORDS")

        while len(self.options) < 3:
            self.options.add(random.choice(self.allchords))

        x = 70
        y = Window.height / 2

        if self.label is None:
            self.label = TextLabel(
                "Which chord is the %s chord?  Strum the correct chord to move on."
                % color,
                pos=(x, y - 50),
                font=20,
                color=Color(*to_rgb[color]))
            self.add(self.label)
        else:
            self.label.update_text(
                "Which chord is the %s chord?  Strum the correct chord to move on."
                % color, to_rgb[color])
        self.diags = []
        # self.diag_labels = []
        for option in self.options:
            # label = TextLabel(option, pos=(x,y - 50), font= 20)
            # self.add(self.label)
            # self.diag_labels.append(label)

            diag = ChordDiagram(self.diagramHeight, (x, y),
                                chord=option,
                                color=self.color_mapping[chord])
            x += self.diagramWidth + self.diagramWidth / 2
            self.add(diag)
            self.optiondiags.append(diag)
            self.diags.append(diag)

    def on_update_diagram(self, string, fret):
        # print(string)
        # print(fret)
        for diag in self.diags:
            diag.on_update(string, fret)

    def remove_options(self):
        self.options = set()
        for option in self.optiondiags:
            self.remove(option)
        self.optiondiags.clear()

    def draw_chord(self, chord):
        if self.x >= Window.width - self.diagramHeight:
            self.y += self.diagramHeight + 20
            self.x = 70
        diag = ChordDiagram(self.diagramHeight, (self.x, self.y),
                            chord=chord,
                            color=self.color_mapping[chord])
        self.add(diag)
        self.diagrams.append(diag)
        self.x += self.diagramWidth + self.diagramWidth / (
            len(self.color_mapping) - 1)

    #what happens when a note is correct, called by ChordPlayer
    def correct(self, chord, right):
        self.change_bg((0, 1, 0))
        self.anim.add(
            TextLabel("Correct!",
                      pos=(400, 200),
                      font=100,
                      align='center',
                      color=Color(0, 1, 0),
                      anim=KFAnim((0, 40), (1, 60), (1.2, 0))))

        if chord not in self.chords and right:
            self.draw_chord(chord)
            self.chords.append(chord)

    #What happens when a chord is incorrect, called by Chord Player
    def wrong(self):
        self.change_bg((1, 0, 0))
        self.anim.add(
            TextLabel("Incorrect, try again!",
                      pos=(400, 200),
                      font=100,
                      align='center',
                      color=Color(1, 0, 0),
                      anim=KFAnim((0, 40), (1.5, 60), (1.7, 0))))

    #changes background to current color
    def change_bg(self, color):
        self.color.s = 1
        self.color.rgb = color

    def on_update(self, frame):
        #self.color.s -= .01
        self.progress_bar.on_update(frame / 44100)
        self.anim.on_update()

    #erases everything from its canvas

    def cleanup(self):
        self.remove(self.color)
        self.progress_bar.cleanup()
        self.remove(self.progress_bar)
        for diag in self.diagrams:
            self.remove(diag)

    def on_touch_down(self, touch):
        self.progress_bar.set_cursor(touch.pos)
コード例 #16
0
    def run(self):
        """
        Main loop
        """
        self.setGUI(0)
        while not self.gameFlag:
            # self.handleEvents()
            self.gameFlag, self.timerFlag = self.textBoxEnter.listenKeyboardEvents(
            )
            self.board.drawGUI(
                self.TextFieldLabels,
                self.textBoxEnter,
            )
            self.board.updateScreen()
            self.clock.tick(60)  # 60 fps

        if self.textBoxEnter.getText() is not '':
            self.playerName = self.textBoxEnter.getText()

        pygame.time.set_timer(
            pygame.USEREVENT + 1,
            1000)  # timer that calls user event nr 25 that can be handled
        self.enemiesMovementThread = threading.Thread(
            target=self.startEnemiesMovement)
        self.enemiesMovementThread.start()

        while self.gameFlag:
            self.handleEvents()
            self.ammoCheck()
            self.currFps = self.clock.get_fps()
            self.board.drawGame(
                self.enemies,
                self.player,
                self.bulletToDisplay + self.ammoToDisplay,
                [  # I dont addd dependency between text size and their position on the screen coz
                    # I want to dynamic change the text inside these text fields and I would need another method to doit
                    TextLabel('Level: {}'.format(self.level), 10, 10, 'comic',
                              20, (222, 127, 233)),
                    TextLabel('Time: {} s'.format(self.gameTime),
                              self.width - 80, self.height - 30, 'comic', 20,
                              (222, 127, 233)),
                    TextLabel('Fps: {}'.format(int(
                        self.currFps)), self.width - 60, 10, 'comic', 20,
                              (222, 127, 233))
                ],
            )
            self.board.updateScreen()
            self.gameLogic()
            self.clock.tick(60)  # 60 fps

        self.db.connect()
        bestScoreRow = self.db.getRowsWhereNameIs('scoresTable',
                                                  self.playerName)
        if len(bestScoreRow) > 0:
            if self.level > bestScoreRow[0][2]:
                self.db.updateRow('scoresTable', self.playerName,
                                  (self.playerName, self.level))
        else:
            self.db.addRow('scoresTable', (self.playerName, self.level))
        self.db.close()

        self.cleanAfterDeath()

        while not self.gameFlag:
            self.handleEvents()
            self.board.drawGUI(self.TextFieldLabels, )
            self.board.updateScreen()
            self.clock.tick(60)  # 60 fps
コード例 #17
0
    def __init__(self, size=400, pos=(0, 0), chord='G', color="black"):
        super(ChordDiagram, self).__init__()

        self.colors = []
        self.add(PushMatrix())

        self.translate = Translate(*pos)
        self.add(self.translate)

        self.size = size
        self.x, self.y = (0, 0)

        # fretboard
        x = self.x + self.size * .1
        y1 = self.y + self.size * .2
        y2 = self.y + self.size * .8

        fretboard = InstructionGroup()
        board_color = Color(139 / 255, 69 / 255, 19 / 255)
        fretboard.add(board_color)
        self.colors.append(board_color)
        background = Rectangle(pos=(x, y1),
                               size=(self.size * 1.4, self.size * .6))
        fretboard.add(background)
        self.add(fretboard)

        # frets
        last_x = x
        self.finger_placements = [x]
        scale_length = self.size * 6
        for i in range(4):
            fret = InstructionGroup()
            fret_color = Color(238 / 255, 238 / 255, 224 / 255)
            fret.add(fret_color)
            self.colors.append(fret_color)
            x = last_x + scale_length / 17.817
            self.finger_placements.append((last_x + x) / 2)
            last_x = x
            line = Line(points=[x, y1, x, y2],
                        width=self.size / 100,
                        cap='round')
            fret.add(line)
            self.add(fret)
            scale_length = scale_length - scale_length / 17.817

        # fret marker
        x_dot = self.finger_placements[3]
        dot = InstructionGroup()
        dot_color = Color(1, 1, 1)
        dot.add(dot_color)
        self.colors.append(dot_color)
        circle = CEllipse(cpos=(x_dot, self.y + self.size / 2),
                          csize=(self.size * .06, self.size * .06))
        dot.add(circle)
        self.add(dot)

        # strings
        self.string_heights = []
        for i in range(6):
            string = InstructionGroup()
            if i < 3:  # brass strings
                string_color = Color(181 / 255, 166 / 255, 66 / 255)
                string.add(string_color)
                self.colors.append(string_color)
                width = size / 100
            else:
                string_color = Color(180 / 255, 180 / 255, 180 / 255)
                string.add(string_color)
                self.colors.append(string_color)
                width = size / 200
            y = self.y + self.size * (.25 + .1 * i)
            self.string_heights.append(y)
            line = Line(points=[
                self.x + self.size * .1, y, self.x + self.size * 1.5, y
            ],
                        width=width,
                        cap='round')
            string.add(line)
            self.add(string)
        #print(self.string_heights)
        # nut
        x = self.x + self.size * .1
        nut = InstructionGroup()
        nut_color = Color(238 / 255, 238 / 255, 224 / 255)
        nut.add(nut_color)
        self.colors.append(nut_color)
        line = Line(points=[x, y1, x, y2], width=self.size / 50, cap='square')
        nut.add(line)
        self.add(nut)

        # chord fingering
        # if chord is hard-coded, get the frets from the dict.  else, use the passed-in list of frets
        self.indices = self.Chords[chord]

        for index, fret in enumerate(self.indices):

            finger = InstructionGroup()
            finger_color = Color(*to_rgb[color])
            finger.add(finger_color)
            self.colors.append(finger_color)  # TO DO: handle muted strings
            if fret == -1:
                mute_color = Color(*to_rgb[color])
                self.colors.append(mute_color)
                x = Mute(size=self.size * .07,
                         pos=(self.finger_placements[0],
                              self.string_heights[index]),
                         color=mute_color)
                finger.add(x)
            else:
                dot = CEllipse(cpos=(self.finger_placements[fret],
                                     self.string_heights[index]),
                               csize=(self.size * .1, self.size * .1))
                finger.add(dot)
            self.add(finger)

        # border
        border = InstructionGroup()

        self.color = to_rgb[color]
        border_color = Color(*self.color)
        border.add(border_color)
        self.colors.append(border_color)
        line = Line(points=[
            self.x, self.y, self.x, self.y + self.size,
            self.x + self.size * 1.6, self.y + self.size,
            self.x + self.size * 1.6, self.y
        ],
                    width=self.size / 100,
                    joint='miter',
                    close=True)
        border.add(line)
        self.add(border)

        font_size = 20 - 2 * len(chord)
        self.label = TextLabel(chord,
                               pos=(self.x - 40, self.y + self.size / 3),
                               font=font_size,
                               color=border_color)
        self.add(self.label)

        self.fingers = []

        self.finger_colors = Color(*self.color)
        self.finger_colors.a = .3
        self.add(self.finger_colors)
        self.colors.append(self.finger_colors)
        for i in range(6):
            dot = CEllipse(cpos=(self.finger_placements[0],
                                 self.string_heights[i]),
                           csize=(self.size * .1, self.size * .1))
            self.fingers.append(dot)
            self.add(dot)
        self.add(PopMatrix())