Python Pygame夹具IP故障?

Python Pygame夹具IP故障?,python,python-3.x,github,pygame,Python,Python 3.x,Github,Pygame,我对pygame的climp_ip()方法有问题。我似乎不明白问题出在哪里。我的相机有一个矩形,叫做player.climp\u ip(相机),但它无法夹紧。我的代码在github上。我还使用Python3.4运行最新的pygame。另一件令人担忧的事情是,它不会抛出错误 Github链接: 提前谢谢 我用一个矩形显示了摄像头,但它不在屏幕上。请在这里发布相关代码,这样读起来比打开github链接更容易。SuperBiasedMan,我看不出缩进…没关系。。。找到了! import pygame

我对pygame的climp_ip()方法有问题。我似乎不明白问题出在哪里。我的相机有一个矩形,叫做
player.climp\u ip(相机)
,但它无法夹紧。我的代码在github上。我还使用Python3.4运行最新的pygame。另一件令人担忧的事情是,它不会抛出错误

Github链接:


提前谢谢

我用一个矩形显示了摄像头,但它不在屏幕上。

请在这里发布相关代码,这样读起来比打开github链接更容易。SuperBiasedMan,我看不出缩进…没关系。。。找到了!
import pygame #3rd-party libraries
import os, sys #Standard libraries
importpath = os.path.split(os.getcwd())
importpath = os.path.join(importpath[0], "libraries")
sys.path.append(importpath) #Allow us to import the library

import resourcemanager #Project-specific library
import player as player_
import pygnamelib #3rd-party libraries 
from logHelper import *



def run(screenRect, gameScreen, boundaryRect):
    camera = pygame.rect.Rect(0, 0, 640, 480)
    def eventhandler(player, textures, gamevariables, event, keyinput, gameScreen, fx):  #Handle events
        returntext = False

        ##Player movement

        if keyinput[pygame.K_ESCAPE] or event.type == pygame.QUIT: #If the player presses escape, exit the game
            returntext = 'End'

        if keyinput[pygame.K_UP] and (keyinput[pygame.K_LEFT] or keyinput[pygame.K_RIGHT]):
            player.rect.y = player.rect.y - player.SPEED / 2
            camera.y = camera.y - player.SPEED
            log("Moved 1 block up")

            if keyinput[pygame.K_LEFT]:
                player.rect.x = player.rect.x - player.SPEED / 2
                camera.x = camera.x - player.SPEED
                log("Moved 1 block left")

            elif keyinput[pygame.K_RIGHT]:
                player.rect.x = player.rect.x + int(player.SPEED / 2)
                camera.x = camera.x + player.SPEED
                log('Moved 1 block right')


        elif keyinput[pygame.K_UP]:
            player.rect.y = player.rect.y - player.SPEED
            camera.y = camera.y - player.SPEED * 2
            log("Moved 1 block up")

        if keyinput[pygame.K_DOWN] and (keyinput[pygame.K_LEFT] or keyinput[pygame.K_RIGHT]):
            player.rect.y = player.rect.y + player.SPEED / 2
            camera.y = camera.y + player.SPEED
            log('Moved one block down')
            if keyinput[pygame.K_LEFT]:
                player.rect.x = player.rect.x - player.SPEED / 2
                camera.x = camera.x - player.SPEED
                log("Moved 1 block left")

            elif keyinput[pygame.K_RIGHT]:
                player.rect.x = player.rect.x + player.SPEED / 2
                camera.x = camera.x + player.SPEED
                log('Moved 1 block right')

        elif keyinput[pygame.K_DOWN]:
            player.rect.y = player.rect.y + player.SPEED
            camera.y = camera.y + player.SPEED *2
            log('Moved one block down')

        if keyinput[pygame.K_LEFT]:
            player.rect.x = player.rect.x - player.SPEED
            camera.x = camera.x - player.SPEED*2
            log("Moved 1 block left")

        if keyinput[pygame.K_RIGHT]:
            player.rect.x = player.rect.x + player.SPEED
            camera.x = camera.x + player.SPEED*2
            log('Moved 1 block right')



        ##Other Keybindings

        if keyinput[pygame.K_RETURN]:
            if player.rect.colliderect(textures.carrotfieldrect) and gamevariables['blitcarrotfield']:
                gamevariables['blitcarrotfield'] = False
                player.inventory['Carrots'] = 20

        if keyinput[pygame.K_i]:
            log('Inventory')
            printtext(gameScreen, str(player.inventory).replace('{','').replace('}','').replace(',',';').replace('"',''), textures,          gamevariables['blitcarrotfield'], player)
           # pygame.mixer.music.play(fx.openinv)

        if keyinput[pygame.K_F11]:
            pygame.display.toggle_fullscreen()

        if returntext != False:
            return returntext



    ##Blitting


    def blit(displayScreen, vardict, Textures, Player):
        if vardict['surroundings'] == 'Start':
            displayScreen.blit(Textures.map,(0-int(camera.x),0 - gamevariables['cameray']))
            displayScreen.blit(Textures.smithy,(Textures.smithyrect.x - gamevariables['camerax'], Textures.smithyrect.y - gamevariables['cameray'] ))
            displayScreen.blit(Textures.faldorhouse,(Textures.faldorhouserect.x - gamevariables['camerax'], Textures.faldorhouserect.y - gamevariables['cameray']))
            if vardict['blitcarrotfield'] == True:
                displayScreen.blit(Textures.carrotfield,(Textures.carrotfieldrect.x - gamevariables['camerax'], Textures.carrotfieldrect.y - gamevariables['cameray']))
            else:
                displayScreen.blit(Textures.carrotfield_depleted,(Textures.carrotfieldrect.x - gamevariables['camerax'], Textures.carrotfieldrect.y - gamevariables['cameray']))
            displayScreen.blit(Textures.brillhouse,(Textures.brillhouserect.x - gamevariables['camerax'],Textures.brillhouserect.y - gamevariables['cameray']))
            displayScreen.blit(Textures.stable,(Textures.stablerect.x- gamevariables['camerax'], Textures.stablerect.y - gamevariables['cameray']))
            displayScreen.blit(Player.player,Player.rect)
            pygame.display.flip()
        if vardict['surroundings'] == 'End':
            displayScreen.blit(Textures.map,(0,0))
            displayScreen.blit(Player.player,(Player.rect.x,player.rect.y))


    ##Setup

    pack = "Default-Texture-Pack" #DEBUGGING PURPOSES
    log('Using texturepack '+pack)
    log('Texturepack is located in "'+'./rescources/textures/'+pack+'.zip'+'"')
    resourcemanager.setpack(pack)    #Load texturepack
    pygame.key.set_repeat(1,10)      #Set holdingdown key to continous movemont
    textures = resourcemanager.textures('FaldorFarm') #Copy 'texturepack' object
    test = resourcemanager.testpack(textures, os.path.join( os.getcwd(),'resources','packs',pack+'.zip'))
    result = test[0]
    if result == True:
        try:
            F = open(os.path.join(os.getcwd(), 'resources', 'packs',pack+'.zip'))
            F.close()
            log('Valid texturepack, continuing with game setup...')
        except:
            log('Texturepack invalid, using default texturepack located in "'+'./rescources/default/Default-Texture-Pack.zip"')
    if result == False:
        log('Texturepack invalid, using default texturepack located in "'+'./rescources/default/Default-Texture-Pack.zip"')
        resourcemanager.setpack('Default-Texture-Pack')
        textures = resourcemanager.textures()
    player = player_._player(pack) #Create the player
    player.inventory['Stuff'] = ''
    sounds = resourcemanager.soundfx(pack)
    log("Sound's loaded from ./rescources/sounds/")

    log('Job "Textures & Objects" completed successfully')

    #Game Variables
    gamevariables = {  'blitcarrotfield':True, 'surroundings':'Start', 'endofgame':False, 'camerax': 320, 'cameray':240  } #Create the variable dictionary

    #Storyline...
    printtext(gameScreen, 'Once there was a storyline', textures, gamevariables['blitcarrotfield'], player, timeout=5)

    log('Game Setup successfully completed\n')




    ##Mainloop
    while True: 

        for event in pygame.event.get(): #Event loop
            events = eventhandler(player, textures, gamevariables, event, pygame.key.get_pressed(), gameScreen, sounds) #Handle events
            if events == 'End':
                gamevariables['endofgame'] = True
        blit(gameScreen, gamevariables, textures, player) #Blit objects
        gamevariables['camerax'] = camera.x
        gamevariables['cameray'] = camera.y

        player.rect.clamp_ip(boundaryRect)
        player.rect.clamp_ip(screenRect)
        player.rect.clamp_ip(camera)
        camera.clamp_ip(boundaryRect)
        pygame.display.flip()

        if gamevariables['endofgame']: #If the game has ended:
            pygame.quit()
            log('----- Game end -----')
            stoplog = True
            logfile.close()
            sys.exit(0)