#!/usr/bin/python3 import pygame from settings import * import math from wobbl_tools import pg class StackedSprite(pygame.sprite.Sprite): def __init__(self, app, name, pos, rot=0): self.app = app self.name = name self.pos = vec2(pos) * TILE_SIZE self.player = self.app.player self.group = self.app.main_group super().__init__(self.group) self.attrs = SPRITE_ATTRS[name] self.y_offset = vec2(0, -self.attrs["num_layers"] / 2 * self.attrs["scale"]) self.cache = self.app.cache.stacked_sprite_cache self.viewing_angle = app.cache.viewing_angle self.rotated_sprites = self.cache[name]["rotated_sprites"] self.angle = 0 self.screen_position = vec2(0) self.rot = (rot % 360) // self.viewing_angle def transform(self): pos = self.pos - self.player.offset pos = pos.rotate_rad(self.player.angle) self.screen_position = pos + CENTER def change_layer(self): self.group.change_layer(self, self.screen_position.y) def get_angle(self): self.angle = -math.degrees(self.player.angle) // self.viewing_angle + self.rot self.angle = int(self.angle % NUM_ANGLES) def update(self): self.transform() self.get_angle() self.get_image() self.change_layer() def get_image(self): self.image = self.rotated_sprites[self.angle] self.rect = self.image.get_rect(center=self.screen_position + self.y_offset)