Skip to content

Commit

Permalink
feat: add background mountain
Browse files Browse the repository at this point in the history
  • Loading branch information
u8slvn committed Aug 14, 2024
1 parent 9562d5e commit 3c01d46
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
Binary file added src/doggo/assets/landscape/mountain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions src/doggo/landscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def render(self, surface: pg.Surface) -> None:
item.render(surface)


class Ground(LandscapeBase):
"""The ground of the world."""
class StaticLandscape(LandscapeBase):
"""Abstract class for static landscape."""

def __init__(self, height: int, path: str = "landscape/ground.png") -> None:
self.height = height
self._surface = pg.image.load(ASSETS_PATH.joinpath(path)).convert()
def __init__(self, topleft: tuple[int, int], path: str) -> None:
self.topleft = topleft
self._surface = pg.image.load(ASSETS_PATH.joinpath(path)).convert_alpha()

def render(self, surface: pg.Surface) -> None:
"""Render the ground."""
surface.blit(self._surface, (0, self.height))
surface.blit(self._surface, self.topleft)
17 changes: 13 additions & 4 deletions src/doggo/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from doggo.dog.body import Fur
from doggo.dog.brain import Brain
from doggo.dog.dog import Dog
from doggo.landscape import Ground
from doggo.landscape import Landscape
from doggo.landscape import StaticLandscape


def build_dog() -> Dog:
Expand All @@ -28,8 +28,17 @@ def build_dog() -> Dog:
)


def build_landscape() -> Landscape:
"""Build the landscape."""
ground = Ground(height=config.WORLD_GROUND)
def build_bg_landscape() -> Landscape:
"""Build the background landscape."""
mountain = StaticLandscape(topleft=(0, 0), path="landscape/mountain.png")

return Landscape(items=[mountain])


def build_fg_landscape() -> Landscape:
"""Build the foreground landscape."""
ground = StaticLandscape(
topleft=(0, config.WORLD_GROUND), path="landscape/ground.png"
)

return Landscape(items=[ground])
9 changes: 6 additions & 3 deletions src/doggo/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
from loguru import logger

from doggo.dog.dog import Dog
from doggo.prepare import build_bg_landscape
from doggo.prepare import build_dog
from doggo.prepare import build_landscape
from doggo.prepare import build_fg_landscape
from doggo.ui import DraggableWindow


Expand All @@ -33,8 +34,9 @@ def __init__(self, title: str, size: tuple[int, int], fps: int = 60) -> None:
self.dt: float = 0.0
self.prev_time: float = time.time()

self.bg_landscape = build_bg_landscape()
self.dog: Dog = build_dog()
self.landscape = build_landscape()
self.fg_landscape = build_fg_landscape()

def process_inputs(self) -> None:
"""Process the inputs of the world."""
Expand All @@ -59,8 +61,9 @@ def update(self) -> None:
def render(self) -> None:
"""Render the world."""
self.screen.fill((135, 206, 235))
self.bg_landscape.render(surface=self.screen)
self.dog.render(surface=self.screen)
self.landscape.render(surface=self.screen)
self.fg_landscape.render(surface=self.screen)
self.window.flip()

def start(self) -> None:
Expand Down

0 comments on commit 3c01d46

Please sign in to comment.