def updateInitials(self, entity): # no checking for which one is updated # just draws them all again colors = ( px_graphics.Color(1, 1, 0, 1), px_graphics.Color(0, 1, 1, 1), px_graphics.Color(1, 0, 1, 1), ) for i in range(0, 3): self.render_layer.replaceImageFromString( old_image=self.initial_images[i], string=entity.controller_data.initials[i], font=self.font, color=colors[i])
def updatePlay(self, dt): # kill # draw score self.renlayer.setColorCast(px_graphics.Color(1, 1, 1, 1)) if self.current_score!= self.old_score: # update score since it's changed self.overlay_renlayer.replaceImageFromString(old_image=self.score_image, string="{0:0=4d}".format(self.current_score), font=self.score_font, color=px_graphics.Color(1, 1, 1, 1)) self.old_score = self.current_score
def __init__(self, game, data): super(NewScore, self).__init__(game) self.render_layer = data["RenderLayer"] self.font = self.render_layer.addFont("Fonts/Silom/Silom.ttf", 48) self.initial_images = [] colors = ( px_graphics.Color(1, 1, 0, 1), px_graphics.Color(0, 1, 1, 1), px_graphics.Color(1, 0, 1, 1), ) for i in range(0, 3): self.initial_images.append( self.render_layer.addImageFromString(string="A", font=self.font, color=colors[i]))
def withRender(cls, font_manager, string, font=0, color=px_graphics.Color(1, 1, 1, 1), size=12): message = Message(font_manager, string, font, color, size) message.renderToTexture() return message
def updateScores(self, entity): for i in range(0, 10): score, r, g, b = self.formatScore(i, entity.scores_data[i][0], entity.scores_data[i][1]) self.render_layer.replaceImageFromString(entity.images[i], string=score, font=self.font, color=px_graphics.Color( r, g, b, 255))
def director_bunny_select(game): return [ SetRenderLayerColor('game', Color(0, 0, 0, 0)), SetRenderLayerColor('overlay', Color(0, 0, 0, 0)), FadeToClearColor(Color.fromInts(0, 0, 0), 1), Message("Choose your bunny:", Vec3(240, 220, 0), Color(1, 1, 1, 1), -1, px_graphics.eAlign.centre), MakeEntity('pacbun choose', data={ 'pos': Vec3(210, 160, 0), 'parent': 'bunny choice', 'bun num': 0, 'bun name': 'Pac-Bun', 'message color': px_graphics.Color(1, 1, 0, 1), }), MakeEntity('pinkie choose', data={ 'pos': Vec3(230, 160, 0), 'parent': 'bunny choice', 'bun num': 1, 'bun name': 'Pinkie', 'message color': px_graphics.Color(1, 0.8, 0.8, 1), }), MakeEntity('blue choose', data={ 'pos': Vec3(250, 160, 0), 'parent': 'bunny choice', 'bun num': 2, 'bun name': 'Blue', 'message color': px_graphics.Color(0.5, 0.5, 1.0, 1), }), MakeEntity('bowie choose', data={ 'pos': Vec3(270, 160, 0), 'parent': 'bunny choice', 'bun num': 3, 'bun name': 'Bowie', 'message color': px_graphics.Color(1, 1, 1.0, 1), }), FadeRenderLayer('overlay', Color(1, 1, 1, 1), 1), FadeRenderLayer('game', Color(1, 1, 1, 1), 1), WaitForFlag('next_scene'), MakeDirector('fade_to_mode', 'play') ]
def __init__(self, font_manager, string, font=0, color=px_graphics.Color(1, 1, 1, 1), size=12): self.string = string self.font_manager = font_manager self.font = font self.color = color self.size = size
def renderTextToSurfaceAndSave(self, file, string, font=False, color=px_graphics.Color(1, 1, 1, 1)): surf = sdl2.sdlttf.TTF_RenderUTF8_Solid(self.sdl_fonts[font].font, string.encode('utf-8'), color) if surf is None: log(f"TTF_RenderText failed: {string}") width = surf.contents.w height = surf.contents.h return width, height
def init(entity): entity.images = [] for i in range(0, 10): score, r, g, b = formatScore(i, entity.scores_data[i][0], entity.scores_data[i][1]) # todo: make this a little less hacky graphics = entity.getComponent('graphics') entity.images.append( graphics.render_layer.addImageFromString(string=score, font=graphics.font, color=px_graphics.Color( r, g, b, 1)))
def update(self, entity, dt): current_color = entity.game.getClearColor() if not self.step_color: # get the incremental color, effectively the vector towards the final color # only calculate this once - but has to be when fade starts, not when instance created # (director creates instances of Events when director is created) self.step_color = px_graphics.Color( (self.color.r - current_color.r) / self.time, (self.color.g - current_color.g) / self.time, (self.color.b - current_color.b) / self.time, (self.color.a - current_color.a) / self.time, ) # check when to stop self.time -= dt if self.time <= 0: entity.game.setClearColor( self.color) # make sure completely get to color desired return eEventStates.dead entity.game.setClearColor(self.step_color * px_graphics.Color(dt, dt, dt, dt) + current_color) return eEventStates.live
def draw(self, entity): offset_x = 0 offset_y = 0 if entity.align == px_graphics.eAlign.centre: offset_x, offset_y = entity.ren_layer.getImageDimensions( entity.image) offset_x /= 2 offset_y /= 2 elif entity.align == px_graphics.eAlign.centre: offset_x, offset_y = entity.ren_layer.getImageDimensions( entity.image) return entity.ren_layer.queueImage( image=entity.image, x=entity.pos.x - offset_x, y=entity.pos.y - offset_y, z=entity.pos.z, color=entity.color * px_graphics.Color(1, 1, 1, entity.fade))
def renderText(self, string, font=False, color=px_graphics.Color(1, 1, 1, 1)): #We need to first render to a surface as that's what TTF_RenderText #returns, then load that surface into a texture surf = sdl2.sdlttf.TTF_RenderUTF8_Solid(self.sdl_fonts[font].font, string.encode('utf-8'), color.toSDLColor()) if surf is None: log(f"TTF_RenderText failed: {string}") return None texture = sdl2.SDL_CreateTextureFromSurface(self.ren.sdlrenderer, surf) if texture is None: print("CreateTexture") #Clean up the surface and font width = surf.contents.w height = surf.contents.h sdl2.SDL_FreeSurface(surf) # sdl2.sdlttf.TTF_CloseFont(font) return texture, width, height
def message(self, text, pos, color=px_graphics.Color(1, 1, 1, 1), duration=-1, # or forever align=px_graphics.eAlign.left, fade_speed=0.5 ): message = self.requestNewEntity(template='message', name= f"message: {text}", pos=pos, parent=self, data={ 'ren_layer': self.render_layers['overlay'], 'message': text, 'font': 0, 'color' : color, 'duration' : duration, 'align' : align, 'fade_speed' : fade_speed } ) return message