コード例 #1
0
    def __init__(self):
        self.title = c.SPRITE(c.IMG("title.png"))
        self.title.scale = 2
        self.label_x_offset = 20
        self.title.x = (c.GAME_WINDOW.width - self.title.width) / 2
        self.title.y = (c.GAME_WINDOW.height - self.title.height) / 2

        self.subtitle = c.SPRITE(c.IMG("quizlabel2.png"))
        self.subtitle.x = (c.GAME_WINDOW.width - self.subtitle.width) / 2
        self.subtitle.y = (c.GAME_WINDOW.height -
                           self.subtitle.height) / 2 - 100

        self.title_background = c.SPRITE(c.IMG("titlebackground.png"))
        self.title.ground = c.SPRITE(c.IMG("titleground.png"))

        #BUTTONS
        self.label_center = 450  #xpos of buttons, i becomes ypos
        self.coords = [
            Coord(self.label_center, i) for i in range(120, 60, -30)
        ]
        self.coords.reverse()

        self.options_button = c.LABEL("Options",
                                      font_size=c.FONT_SIZE,
                                      color=c.BLACK,
                                      bold=True)
        self.options_button.x = self.coords[0].x + self.label_x_offset
        self.options_button.y = self.coords[0].y

        self.game_button = c.LABEL("Game",
                                   font_size=c.FONT_SIZE,
                                   color=c.BLACK,
                                   bold=True)
        self.game_button.x = self.coords[1].x + self.label_x_offset
        self.game_button.y = self.coords[1].y

        self.vertical_index = 0
        self.selector = s.Selector(self.coords)
コード例 #2
0
def char_select():
    def get(insert):
        image = d.GAME_MEDIA[insert]['player_image']
        color = d.GAME_MEDIA[insert]['color']
        text = v.font.render(insert, True, color)
        return image, text
    color_choices = ['Blue', 'Orange', 'Green', 'Purple', 'Red', 'Yellow', 'Grey', 'White', 'Rainbow']
    player1 = 0
    player2 = 1
    textS1 = v.font.render('Choose Your Character', True, v.white)
    textS2 = v.font.render('Space To Continue', True, v.white)
    textS3 = v.font3.render('VS.', True, v.white)
    all_sprites = pygame.sprite.Group()
    player1_image, text1 = get(color_choices[player1])
    player2_image, text2 = get(color_choices[player2])
    selectorA = s.Selector((30, 188))
    selectorB = s.Selector((85, 388))
    all_sprites.add(selectorA, selectorB)
    clock = pygame.time.Clock()
    loop = True

    while loop:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_d:
                    player1 += 1
                    selectorA.pos[0] += 55
                elif event.key == pygame.K_a:
                    player1 -= 1
                    selectorA.pos[0] -= 55
                if event.key == pygame.K_RIGHT:
                    player2 += 1
                    selectorB.pos[0] += 55
                elif event.key == pygame.K_LEFT:
                    player2 -= 1
                    selectorB.pos[0] -= 55
                if event.key in (pygame.K_d, pygame.K_a, pygame.K_RIGHT, pygame.K_LEFT):
                    player1 %= len(color_choices)
                    player2 %= len(color_choices)
                    player1_image, text1 = get(color_choices[player1])
                    player2_image, text2 = get(color_choices[player2])
                    m.MEDIA['select'].play()                    
                if event.key == pygame.K_SPACE:
                    v.P1Char = color_choices[player1]
                    v.P2Char = color_choices[player2]
                    loop = False
        all_sprites.update()
        
        m.screen.fill(v.black)
        m.screen.blit(textS1, (90, 50))
        m.screen.blit(textS2, (120, 500))
        m.screen.blit(textS3, (230, 275))
        m.screen.blit(text1, (d.GAME_MEDIA[color_choices[player1]]['local'], 218))
        m.screen.blit(text2, (d.GAME_MEDIA[color_choices[player2]]['local'], 330))
        
        m.screen.blit(m.MEDIA['blue'], (60 - 55, 163))
        m.screen.blit(m.MEDIA['orange'], (115 - 55, 163))
        m.screen.blit(m.MEDIA['green'], (170 - 55, 163))
        m.screen.blit(m.MEDIA['purple'], (225 - 55, 163))
        m.screen.blit(m.MEDIA['red'], (280 - 55, 163))
        m.screen.blit(m.MEDIA['yellow'], (335 - 55, 163))
        m.screen.blit(m.MEDIA['grey'], (390 - 55, 163))
        m.screen.blit(m.MEDIA['white'], (390, 163))
        m.screen.blit(m.MEDIA['rainbow'], (445, 163))
        
        m.screen.blit(m.MEDIA['blue'], (60 - 55, 363))
        m.screen.blit(m.MEDIA['orange'], (115 - 55, 363))
        m.screen.blit(m.MEDIA['green'], (170 - 55, 363))
        m.screen.blit(m.MEDIA['purple'], (225 - 55, 363))
        m.screen.blit(m.MEDIA['red'], (280 - 55, 363))
        m.screen.blit(m.MEDIA['yellow'], (335 - 55, 363))
        m.screen.blit(m.MEDIA['grey'], (390 - 55, 363))
        m.screen.blit(m.MEDIA['white'], (390, 363))
        m.screen.blit(m.MEDIA['rainbow'], (445, 363))
        
        all_sprites.draw(m.screen)
        
        pygame.display.flip()
        clock.tick(60)
コード例 #3
0
    def __init__(self, aGame, aMapData, aStartingPlayer, aUnitInfoList,
                 aPlayerInfoList, aCityInfo):
        # when creating a new map, clear the old player objects so new ones can be instantiated
        aGame.mPlayers.clear()

        self.mGame = aGame
        self.mapHeight = 0
        self.mapWidth = 0
        self.mMapData = []
        self.mTileDict = {}
        vY = 0

        self.mGame.mSelector = sprites.Selector(self.mGame)
        self.mGame.mSelected = sprites.Selected(self.mGame)

        aGame.mCurrentPlayerTurn = aStartingPlayer

        # add the player obj to the current players dictionary
        for vPlayer in aPlayerInfoList:
            vPlayerId = vPlayer[0]
            vPlayerMoney = vPlayer[1]
            vPlayerObj = player.Player(self.mGame, vPlayerId, vPlayerMoney)
            aGame.mPlayers[vPlayerId] = vPlayerObj

        aGame.mNumPlayers = int(len(aPlayerInfoList))

        # have to open the file twice as we run through it twice
        for vRow in aMapData:
            for vTile in vRow:
                if self.mapWidth < len(vRow):
                    self.mapWidth = len(vRow)
            self.mapHeight += 1

        if aGame.mVerbosity >= 1:
            print('Mapsize: ', self.mapWidth, 'x', self.mapHeight)
        for vRow in aMapData:
            vMapRowData = []
            vX = 0
            for vTileChar in vRow:
                if len(vRow) > 0:
                    import tileDict
                    vTileConstructor = tileDict.tileDict[vTileChar]
                    if vTileChar in 'zxcvb':
                        try:
                            vCityOwner = aCityInfo[(vX, vY)]
                        except:
                            vCityOwner = None
                        vTile = self.createTile(vTileConstructor, vX, vY,
                                                vCityOwner)
                    else:
                        vTile = self.createTile(vTileConstructor, vX, vY)

                    vMapRowData.append(vTileChar)
                    self.mTileDict[(vX, vY)] = vTile
                    vX += 1
            self.mMapData.append(vMapRowData)
            vY += 1

        for vUnit in aUnitInfoList:
            # unit info : ( self.mName, ( self.x, self.y ), self.mPlayerId, self.mHealth, self.mLevel )
            vUnitName = vUnit[0]
            vUnitXPos = vUnit[1][0]
            vUnitYPos = vUnit[1][1]
            vPlayerId = vUnit[2]
            vUnitHealth = vUnit[3]
            vUnitLevel = vUnit[4]
            vUnitConstructor = getattr(sprites, vUnitName)
            vTile = self.mTileDict[(vUnitXPos, vUnitYPos)]
            vUnitConstructor(self.mGame, vTile, vPlayerId, vUnitHealth,
                             vUnitLevel)
            if aGame.mVerbosity >= 5:
                print('Units being constructed', vUnitName)

        if aGame.mVerbosity >= 2:
            print('vnumplayers', aGame.mNumPlayers)

        # leave these for debug

        # unitSprites.LightInfantry(self.mGame, self.mTileDict[ ( 13, 10 ) ], 0, 98, 1)
        # unitSprites.LightInfantry( self.mGame, self.mTileDict[(13, 12)], 1, 27, 1 )
        # unitSprites.LightInfantry( self.mGame, self.mTileDict[(10, 14)], 0, 76, 1 )
        # unitSprites.LightInfantry( self.mGame, self.mTileDict[(10, 16)], 1, 100, 1 )
        # unitSprites.Battleship( self.mGame, self.mTileDict[(5, 5)], 0, 100, 1 )
        # unitSprites.Battleship( self.mGame, self.mTileDict[(5, 2)], 1, 100, 1 )

        #assuming all is well and generated, create the camera obj
        self.mXCenter = (self.mapWidth * Settings.TILESIZE) / 2
        self.mYCenter = (self.mapHeight * Settings.TILESIZE) / 2
        # TODO currently the centers dont acutlaly do anything, yes I spelled that wrong thanks Andrew
        self.mGame.mCamera = Camera(self.mGame, self.mXCenter, self.mYCenter)

        # after everything has finished, change game state last to avoid bugs
        self.mGame.mGameState = GameState.HUMANPLAYER
コード例 #4
0
ファイル: game.py プロジェクト: Ale-XYX/Rects-Fight
def char_select():
    def get(insert):
        color = dictionaries.PLAYER_MEDIA[insert[0]]['Color']
        img = dictionaries.PLAYER_MEDIA[insert[0]]['Image']
        txt = globals.FONT_BIG.render(insert[0], True, color)
        abiltxt = globals.FONT_BIG.render('Ability: ' + str(insert[1]), True,
                                          color)
        return img, txt, abiltxt

    clock = pygame.time.Clock()
    loop = True
    color_choices = [('Blue', 'Big Bullet'), ('Orange', 'Big Bullet'),
                     ('Green', 'Split Bullet'), ('Yellow', 'Split Bullet'),
                     ('Red', 'Beam'), ('Purple', 'Beam'),
                     ('Grey', 'Reverse Bullet'), ('White', 'Reverse Bullet'),
                     ('Rainbow', 'Multi bullet')]
    TEXTS1 = globals.FONT_BIG.render('Choose Your Character', True,
                                     globals.WHITE)
    TEXTS2 = globals.FONT_BIG.render('Space To Continue', True, globals.WHITE)
    TEXTS3 = globals.FONT_BOLD_ITALIC.render('VS.', True, globals.WHITE)
    playero_int = 0
    playert_int = 1
    playero_image, chartxto, abiltxto = get(color_choices[playero_int])
    playert_image, chartxtt, abiltxtt = get(color_choices[playert_int])
    selector_a = sprites.Selector((30, 188))
    selector_b = sprites.Selector((85, 388))
    all_sprites = pygame.sprite.Group()
    all_sprites.add(selector_a, selector_b)

    while loop:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
                # Keymap
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_d:
                    playero_int += 1
                    selector_a.pos[0] += 55
                elif event.key == pygame.K_a:
                    playero_int -= 1
                    selector_a.pos[0] -= 55
                if event.key == pygame.K_RIGHT:
                    playert_int += 1
                    selector_b.pos[0] += 55
                elif event.key == pygame.K_LEFT:
                    playert_int -= 1
                    selector_b.pos[0] -= 55
                if event.key == pygame.K_SPACE:
                    # Loads character values based on Player 1 and Player 2's choices.
                    globals.playero_charvalue = color_choices[playero_int][0]
                    globals.playert_charvalue = color_choices[playert_int][0]
                    if globals.playero_charvalue == 'Grey' and globals.playert_charvalue == 'White':
                        globals.mem_activate = True
                    loop = False
                if event.key in (pygame.K_d, pygame.K_a, pygame.K_RIGHT,
                                 pygame.K_LEFT):
                    playero_int %= len(color_choices)
                    playert_int %= len(color_choices)
                    playero_image, chartxto, abiltxto = get(
                        color_choices[playero_int])
                    playert_image, chartxtt, abiltxtt = get(
                        color_choices[playert_int])
                    dictionaries.MEDIA['select_sound'].play()
        all_sprites.update(470, 30)

        globals.screen.fill(globals.BLACK)
        globals.screen.blit(TEXTS1, (90, 50))
        globals.screen.blit(TEXTS2, (120, 500))
        globals.screen.blit(TEXTS3, (230, 275))
        globals.screen.blit(chartxto, (dictionaries.PLAYER_MEDIA[
            color_choices[playero_int][0]]['Location'][0], 218))
        globals.screen.blit(chartxtt, (dictionaries.PLAYER_MEDIA[
            color_choices[playert_int][0]]['Location'][0], 300))
        globals.screen.blit(abiltxto, (dictionaries.PLAYER_MEDIA[
            color_choices[playero_int][0]]['Location'][1], 248))
        globals.screen.blit(abiltxtt, (dictionaries.PLAYER_MEDIA[
            color_choices[playert_int][0]]['Location'][1], 330))
        globals.screen.blit(dictionaries.MEDIA['charsel_bar'], (0, 158))
        globals.screen.blit(dictionaries.MEDIA['charsel_bar'], (0, 358))
        all_sprites.draw(globals.screen)

        pygame.display.flip()
        clock.tick(60)
コード例 #5
0
ファイル: game.py プロジェクト: carlosrh18/Fie-Fighter
def char_select():
    def get(insert):
        color = dictionaries.PLAYER_MEDIA[insert[0]]['Color']
        img = dictionaries.PLAYER_MEDIA[insert[0]]['Image']
        txt = globals.FONT_BIG.render(insert[0], True, color)
        abiltxt = globals.FONT_BIG.render('Ability: ' + str(insert[1]), True,
                                          color)
        return img, txt, abiltxt

    clock = pygame.time.Clock()
    loop = True
    color_choices = [
        ('Sistemas', 'Lanzar computadoras'), ('Software', 'Rayo digital'),
        ('Mecatronica', 'Golpe KUKA'), ('Mecanica', 'Golpe TESLA'),
        ('Electronica', 'Rayo laser'), ('Telematica', 'Lanzar antenas'),
        ('Oceanica', 'Golpe con tiburon'), ('Industrial', 'golpe con casco'),
        ('Quimica', 'golpe con bata')
    ]
    TEXTS1 = globals.FONT_BIG.render('Escoge tu ingenieria', True,
                                     globals.WHITE)
    TEXTS2 = globals.FONT_BIG.render('Espacio para continuar...', True,
                                     globals.WHITE)
    TEXTS3 = globals.FONT_BOLD_ITALIC.render('VS.', True, globals.WHITE)
    playero_int = 0
    playert_int = 1
    playero_image, chartxto, abiltxto = get(color_choices[playero_int])
    playert_image, chartxtt, abiltxtt = get(color_choices[playert_int])
    selector_a = sprites.Selector((30, 188))
    selector_b = sprites.Selector((85, 388))
    all_sprites = pygame.sprite.Group()
    all_sprites.add(selector_a, selector_b)

    while loop:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
                # Keymap
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_d:
                    playero_int += 1
                    selector_a.pos[0] += 55
                elif event.key == pygame.K_a:
                    playero_int -= 1
                    selector_a.pos[0] -= 55
                if event.key == pygame.K_RIGHT:
                    playert_int += 1
                    selector_b.pos[0] += 55
                elif event.key == pygame.K_LEFT:
                    playert_int -= 1
                    selector_b.pos[0] -= 55
                if event.key == pygame.K_SPACE:
                    # Loads character values based on Player 1 and Player 2's choices.
                    globals.playero_charvalue = color_choices[playero_int][0]
                    globals.playert_charvalue = color_choices[playert_int][0]
                    if globals.playero_charvalue == 'Grey' and globals.playert_charvalue == 'White':
                        globals.mem_activate = True
                    loop = False
                if event.key in (pygame.K_d, pygame.K_a, pygame.K_RIGHT,
                                 pygame.K_LEFT):
                    playero_int %= len(color_choices)
                    playert_int %= len(color_choices)
                    playero_image, chartxto, abiltxto = get(
                        color_choices[playero_int])
                    playert_image, chartxtt, abiltxtt = get(
                        color_choices[playert_int])
                    dictionaries.MEDIA['select_sound'].play()
        all_sprites.update(470, 30)

        globals.screen.fill(globals.BLACK)
        globals.screen.blit(TEXTS1, (90, 50))
        globals.screen.blit(TEXTS2, (120, 500))
        globals.screen.blit(TEXTS3, (230, 275))
        globals.screen.blit(chartxto, (dictionaries.PLAYER_MEDIA[
            color_choices[playero_int][0]]['Location'][0], 218))
        globals.screen.blit(chartxtt, (dictionaries.PLAYER_MEDIA[
            color_choices[playert_int][0]]['Location'][0], 300))
        globals.screen.blit(abiltxto, (dictionaries.PLAYER_MEDIA[
            color_choices[playero_int][0]]['Location'][1], 248))
        globals.screen.blit(abiltxtt, (dictionaries.PLAYER_MEDIA[
            color_choices[playert_int][0]]['Location'][1], 330))
        globals.screen.blit(dictionaries.MEDIA['charsel_bar'], (0, 158))
        globals.screen.blit(dictionaries.MEDIA['charsel_bar'], (0, 358))
        all_sprites.draw(globals.screen)

        pygame.display.flip()
        clock.tick(60)