def __init__(self, x, y, z, Width, Height, Depth, life, speed, name, centered=False): self.name = name self.pos = vec3(x, y, z) self.scale = vec3(Width, Height, Depth) self.rotation = 0 self.worldMatrix = None self.setWorldMatrix() self.Width = Width self.Height = Height self.Depth = Depth self.life = life self.speed = speed #self.hitBox = BoundingBox(self.pos, vec3(x+Width, y+Height, z+Depth)) self.deathFadeT = globs.bulletLife self.State = globs.ALIVE self.fadeTime = 0 self.centered = centered if Entity.vao == None: vbuff = array.array("f") centerVbuff = array.array("f") tbuff = array.array("f") centerTBuff = array.array("f") ibuff = array.array("I") centerIBuff = array.array("I") Shapes.createSquare( vbuff, 1, 1, 0, 0) #create vbuff of square that is 1 by 1 at center of screen Shapes.createSquare(centerVbuff, 1, 1, 0, 0, True) Shapes.createSquareIndexArray(ibuff) Shapes.createSquareIndexArray(centerIBuff, True) Shapes.createSquareTextureArray(tbuff) Shapes.createSquareTextureArray(centerTBuff, 1, True) Entity.vao = glCommands.setup(vbuff, tbuff, ibuff) Entity.centerVao = glCommands.setup(centerVbuff, centerTBuff, centerIBuff) Entity.ibuffSize = len(ibuff) Entity.ibuffCenterSize = len(centerIBuff) Entity.ibuffStart = 0 Entity.prog = Program("vs.txt", "fs.txt")
def __init__(self, x, y, size): self.pos = math3d.vec2(x, y) self.size = size if mapSquare.vbuff == None or mapSquare.tbuff == None or mapSquare.ibuff == None: mapSquare.vbuff = array.array("f") mapSquare.tbuff = array.array("f") mapSquare.ibuff = array.array("I") mapSquare.tex = ImageTexture2DArray(globs.mapTextures) Shapes.createSquare(mapSquare.vbuff, self.size, self.pox.x, self.pos.y) Shapes.createSquareIndexArray(mapSquare.ibuff) glCommands.setup(mapSquare.vbuff, mapSquare.ibuff, mapSquare.tbuff)
def __init__(self): with open(os.path.join("assets", "map.tmx")) as fp: data = fp.read() i = data.find("<data ") j = data.find("</data>") tiles = data[i:j] i = tiles.find(">") tiles = tiles[i + 1:].strip() L = tiles.split("\n") outputList = [] for line in L: if line.endswith(","): line = line[:-1] outputList.append([int(q) for q in line.split(",")]) self.tileList = outputList self.pos = math3d.vec2(0, 0) self.size = 2 / len(self.tileList) self.texList = [] if Map.vao == None: Map.vbuff = array.array("f") Map.tbuff = array.array("f") Map.ibuff = array.array("I") for i in range(len(globs.mapTextures)): self.texList.append( ImageTexture2DArray.ImageTexture2DArray( globs.mapTextures[i])) Shapes.createSquare(Map.vbuff, self.size, self.size, -1, -1) Shapes.createSquareTextureArray(Map.tbuff) Shapes.createSquareIndexArray(Map.ibuff) self.vao = glCommands.setup(Map.vbuff, Map.tbuff, Map.ibuff)
def __init__(self, x, y, direction, Width, Height, life, speed): self.pos = math3d.vec2(x, y) self.scale = math3d.vec2(Width, Height) self.Width = Width self.Height = Height self.dir = direction self.life = life self.speed = speed if Entity.vao == None: vbuff = array.array("f") tbuff = array.array("f") ibuff = array.array("I") Entity.ibuffSize = len(ibuff) Entity.ibuffStart = 0 Shapes.createSquare( vbuff, 1, 1, 0, 0) #create vbuff of square that is 1 by 1 at center of screen Shapes.createSquareIndexArray(ibuff) Shapes.createSquareTextureArray(tbuff) Entity.vao = glCommands.setup(vbuff, tbuff, ibuff) Entity.ibuffSize = len(ibuff) Entity.ibuffStart = 0
def __init__(self, x, y, size): self.pos = math3d.vec2(x, y) #set players start position self.crouchScale = math3d.vec2(1, .5) self.crouching = False self.direction = 0 #-1:Left, 1:Right self.lastFired = 0 #Time since last Fired self.state = globs.ON_GROUND #State player is in self.life = 10 #amount of life left self.size = size #Scale of player self.halfSize = size / 2 #half scale of player #''' if Player.vao == None: Player.vbuff = array.array("f") Player.tbuff = array.array("f") Player.ibuff = array.array("I") Shapes.createSquare(Player.vbuff, size, size, x, y) Shapes.createSquareTextureArray(Player.tbuff) Shapes.createSquareIndexArray(Player.ibuff) Player.vao = glCommands.setup(Player.vbuff, Player.tbuff, Player.ibuff) #''' #super().__init__() if Player.tex == None: Player.tex = ImageTexture2DArray.ImageTexture2DArray( *globs.playerTextures)
def __init__(self, x, y, direction, Width, Height, life, speed): self.pos = math3d.vec2(x, y) self.scale = math3d.vec2(Width, Height) self.Width = Width self.Height = Height self.dir = direction self.life = life self.speed = speed self.hitBox = BoundingBox(self.pos, math3d.vec2(x + Width, y + Height)) self.deathFadeT = globs.bulletLife self.State = globs.ALIVE self.fadeTime = 0 if Entity.vao == None: vbuff = array.array("f") tbuff = array.array("f") ibuff = array.array("I") Entity.ibuffSize = len(ibuff) Entity.ibuffStart = 0 Shapes.createSquare( vbuff, 1, 1, 0, 0) #create vbuff of square that is 1 by 1 at center of screen Shapes.createSquareIndexArray(ibuff) Shapes.createSquareTextureArray(tbuff) Entity.vao = glCommands.setup(vbuff, tbuff, ibuff) Entity.ibuffSize = len(ibuff) Entity.ibuffStart = 0 Entity.prog = Program("vs.txt", "fs.txt")
def __init__(self, x, y): self.pos = math3d.vec2(x, y) if StarBackground.vbuff == None: StarBackground.vbuff = array.array("f") StarBackground.tbuff = array.array("f") Shapes.createRandPoints(StarBackground.vbuff, globs.numStars) Shapes.createSquareTextureArray(self.tbuff) StarBackground.vao = glCommands.setup(StarBackground.vbuff, StarBackground.tbuff) StarBackground.tex = ImageTexture2DArray(*globs.starTextures) StarBackground.prog = Program("vs.txt", "fs.txt")
def __init__(self): if Entity.vao == None: print("making vao") vbuff = array.array("f") tbuff = array.array("f") ibuff = array.array("f") Entity.ibuffSize = len(ibuff) Entity.ibuffStart = 0 Shapes.createSquare(vbuff, 1, 1) #create vbuff of square that is 1 by 1 Shapes.createTriangleIndexArray(ibuff) Shapes.createSquareTextureArray(tbuff) Entity.vao = glCommands.setup(vbuff, tbuff, ibuff)
def __init__(self, startPos): self.life = globs.particleLife self.currentTime = 0 self.startTime = 0 self.worldMatrix = translation2(startPos) if ParticleSystem.vao == None: vbuff = array.array("f") tbuff = array.array("f") Shapes.createRandPoints(vbuff, globs.particleCount) #Create randomVelocities tbuff = Shapes.createSquareTextureArray(tbuff) ParticleSystem.vao = glCommands.setup(vbuff, tbuff) ParticleSystem.vSize = len(vbuff) ParticleSystem.tex = ImageTexture2DArray(globs.starTextures[0]) ParticleSystem.prog = Program("particleVS.txt", "particleFS.txt")
def __init__(self, x, y, direction, size=.05): self.pos = math3d.vec2(x, y) self.dir = direction self.life = 750 if Bullet.vbuff == None and Bullet.ibuff == None: Bullet.vbuff = array.array("f") Bullet.tbuff = array.array("f") Bullet.ibuff = array.array("I") Bullet.tex = ImageTexture2DArray.ImageTexture2DArray( globs.bulletTextures[0]) Shapes.createSquare(Bullet.vbuff, size, size, x, y) Shapes.createSquareTextureArray(Bullet.tbuff) Shapes.createSquareIndexArray(Bullet.ibuff) Bullet.vao = glCommands.setup(Bullet.vbuff, Bullet.tbuff, Bullet.ibuff) self.playSound()
def __init__(self, f): self.fname = os.path.join("assets", f) self.materialDict = {} curMat = None VertexPoints = [] # Vertex Vec3 Points for Mesh Normals = [] TexturePoints = [] # Texture Vec2 Points for Mesh IndexPoints = {} # Index Points in vertex points and texture points with open(self.fname) as fp: for line in fp: line = line.strip() if line.startswith("#"): # line is a Comment ignore it continue elif line.startswith( "mtllib" ): # Get Meshes material file name and get its textures matfname = line[7:] self.materialDict = self.parseMtl(matfname) elif line.startswith("v "): # Get Meshes vertex points vertices = line.split() VertexPoints.append( vec3(float(vertices[1]), float(vertices[2]), float(vertices[3]))) elif line.startswith("vt"): # Get Meshes Texture points texturePoints = line.split() TexturePoints.append( vec2(float(texturePoints[1]), float(texturePoints[2]))) elif line.startswith("vn"): # Get Meshes Normal points normalPoints = line.split() Normals.append( vec3(float(normalPoints[1]), float(normalPoints[2]), float(normalPoints[3]))) elif line.startswith("usemtl"): # Set CurrentMaterial curMat = line.split()[1] if curMat not in IndexPoints: IndexPoints[curMat] = [] elif line.startswith( "f " ): # Set CurrentMaterials Vertex Points, Texture Points, and Normals fLine = line.split() if len(fLine) != 4: raise Exception("Not Triangles") for VSpec in fLine[1:]: pointPack = VSpec.split('/') if len(pointPack) != 3: raise Exception( "Expected vi / ti / ni, instead got: ", pointPack) if pointPack[1] == "": raise Exception( "Expected vertex index, instead got None!!! pointPack contains: ", pointPack) vi = int(pointPack[0]) - 1 # Set Vertice Index ti = int(pointPack[1]) - 1 # Set Texture Index #ni = int(pointPack[2]) - 1 # Set Normal Index IndexPoints[curMat].append((vi, ti)) tmp = array.array("I", [0]) # Set vao glGenVertexArrays(1, tmp) self.vao = tmp[0] vmap = {} # key = (vi,ti), Val = index p = [] t = [] # n = [] i = [] numV = 0 self.matDict = {} # key = matName, Val = (startIndex, size) for matName in IndexPoints: # Foreach key # Set Start starting point into point set, and number of indices for point set for material self.matDict[matName] = (len(i) * 4, len(IndexPoints[matName])) for vi, ti in IndexPoints[matName]: # Foreach value pair key = (vi, ti) if key not in vmap: # Append key to dictionary if not already there vmap[key] = numV numV += 1 # Set Vertex Values, 3 floats per point p.append(VertexPoints[vi].x) p.append(VertexPoints[vi].y) #p.append(VertexPoints[vi].z) # Set Texture Values, 2 floats per point t.append(TexturePoints[ti].x) t.append(TexturePoints[ti].y) # Set Normal values, 3 floats per point # n.append(Normals[ni].x) # n.append(Normals[ni].y) # n.append(Normals[ni].z) i.append(vmap[key] ) # Append Index into dictionary for point value set pointBuf = array.array("f", p) # Create Point Buffer texBuf = array.array("f", t) # Create Texture Buffer indexBuf = array.array("I", i) # Create Index buffer for index points self.vao = glCommands.setup(pointBuf, texBuf, indexBuf)