174 days ago · 9 min read1748 words · Tech · hide · Fediverse post

Sprites, yesterday and today. Refactoring the Content design, because Sprites. You may be forgiven for not recalling that dungeon content items used to be drawn by drawing textures in a rectangle at the appropriate coordinates: class ContentPainter: error_texture = ':resources:images/items/star.png' def __init__(self, resource, scale=0.5): self.scale = scale try: self.shape = arcade.load_texture(resource) except (FileNotFoundError, AttributeError): self.shape = arcade.load_texture(self.error_texture) def draw(self, cx, cy, cell_size): texture = self.shape scale = scale_texture(texture, self.scale) arcade.draw_texture_rect( texture, arcade.XYWH(cx, cy, texture.width, texture.height).scale(scale) ) ContentPainter is yesterday’s Method Object that allows all the different types of Content to avoid duplicating those two methods, instead relying on a ContentPainter to do the job for them. But that was the morning. In the afternoon I had a little time and converted the ContentPainter to use…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town