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 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, 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): 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): 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, 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 draw(self): glBindVertexArray(self.vao) tileHeight = len(self.tileList) for i in range(tileHeight): tmpI = tileHeight - i - 1 row = self.tileList[tmpI] tileWidth = len(row) yVal = self.pos.y + (i * (2 / tileHeight)) for j in range(tileWidth): xVal = self.pos.x + (j * (2 / tileWidth)) glCommands.changeUniform(math3d.vec2(xVal, yVal)) self.texList[row[j] - 1].bind(0) glDrawElements(GL_TRIANGLES, len(self.ibuff), GL_UNSIGNED_INT, 0)
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 changeUniform(translationVec, scalingVec=math3d.vec2(1, 1)): Program.setUniform("translation", translationVec) Program.setUniform("scaling", scalingVec) Program.updateUniforms()