Пример #1
0
def selectionScreen2():
    '''Displays the backup selection screen.'''
    cfg.gameDisplay.fill(cfg.pokemonYellow)
    headerFont = pygame.font.SysFont('segoeui', 40, bold=True)
    font = pygame.font.SysFont('segoeui', 25, bold=True)
    draw.drawText('Select your Backup Mon!', headerFont, cfg.black, 'center',
                  cfg.displayWidth / 2, 40)
    pygame.display.update()
    sleep(0.5)

    inScreen = True
    while inScreen:
        for event in pygame.event.get():
            ##print(event) #debug
            if event.type == pygame.QUIT:
                logic.quitGame()
        cfg.gameDisplay.fill(cfg.pokemonYellow)

        headerFont = pygame.font.SysFont('segoeui', 40, bold=True)
        draw.drawText('Select your Backup Mon!', headerFont, cfg.black,
                      'center', cfg.displayWidth / 2, 40)

        draw.thumbnail('Snowbro', 40, 100, 2)
        draw.thumbnail('Megabite', 160, 100, 2)
        draw.thumbnail('None', 280, 100, 2)

        draw.thumbnail('Drogon', 40, 220, 2)
        draw.thumbnail('None', 160, 220, 2)
        draw.thumbnail('None', 280, 220, 2)

        draw.thumbnail('None', 40, 340, 2)
        draw.thumbnail('None', 160, 340, 2)
        draw.thumbnail('None', 280, 340, 2)

        draw.drawText('Your Party:', font, cfg.black, 'topleft', 440, 460)
        draw.drawText('1. ' + cfg.primaryPick, font, cfg.black, 'topleft', 440,
                      500)
        draw.drawText('2. (selecting...)', font, cfg.black, 'topleft', 440,
                      540)

        # Back button
        draw.button('Back', 40, 520, 100, 50, cfg.waterBlue, cfg.iceBlue,
                    cfg.black, selectionScreen)

        pygame.display.update()
        cfg.clock.tick(30)
Пример #2
0
def loseScreen():
    '''Displays the lose screen.'''
    headerFont = pygame.font.SysFont('segoeui', 80, bold=True)
    font = pygame.font.SysFont('segoeui', 25, bold=True)
    inResultsScreen = True
    while inResultsScreen:
        for event in pygame.event.get():
            click = pygame.mouse.get_pressed()
            if event.type == pygame.QUIT:
                logic.quitGame()

        cfg.gameDisplay.fill(cfg.white)
        cfg.gameDisplay.blit(cfg.titleBackground, (0, 0))

        # Draw heading
        draw.drawText('You lost...', headerFont, cfg.black, 'center',
                      cfg.displayWidth / 2, 80)

        # Draw text
        draw.drawText('You took ' + str(cfg.newStats['Turns']) + ' turns',
                      font, cfg.black, 'topleft', 25, 180)
        draw.drawText(
            'You dealt a total of ' + str(cfg.newStats['Damage']) +
            ' damage in this battle', font, cfg.black, 'topleft', 25, 220)

        # Draw button
        draw.button('Main Menu', 610, 520, 150, 50, cfg.waterBlue, cfg.iceBlue,
                    cfg.black, logic.resetGame)

        pygame.display.update()
        cfg.clock.tick(30)
Пример #3
0
def confirmSelection():
    '''Displays the Mon confirmation screen.'''

    cfg.gameDisplay.fill(cfg.pokemonYellow)
    headerFont = pygame.font.SysFont('segoeui', 40, bold=True)
    font = pygame.font.SysFont('segoeui', 25, bold=True)
    draw.drawText('Proceed to Battle?', headerFont, cfg.black, 'center',
                  cfg.displayWidth / 2, 40)
    pygame.display.update()
    sleep(0.5)

    inScreen = True
    while inScreen:
        for event in pygame.event.get():
            ##print(event) #debug
            if event.type == pygame.QUIT:
                logic.quitGame()
        cfg.gameDisplay.fill(cfg.pokemonYellow)

        draw.drawText('Proceed to Battle?', headerFont, cfg.black, 'center',
                      cfg.displayWidth / 2, 40)
        draw.drawText('You have chosen the following Pius Mon:', font,
                      cfg.black, 'topleft', 40, 90)

        draw.character2(cfg.primaryPick, 40, 120)
        draw.drawText('1. ' + cfg.primaryPick, font, cfg.black, 'topleft', 40,
                      430)
        draw.character2(cfg.backupPick, 380, 120)
        draw.drawText('2. ' + cfg.backupPick, font, cfg.black, 'topleft', 380,
                      430)

        draw.button("Start the Battle!", 460, 520, 300, 50, cfg.darkGreen,
                    cfg.green, cfg.white, gameLoop)
        draw.button('Choose Again', 40, 520, 200, 50, cfg.waterBlue,
                    cfg.iceBlue, cfg.black, selectionScreen)

        pygame.display.update()
        cfg.clock.tick(30)
Пример #4
0
def confirmStatReset():
    '''Confirmation screen for resetting player stats.'''
    cfg.gameDisplay.fill(cfg.white)
    cfg.gameDisplay.blit(cfg.titleBackground, (0, 0))
    draw.shadedSurface()
    pygame.draw.rect(cfg.gameDisplay, cfg.black, (50, 50, 700, 500), 2)

    font = pygame.font.SysFont('segoeui', 25, bold=True)
    draw.drawText('Are you sure you want to erase your career statistics?',
                  font, cfg.black, 'center', cfg.displayWidth / 2, 200)
    draw.drawText('This action can not be undone.', font, cfg.black, 'center',
                  cfg.displayWidth / 2, 240)
    pygame.display.update()
    sleep(1)

    pygame.draw.rect(cfg.gameDisplay, cfg.brightRed, (50, 50, 700, 500), 2)
    pygame.display.update()
    sleep(1)

    inScreen = True
    while inScreen:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                logic.quitGame()

        cfg.gameDisplay.fill(cfg.white)
        cfg.gameDisplay.blit(cfg.titleBackground, (0, 0))
        draw.shadedSurface()
        pygame.draw.rect(cfg.gameDisplay, cfg.brightRed, (50, 50, 700, 500), 2)

        draw.drawText('Are you sure you want to erase your career statistics?',
                      font, cfg.black, 'center', cfg.displayWidth / 2, 200)
        draw.drawText('This action can not be undone.', font, cfg.black,
                      'center', cfg.displayWidth / 2, 240)

        # Button resets stats
        draw.button('Erase Stats', 100, 450, 150, 50, cfg.red, cfg.brightRed,
                    cfg.white, statHandler.resetJson)

        # Button to cancel
        draw.button('Cancel', 500, 450, 200, 50, cfg.waterBlue, cfg.iceBlue,
                    cfg.black, statsScreen)

        pygame.display.update()
        cfg.clock.tick(30)
Пример #5
0
def statsScreen():
    '''Displays the stats screen.'''
    stats = statHandler.readJson()
    winRatio = logic.winRatio(stats['BattlesWon'], stats['GamesPlayed'])

    headerFont = pygame.font.SysFont('segoeui', 60, bold=True)
    font = pygame.font.SysFont('segoeui', 25, bold=True)

    inStatsScreen = True
    while inStatsScreen:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                logic.quitGame()

        cfg.gameDisplay.fill(cfg.white)
        cfg.gameDisplay.blit(cfg.titleBackground, (0, 0))

        # Draw heading
        draw.drawText('Career Stats', headerFont, cfg.black, 'center',
                      cfg.displayWidth / 2, 60)

        # Draw stat text
        draw.drawText('Battles won: ' + str(stats['BattlesWon']), font,
                      cfg.black, 'topleft', 40, 140)
        draw.drawText('Games played: ' + str(stats['GamesPlayed']), font,
                      cfg.black, 'topleft', 40, 180)
        draw.drawText('Win ratio: ' + str(winRatio) + '%', font, cfg.black,
                      'topleft', 40, 220)
        draw.drawText('Total damage: ' + str(stats['TotalDamage']), font,
                      cfg.black, 'topleft', 40, 260)
        draw.drawText('Total turns: ' + str(stats['TotalTurns']), font,
                      cfg.black, 'topleft', 40, 300)
        draw.drawText('Fastest game: ' + str(stats['FastestGame']) + ' turns',
                      font, cfg.black, 'topleft', 40, 340)

        # Draw back button
        draw.button('Main Menu', 560, 520, 200, 50, cfg.waterBlue, cfg.iceBlue,
                    cfg.black, titleScreen)
        draw.button('Reset Stats', 40, 520, 150, 50, cfg.red, cfg.brightRed,
                    cfg.white, confirmStatReset)

        pygame.display.update()
        cfg.clock.tick(30)
Пример #6
0
def DonghuaWin(win, text):

    pg.draw.rect(win, [0, 255, 0], [0, 320, 640, 160], 0)
    for i, t in enumerate(text):
        drawText(win, t, (0, 320 + i * 25))
Пример #7
0
    def run(self, gv, mobTeam, moveQueue, state):
        for event in pg.event.get():
            if event.type == pg.QUIT:
                exit()

        #绘制背景
        self.win.blit(self.bg, (0, 0))
        #绘制我方角色信息
        for i, r in enumerate(gv.gd.team):
            drawPic43(self.win, r.pic, (0, 80 * i))
            drawText(self.win, "HP:" + str(r.hp) + "/" + str(r.maxHp),
                     (60, 80 * i))
            drawText(self.win, "MP:" + str(r.mp) + "/" + str(r.maxMp),
                     (60, 25 + 80 * i))
        #绘制敌方角色信息
        for i, r in enumerate(mobTeam):
            drawPic43(self.win, r.pic, (460, 80 * i))
            drawText(self.win, "HP:" + str(r.hp) + "/" + str(r.maxHp),
                     (360, 80 * i))
            drawText(self.win, "MP:" + str(r.mp) + "/" + str(r.maxMp),
                     (360, 25 + 80 * i))
        #绘制队列信息
        drawText(self.win, u"行动顺序", (520, 0))
        for i, key in enumerate(moveQueue):
            if key < 10:
                drawText(self.win, gv.gd.team[key].name, (520, 25 + i * 25))
            else:
                drawText(self.win, mobTeam[key - 10].name, (520, 25 + i * 25))
Пример #8
0
def main(sourceDir_, recycleDir_, statFileName_, waitKey=cv.WaitKey):
    global sourceDir, recycleDir, statFileName
    sourceDir = sourceDir_
    recycleDir = recycleDir_
    statFileName = statFileName_
    global newPoint, previousFrameTime

    # Algorithm parameters
    sampleRectDims = crowdmisc.Properties.sample_rect_dims
    egomotion_correction = crowdmisc.Properties.egomotion_correction

    # Variables
    processMode = "pause"

    trackingRegions = None

    delayBetweenFrames = 500  # ms. For 'delay' mode
    gotoNextFrame = 0  # allow go to next frame in 'pause' mode

    crowdDensity = 0.
    numPeopleInSample = 0
    currPeopleCount = 0
    velocities = []

    peoplePerStreetRegStr = ""

    currentFileName = ""

    rgbFrame = None

    #TODO:  Remove all references to currentFrame and previusFrame in favor
    # of the versions that memoize things about the image.
    currentFrame = None
    previousFrame = None
    currentTrackedFrame = None
    previousTrackedFrame = None

    firstFrameTime = 0
    currentFrameTime = 0
    previousFrameTime = 0
    frameQueueLenght = 0

    recomputeDensityFlag = True

    # Set up windows
    configWindow = 'flowCorners'
    configWindowImage = None

    densityWindow = 'Density'
    densityWindowImage = np.zeros(densityWindowSize + (3, ), dtype=np.uint8)

    stateWindow = 'State'
    stateWindowImage = np.zeros(stateWindowSize + (3, ), dtype=np.uint8)

    statisticWindow = 'Statistic'
    statisticWindowImage = np.zeros(statisticWindowSize + tuple([3]),
                                    dtype=np.uint8)
    cv.NamedWindow(configWindow)
    cv.SetMouseCallback(configWindow, on_mouse)

    cv.NamedWindow(densityWindow, 0)
    cv.NamedWindow(statisticWindow)
    cv.NamedWindow(stateWindow)

    #############################
    # Load saved state.  COMMENT TO RESET EVERY TIME
    #############################
    firstFrameTime, previousFrameTime, currPeopleCount = restoreState()

    # Take one first and second frames
    imageSequence = crowdio.ImageSequence(sourceDir, recycleDir)
    frame, previousFrameTime, frameQueueLenght, currentFileName = \
        imageSequence.getNextFrame(previousFrameTime)
    gotoNextFrame = 1
    if firstFrameTime <= 0.0:
        firstFrameTime = previousFrameTime

    trackingRegions = crowdmisc.constructTrackingRegions(frame)
    currTrackingRegions = crowdmisc.constructTrackingRegions(frame)
    configWindowSize = (int(frame.shape[1] * configImageZoom),
                        int(frame.shape[0] * configImageZoom))

    # Main Loop
    delayTime = 1
    while True:
        # Determine how long to pause to check for key input, depending on
        # the state of the program.  If we check too often, we lose performance
        # but if we don't check often enough, the program becomes unresponsive.
        if processMode == 'delay':
            delayTime = delayBetweenFrames
        elif processMode in ('pause', 'egomotion') and gotoNextFrame == 0:
            delayTime = 250  # check for events four times a second
        elif processMode == 'pause' and gotoNextFrame > 0:
            delayTime = 1
        else:
            delayTime = 100

        key = waitKey(delayTime)
        if key >= 0:
            key = key & 0xff

            # Reset motion and egomotion tracking regions
            if key == ord('r'):
                trackingRegions = crowdmisc.constructTrackingRegions(
                    currentFrame)

            # To edit number of people
            if key >= ord('0') and key <= ord('9'):
                peoplePerStreetRegStr = peoplePerStreetRegStr + chr(key)
            if key == 8 and peoplePerStreetRegStr != "":
                peoplePerStreetRegStr = peoplePerStreetRegStr[:-1]

            # 'Enter' pressed - save new number of people
            if key in (10, 13) and peoplePerStreetRegStr != "":
                print "Density input successful"
                crowdDensity = crowd.calculate_density(
                    int(peoplePerStreetRegStr), sampleRectDims)
                numPeopleInSample = int(peoplePerStreetRegStr)
                peoplePerStreetRegStr = ""
                recomputeDensityFlag = True

            # Select mode
            if key == ord('p'):
                processMode = "pause"
            if key == ord('e') and egomotion_correction == True:
                processMode = "egomotion"
            if key == ord(
                    'a') and not trackingRegions['flowWarpMatrix'] is None:
                processMode = "auto"
            if key == ord(
                    'd') and not trackingRegions['flowWarpMatrix'] is None:
                processMode = "delay"

            if processMode == "delay":
                if key == 82:  # UP
                    delayBetweenFrames += 1000
                elif key == 84:  # DOWN
                    delayBetweenFrames -= 1000
                elif key == 81:  # LEFT
                    delayBetweenFrames -= 100
                elif key == 83:  # RIGHT
                    delayBetweenFrames += 100

                if delayBetweenFrames < 1:
                    delayBetweenFrames = 1

            if processMode in ("pause", "egomotion"):
                if key == 82:  # UP
                    gotoNextFrame = 10
                if key == 83:  # RIGHT
                    gotoNextFrame = 1

            if processMode == 'delay':
                delayTime = delayBetweenFrames

        # Quit from main loop
        if key == ord('q'):
            cv2.destroyAllWindows()
            return velocities
            break

        # Check new corner point
        if not newPoint is None:
            if processMode == 'egomotion':
                crowdmisc.updateEgomotionTrackingRegion([newPoint],
                                                        configImageZoom,
                                                        trackingRegions)
            else:
                crowdmisc.updateFlowTrackingRegion([newPoint], configImageZoom,
                                                   trackingRegions)
            newPoint = None
            currTrackingRegions = trackingRegions

        ##################################
        # Get next frame
        if not processMode in ("pause", "egomotion") or gotoNextFrame > 0:
            frame, tm, frameQueueLenght, currentFileName = \
                imageSequence.getNextFrame(previousFrameTime)
            if not frame is None:
                currentFrameTime = tm
            gotoNextFrame -= 1

        if not frame is None:
            if firstFrameTime <= 0.0:
                firstFrameTime = currentFrameTime

            if rgbFrame is None:
                rgbFrame = np.zeros(frame.shape + tuple([3]), dtype=np.uint8)

            if currentFrame is None:
                currentFrame = np.zeros_like(frame)
            if previousFrame is None:
                previousFrame = np.zeros_like(frame)

            if frame.squeeze().ndim == 2:
                rgbFrame = cv2.cvtColor(frame, cv.CV_GRAY2BGR)
            else:
                rgbFrame = frame.copy()

            currentFrame = frame.copy()
            currentTrackedFrame = crowdmisc.TrackedFrame(frame)

            ##################################
            # Draw corner configuration

            configWindowImage = cv2.resize(rgbFrame, configWindowSize)

        #end if (not frame is None)

        draw.drawPoints(configWindowImage,
                        currTrackingRegions['displayFlowCorners'])
        draw.drawPoints(configWindowImage,
                        currTrackingRegions['displayStableCorners'],
                        color=cv.RGB(0, 0, 255))

        ##################################
        # Prepare images for windows
        #cv.SetZero(densityWindowImage)
        stateWindowImage.fill(0)
        # cv.SetZero(statisticWindowImage)

        ###################################
        # calculate result
        if not trackingRegions['flowWarpMatrix'] is None:
            # draw part of street
            if recomputeDensityFlag:
                densityWindowImage, sampleRegionBounds = draw.draw_sample_region( \
                    currentFrame, currTrackingRegions['flowWarpMatrix'], sampleRectDims)

                recomputeDensityFlag = False

                #print "redisplaying density image..."
            if currentFrameTime > previousFrameTime:
                # analyzing
                currPeopleCount, prevFeatures, currFeatures, \
                meanVelocity, velocityInlierIdx, \
                currTrackingRegions,\
                prevEgomotionMatrix, currEgomotionMatrix = \
                    crowd.compute_pedestrian_flow(
                        previousTrackedFrame, currentTrackedFrame,
                        trackingRegions,
                        crowdDensity, currPeopleCount)
                velocities.append((meanVelocity, currentFrameTime))
                # draw statistic to
                statImage = draw.drawResult(
                    currentTrackedFrame.getImage(), prevFeatures, currFeatures,
                    meanVelocity, velocityInlierIdx, crowdDensity,
                    numPeopleInSample, currPeopleCount, currentFrameTime,
                    sampleRegionBounds, trackingRegions, currTrackingRegions,
                    prevEgomotionMatrix, currEgomotionMatrix)
                saveStatImage(statImage, currentFrameTime)
                sampleRegionBounds = None

        ##################################
        ## Draw text
        if not configWindowImage is None:
            draw.drawText(configWindowImage,
                          "Press 'r' to reset street corners",
                          cv.RGB(255, 255, 0))

        densityStr = "Number of People: %d" % (crowdDensity)
        draw.drawText(densityWindowImage, densityStr, cv.RGB(0, 255, 0))
        draw.drawText(densityWindowImage,
                      "Input number: " + peoplePerStreetRegStr,
                      cv.RGB(0, 255, 0), 1)

        modeStr = "Current mode: '" + processMode + "'"
        if trackingRegions['flowWarpMatrix'] is None:
            modeStr = modeStr + " (configuring)"
        if processMode == 'delay':
            secBetweenFrames = delayBetweenFrames / 1000.0
            modeStr = (modeStr + " ( %.03f sec )") % secBetweenFrames
        draw.drawText(stateWindowImage, modeStr, cv.RGB(255, 255, 0), 0)
        timeString = "Statistic begin: " + time.strftime(
            "%Y.%m.%d %H:%M:%S", time.localtime(firstFrameTime))
        timeString += " (%.2f min)" % (
            (currentFrameTime - firstFrameTime) / 60.0)
        draw.drawText(stateWindowImage, timeString, cv.RGB(0, 155, 0), 1)
        draw.drawText(
            stateWindowImage, "Time of the frame: " + time.strftime(
                "%Y.%m.%d %H:%M:%S", time.localtime(currentFrameTime)),
            cv.RGB(0, 155, 0), 2)
        draw.drawText(stateWindowImage,
                      "Total number of people: %d" % currPeopleCount,
                      cv.RGB(0, 255, 0), 3)
        draw.drawText(stateWindowImage,
                      "Frame queue length: %d" % frameQueueLenght,
                      cv.RGB(0, 255, 0), 4)
        if frame is None:
            draw.drawText(stateWindowImage, "No any frame", cv.RGB(255, 0, 0),
                          5)

        draw.drawText(stateWindowImage, "'a' - 'auto' mode",
                      cv.RGB(0, 155, 155), 7)
        draw.drawText(stateWindowImage,
                      "'p' - 'pause' mode ('right' - next, 'up' - 10 next)",
                      cv.RGB(0, 155, 155), 8)
        draw.drawText(stateWindowImage,
                      "'d' - 'delay' mode (arrows change delay time)",
                      cv.RGB(0, 155, 155), 9)
        draw.drawText(stateWindowImage, "'q' - Quit", cv.RGB(0, 155, 155), 10)

        ##################################
        # Update windows
        cv2.imshow(configWindow, configWindowImage)
        cv2.imshow(densityWindow, densityWindowImage)
        cv2.imshow(stateWindow, stateWindowImage)
        cv2.imshow(statisticWindow, statisticWindowImage)

        # Save current file
        if not processMode in (
                "pause", "egomotion") or currentFrameTime != previousFrameTime:
            frm = previousFrame
            previousFrame = currentFrame
            previousTrackedFrame = currentTrackedFrame
            currentFrame = frm
            previousFrameTime = currentFrameTime
            imageSequence.moveProcessedFrames(currentFrameTime)
            logState(currentFileName, currentFrameTime, crowdDensity,
                     currPeopleCount)