Skip to content

Commit

Permalink
refactor: merge biome foreground and background image
Browse files Browse the repository at this point in the history
  • Loading branch information
u8slvn committed Aug 24, 2024
1 parent 008d84d commit 92deaa2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
Binary file added src/doggo/assets/landscape/00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/doggo/assets/landscape/00_bg.png
Binary file not shown.
Binary file removed src/doggo/assets/landscape/00_fg.png
Binary file not shown.
18 changes: 9 additions & 9 deletions src/doggo/landscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from loguru import logger

from doggo import ASSETS_PATH
from doggo.dog.body import SpriteSheet


class Biome(IntEnum):
Expand All @@ -28,11 +29,8 @@ def random(cls) -> Biome:
class LandscapeLayer:
"""A layer of the landscape."""

path = ASSETS_PATH.joinpath("landscape")

def __init__(self, image: str, topleft: tuple[int, int] = (0, 0)) -> None:
image_path = self.path.joinpath(image)
self.image = pg.image.load(image_path).convert_alpha()
def __init__(self, image: pg.Surface, topleft: tuple[int, int] = (0, 0)) -> None:
self.image = image
self.rect = self.image.get_rect(topleft=topleft)

def draw(self, screen: pg.Surface) -> None:
Expand All @@ -43,9 +41,11 @@ def draw(self, screen: pg.Surface) -> None:
class Landscape:
"""The landscape of the game."""

bg_suffix = "_bg.png"
fg_suffix = "_fg.png"
path = ASSETS_PATH.joinpath("landscape")

def __init__(self, biome: Biome) -> None:
self.background = LandscapeLayer(image=f"{biome:02d}{self.bg_suffix}")
self.foreground = LandscapeLayer(image=f"{biome:02d}{self.fg_suffix}")
asset_path = self.path.joinpath(f"{biome:02d}.png")
sprite_sheet = SpriteSheet(path=asset_path, columns=1, rows=2)

self.background = LandscapeLayer(image=sprite_sheet.get_sprite((0, 1)))
self.foreground = LandscapeLayer(image=sprite_sheet.get_sprite((0, 0)))
Binary file removed src_assets/ground.aseprite
Binary file not shown.
4 changes: 3 additions & 1 deletion tests/test_landscape.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import pygame as pg

from doggo.landscape import Biome
from doggo.landscape import LandscapeLayer

Expand All @@ -12,7 +14,7 @@ def test_get_random_biome():


def test_landscape_layer_draw_on_screen(pg_screen_mock):
image = f"{Biome.MOUNTAIN:02d}_bg.png"
image = pg.Surface((100, 100))
landscape_layer = LandscapeLayer(image=image, topleft=(10, 10))

landscape_layer.draw(pg_screen_mock)
Expand Down

0 comments on commit 92deaa2

Please sign in to comment.