-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
14 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,18 @@ | ||
from __future__ import annotations | ||
|
||
from abc import ABC | ||
from abc import abstractmethod | ||
|
||
import pygame as pg | ||
|
||
from doggo import ASSETS_PATH | ||
|
||
|
||
class LandscapeBase(ABC): | ||
"""Abstract class for static landscape objects.""" | ||
|
||
@abstractmethod | ||
def render(self, surface: pg.Surface) -> None: | ||
raise NotImplementedError | ||
|
||
|
||
class Landscape(LandscapeBase): | ||
"""The landscape of the world.""" | ||
class Landscape(pg.sprite.Sprite): | ||
"""Abstract class for landscape.""" | ||
|
||
def __init__(self, items: list[LandscapeBase] | None = None) -> None: | ||
self._items = items or [] | ||
|
||
def add(self, item: LandscapeBase) -> None: | ||
"""Add a static item to the landscape.""" | ||
self._items.append(item) | ||
|
||
def render(self, surface: pg.Surface) -> None: | ||
"""Render the landscape.""" | ||
for item in self._items: | ||
item.render(surface) | ||
|
||
|
||
class StaticLandscape(LandscapeBase): | ||
class StaticLandscape(Landscape): | ||
"""Abstract class for static landscape.""" | ||
|
||
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, self.topleft) | ||
super().__init__() | ||
self.image = pg.image.load(ASSETS_PATH.joinpath(path)).convert_alpha() | ||
self.rect = self.image.get_rect(topleft=topleft) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters