def apply_lightmap(self): sun_direction = math.pi*0.75 lighting_direction = sanitize_angle(self.heading+sun_direction) # figure out which one of the prerendered lightmaps to use h = int(lighting_direction/(2*math.pi)*len(self.lightmaps*2)) if 0 <= h < len(self.lightmaps): lm = self.lightmaps[h] else: lm = self.lightmaps[2*len(self.lightmaps)-h-1].transpose(Image.FLIP_TOP_BOTTOM) im = get_pil_image(self.image) img = im.convert("L") # apply lightmap limg = ImageChops.multiply(img, lm).convert("RGBA") limg.putalpha(im.split()[-1]) return pygame.image.frombuffer(limg.tostring(), self.image.get_size(), "RGBA")
def turn(self, t): # turn the ship according to its rotation self.heading = sanitize_angle(self.heading+self.angular_freq*t)