diff --git a/assets/stacked_sprites/animated/sprite_properties.json b/assets/stacked_sprites/animated/sprite_properties.json new file mode 100644 index 0000000..c6bbb75 --- /dev/null +++ b/assets/stacked_sprites/animated/sprite_properties.json @@ -0,0 +1,7 @@ +{ + "Bla": { + "path": "../assets/stacked_sprites/animated/bla/", + "layers": 3, + "scale": 16 + } +} \ No newline at end of file diff --git a/assets/stacked_sprites/sprite_properties.json b/assets/stacked_sprites/sprite_properties.json new file mode 100644 index 0000000..8f573ea --- /dev/null +++ b/assets/stacked_sprites/sprite_properties.json @@ -0,0 +1,12 @@ +{ + "Robot": { + "path": "../assets/stacked_sprites/Robot.png", + "layers": 16, + "scale": 8 + }, + "Building": { + "path": "../assets/stacked_sprites/Building.png", + "layers": 80, + "scale": 4 + } +} \ No newline at end of file diff --git a/sprite_stacking_engine/settings.py b/sprite_stacking_engine/settings.py index a67b895..fed4ed1 100644 --- a/sprite_stacking_engine/settings.py +++ b/sprite_stacking_engine/settings.py @@ -1,12 +1,23 @@ #!/usr/bin/python3 import pygame +import json + + +def load_json(path): + file = open(path, "r") + data = json.load(file) + file.close() + + return data + vec2 = pygame.math.Vector2 RES = WIDTH, HEIGHT = vec2(1400, 800) CENTER = H_WIDTH, H_HEIGHT = RES // 2 TILE_SIZE = 250 +DEFAULT_SCALE = 4 PLAYER_SPEED = 0.4 PLAYER_ROT_SPEED = 0.0015 @@ -16,23 +27,26 @@ NUM_ANGLES = 180 # multiple of 360 TRANSP_COLOR = (45, 54, 76) OUTLINE = True -SPRITE_ATTRS = { - "Robot": { - "path": "../assets/stacked_sprites/Robot.png", - "layers": 16, - "scale": 8 - }, - "Building": { - "path": "../assets/stacked_sprites/Building.png", - "layers": 80, - "scale": 4 - } -} +SPRITE_ATTRS = load_json("../assets/stacked_sprites/sprite_properties.json") +ANIMATED_SPRITE_ATTRS = load_json("../assets/stacked_sprites/animated/sprite_properties.json") -ANIMATED_SPRITE_ATTRS = { - "Bla": { - "path": "../assets/stacked_sprites/animated/bla/", - "layers": 3, - "scale": 16 - } -} \ No newline at end of file +# SPRITE_ATTRS = { +# "Robot": { +# "path": "../assets/stacked_sprites/Robot.png", +# "layers": 16, +# "scale": 8 +# }, +# "Building": { +# "path": "../assets/stacked_sprites/Building.png", +# "layers": 80, +# "scale": 4 +# } +# } + +# ANIMATED_SPRITE_ATTRS = { +# "Bla": { +# "path": "../assets/stacked_sprites/animated/bla/", +# "layers": 3, +# "scale": 16 +# } +# } \ No newline at end of file diff --git a/sprite_stacking_engine/stacked_sprite.py b/sprite_stacking_engine/stacked_sprite.py index 5d74b74..3e2e905 100644 --- a/sprite_stacking_engine/stacked_sprite.py +++ b/sprite_stacking_engine/stacked_sprite.py @@ -15,6 +15,10 @@ class StackedSprite(pygame.sprite.Sprite): super().__init__(self.group) self.attrs = SPRITE_ATTRS[name] # get attributes + + if not "scale" in self.attrs: + self.attrs["scale"] = DEFAULT_SCALE + self.y_offset = vec2(0, -self.attrs["layers"] / 2 * self.attrs["scale"]) # calculate the y offset because the - # images position in pygame is the position of the top left corner of the image and we use the bottom position self.cache = self.app.cache.stacked_sprite_cache @@ -57,6 +61,10 @@ class AnimatedStackedSprite(pygame.sprite.Sprite): # stacked sprite class for a super().__init__(self.group) self.attrs = ANIMATED_SPRITE_ATTRS[name] + + if not "scale" in self.attrs: + self.attrs["scale"] = DEFAULT_SCALE + self.attrs["animated"] = True # set the animated attribute to true so that the cache knows that this sprite - self.y_offset = vec2(0, -self.attrs["layers"] / 2 * self.attrs["scale"]) # is animated self.cache = self.app.cache.stacked_sprite_cache