def __init__(self, layer=0, color=sf.Color.WHITE, texture=None): super(SpriteEntity, self).__init__(layer) (sf.Sprite, self).__init__(texture=texture) self.sprite = sf.Sprite(texture) self.sprite.color = color self.ratio = sf.Vector2(1.0, 1.0) self.origin = sf.Vector2(0.5, 0.5) self.__renderstate = sf.RenderStates()
def __init__(self, text): super(TextEntity, self).__init__() self.text = sf.Text(text) self.text.font = FM.get("fonts/toscuchet.otf") self.text.color = sf.Color.WHITE self.text.character_size = 72 self.__renderstate = sf.RenderStates()
def __init__(self, layer=0, color=sf.Color.WHITE, texture=None, fullscreen=True): super(ScreenSpriteEntity, self).__init__(layer, color, texture) self.fullscreen = fullscreen self.__renderstate = sf.RenderStates()
def _Get_Render_State(sName, sFileName): #Check to see if that filename is listed in our dictionary already. if Asset_Manager.dRenderStates.get(sName, None) != None: #We can now just return the SFML object that is within the dictionary. return Asset_Manager.dRenderStates[sName] else: #We must create a new SFML Texture object while using the sFileName to load in a font. texture = sf.Texture.load_from_file('Resources/Textures/'+sFileName) Asset_Manager.dRenderStates[sName] = sf.RenderStates(sf.BLEND_ALPHA, None, texture) #We can now just return the SFML object that is within the dictionary. return Asset_Manager.dRenderStates[sName]
def shoot_effect(self): self.game.window.draw(self.game.active_tank, sf.RenderStates(sf.BLEND_ADD)) self.game.window.display() # TODO: Improve this effect and check ammo before displaying it
def __init__( self, chunkPosition, chunkInWindow ): #viewCoords is a tuple of integers containing the world chunk position for the top left chunk on the window self._x_World_Chunk_Position = chunkPosition[0] self._y_World_Chunk_Position = chunkPosition[1] self._chunks_In_Window_X = chunkInWindow[0] self._chunks_In_Window_Y = chunkInWindow[1] self._chunk_Dict = {} #This stores all of the chunks (even outside of the wndow) around the area in the world the window's position is. #These will all contain chunk pointers to the _chunk_Dict's chunks that apply self._load_List = [] self._rebuild_List = [] self._unload_List = [] self._flag_List = [] self._render_List = [] #This tells us whether or not a chunk's contents have rebuilt or loaded self._force_Visibility_Update = False try: os.makedirs(config.Chunk_Directory) except OSError as e: if e.errno != errno.EEXIST: raise #Here we must add in the chunks that are visible to the screen into our chunk dictionary (along with our buffer of chunks outside of the screen.) for i in xrange( self._x_World_Chunk_Position-1, self._x_World_Chunk_Position + self._chunks_In_Window_X+1 ): for j in xrange( self._y_World_Chunk_Position-1, self._y_World_Chunk_Position + self._chunks_In_Window_Y+1 ): #This will initialize us a new chunk to use self._chunk_Dict[(i,j)] = Chunk() pChunk = self._chunk_Dict[(i,j)] #This creates a pointer to our chunk in the chunk dictionary pChunk._window_Position = [ i - self._x_World_Chunk_Position, j - self._y_World_Chunk_Position ] #This will set the chunk's position within the window (starting from the top-left.) pChunk._world_Position = (i,j) self._load_List.append(pChunk) #Here we store our pointer in the load list, so that the chunk can have its data loaded self._tile_Atlas_List = [] #This updates our global tile_Atlas_List variable to contain the textures for the tile atlases of each chunk layer for layer in xrange(config.CHUNK_LAYERS): try: self._tile_Atlas_List.append(sf.RenderStates(-1, None, sf.Texture.load_from_file('Resources/tileAtlas'+str(layer)+'.png'), None)) except sf.PySFMLException: print "The tileAtlasX.png doesn't exist yet!\nConverting .jpg version to .png now!" oldImg = sf.Image.load_from_file('Resources/tileAtlas'+str(layer)+'.bmp') newImg = sf.Image.load_from_pixels(oldImg.width, oldImg.height, oldImg.get_pixels()) newImg.create_mask_from_color(sf.Color(255,0,255), 0) print newImg[70,0] newImg.save_to_file('Resources/tileAtlas'+str(layer)+'.png') self._tile_Atlas_List.append(sf.RenderStates(-1, None, sf.Texture.load_from_file('Resources/tileAtlas'+str(layer)+'.png'), None))