Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python参数TypeError使用我自己新制作的游戏框架_Python_Pygame - Fatal编程技术网

Python参数TypeError使用我自己新制作的游戏框架

Python参数TypeError使用我自己新制作的游戏框架,python,pygame,Python,Pygame,我正在使用自己新制作的框架用Python制作一个游戏,但我遇到了以下错误: 我不明白我做错了什么 游戏文件: 导入pygame 导入操作系统 从dev.nils.pythonGame.framework.objectHandler导入* 班级游戏: 定义初始化(自): self.screen_size=(1280720) self.window=pygame.display.set_模式(self.screen_大小) self.screen=pygame.Surface((int(self.s

我正在使用自己新制作的框架用Python制作一个游戏,但我遇到了以下错误:

我不明白我做错了什么

游戏文件:

导入pygame
导入操作系统
从dev.nils.pythonGame.framework.objectHandler导入*
班级游戏:
定义初始化(自):
self.screen_size=(1280720)
self.window=pygame.display.set_模式(self.screen_大小)
self.screen=pygame.Surface((int(self.screen\u size[0]/3)、int(self.screen\u size[1]/3)))
self.fps=60
self.running=True
self.bgcolor=(0,0,0)
self.clock=pygame.time.clock()
self.handler=handler(“D:/PyCharm/pythonGame/dev/nils/pythonGame/game/levelDesign/map.txt”,self.screen)
def事件(自):
对于pygame.event.get()中的事件:
如果event.type==pygame.QUIT:
self.running=False
def牵引(自):
self.screen.fill(self.bgcolor)
drawTiles(self.screen、self.handler.getTileList())
self.handler.draw()
blit(pygame.transform.scale(self.screen,self.screen\u size),(0,0))
pygame.display.update()
def更新(自我):
self.handler.update()
def运行(自):
自运行时:
self.events()
self.update()
self.draw()
self.clock.tick(self.fps)
pygame.quit()
退出()
def main():
操作系统环境[“以SDL\U视频为中心”]=“1”
pygame.init()
Game().run()
如果名称=“\uuuuu main\uuuuuuuu”:
main()
播放器文件:

import pygame
from dev.nils.pythonGame.framework.physicsObject import *


class Player(PhysicsObject):
    def __init__(self, x:int, y:int, xSize:int, ySize:int):
        PhysicsObject.__init__(self, x, y, xSize, ySize)

    def update(self, collisionList:[]):
        self.collisions2D(self.rect, collisionList)
    
    def draw(self, screen:pygame.Surface):
        pygame.draw.rect(screen, (255,255,255), self.rect)
平铺文件:

导入pygame
从dev.nils.pythonGame.framework.physicsObject导入physicsObject
类平铺(PhysicsObject):
定义初始化(self,x:int,y:int,xSize:int,ySize:int):
PhysicsObject.\uuuu初始化(self,x,y,xSize,ySize)
def getCollisionList(objectRect:pygame.Rect,tileList:[]):
冲突=[]
对于瓷砖列表中的瓷砖:
印刷品(瓷砖)
如果objectRect.colliderect(平铺[1].rect):
冲突。追加(平铺)
返回碰撞
def drawTiles(屏幕:pygame.Surface,tileList:[]):
对于瓷砖列表中的瓷砖:
如果平铺[0]=“1”:
pygame.draw.rect(屏幕,(255255255),(分幅[1].rect.x,分幅[1].rect.y,分幅[1].rect.width,分幅[1].rect.height))
对象处理程序:

import pygame
from dev.nils.pythonGame.game.objects.tile import *
from dev.nils.pythonGame.game.objects.player import *
from dev.nils.pythonGame.framework.physicsObject import *


class Handler:
    def __init__(self, path: str, screen: pygame.Surface):
        self.path = path
        self.objects = {
            "player":Player(0, 0, 32, 32)
        }
        self.screen = screen
        self.tileList = self.getTileList()

    def update(self):
        for object in self.objects.values():
            object.update(getCollisionList(object.rect, self.tileList))

    def draw(self):
        for object in self.objects.values():
            object.draw(self.screen)

    def getTileList(self):
        tiles = []
        x = 0
        y = 0
        with open(self.path) as map:
            map = list(map)
            for row in map:
                x = 0
                for tile in row:
                    tiles.append([tile, PhysicsObject(x, y, 16, 16)])
                    x += 1
                y += 1
        return tiles
和物理对象文件:

导入pygame
类物理对象:
定义初始化(self,x:int,y:int,xSize:int,ySize:int):
self.xVel=0.0
self.yVel=0.0
self.xSize=xSize
self.ySize=ySize
self.rect=pygame.rect(x*self.xSize,y*self.ySize,xSize,ySize)
self.collisionTypes={}
def碰撞2D(自身,碰撞列表:[]):
self.collisionTypes={“left”:False,“right”:False,“top”:False,“bottom”:False}
self.rect.x+=self.xVel
对于collisionList中的对象:
如果self.xVel>0:
self.rect.right=object.left
self.collisionTypes[“left”]=True
如果self.xVel<0:
self.rect.left=object.right
self.collisionTypes[“right”]=True
self.rect.y+=self.yVel
对于collisionList中的对象:
如果self.yVel>0:
self.rect.bottom=object.top
self.collisionTypes[“top”]=True
如果self.yVel<0:
self.rect.top=object.bottom
self.collisionTypes[“bottom”]=True

冲突2d
是一个带有签名的:

def collisions2D(self,collisionList:[]):
必须按如下方式调用该方法

self.collisions2D(self.rect,collisionList)

self.collisions2D(冲突列表)
import pygame
from dev.nils.pythonGame.game.objects.tile import *
from dev.nils.pythonGame.game.objects.player import *
from dev.nils.pythonGame.framework.physicsObject import *


class Handler:
    def __init__(self, path: str, screen: pygame.Surface):
        self.path = path
        self.objects = {
            "player":Player(0, 0, 32, 32)
        }
        self.screen = screen
        self.tileList = self.getTileList()

    def update(self):
        for object in self.objects.values():
            object.update(getCollisionList(object.rect, self.tileList))

    def draw(self):
        for object in self.objects.values():
            object.draw(self.screen)

    def getTileList(self):
        tiles = []
        x = 0
        y = 0
        with open(self.path) as map:
            map = list(map)
            for row in map:
                x = 0
                for tile in row:
                    tiles.append([tile, PhysicsObject(x, y, 16, 16)])
                    x += 1
                y += 1
        return tiles