def show(self, window, window_scale): # Get blit pos and scale current_pos = self.get_pos() if current_pos: pos = list(current_pos) pos[0] *= window_scale pos[1] *= window_scale # Scale image to fit the correct amount of space img = transform.scale(self.image, (int(window_scale),) * 2) old_rect = img.get_rect() # Add the rotation next_dist = self.dist + 0.7 next_pos = self.get_pos(dist = next_dist) angle = gfunc.get_rot(next_pos, current_pos) - 90 img = transform.rotate(img, angle) # Add the sway rot = math.sin(self.dist * 4) * 5 # Sin because the curve resembles the wanted swaying motion img = transform.rotate(img, rot) rect = img.get_rect() change = (rect.width - old_rect.width) / 2, (rect.height - old_rect.height) / 2 pos[0] -= change[0] pos[1] -= change[1] # Show window.blit(img, pos)
def aim(self, enemies): if len(enemies) > 0: # Aim at first enemy = enemies[0] pos = enemy.get_pos() if pos: pos[0] += 0.5 pos[1] += 0.5 this_pos = list(self.pos) this_pos[0] += 0.5 this_pos[1] += 0.5 self.rot = gfunc.get_rot(pos, this_pos) self.aiming = pos return self.aiming = False
def get_angle(self): p1 = self.pos p2 = self.pos[0] + self.slope[0], self.pos[1] + self.slope[1] return gfunc.get_rot(p1, p2)