added support for animated texture
Before Width: | Height: | Size: 156 B After Width: | Height: | Size: 156 B |
Before Width: | Height: | Size: 572 B After Width: | Height: | Size: 572 B |
Before Width: | Height: | Size: 609 B After Width: | Height: | Size: 609 B |
Before Width: | Height: | Size: 644 B After Width: | Height: | Size: 644 B |
Before Width: | Height: | Size: 695 B After Width: | Height: | Size: 695 B |
Before Width: | Height: | Size: 712 B After Width: | Height: | Size: 712 B |
Before Width: | Height: | Size: 753 B After Width: | Height: | Size: 753 B |
Before Width: | Height: | Size: 766 B After Width: | Height: | Size: 766 B |
Before Width: | Height: | Size: 708 B After Width: | Height: | Size: 708 B |
Before Width: | Height: | Size: 691 B After Width: | Height: | Size: 691 B |
Before Width: | Height: | Size: 533 B After Width: | Height: | Size: 533 B |
Before Width: | Height: | Size: 192 B After Width: | Height: | Size: 192 B |
Before Width: | Height: | Size: 418 B After Width: | Height: | Size: 418 B |
Before Width: | Height: | Size: 339 B After Width: | Height: | Size: 339 B |
Before Width: | Height: | Size: 264 B After Width: | Height: | Size: 264 B |
Before Width: | Height: | Size: 213 B After Width: | Height: | Size: 213 B |
Before Width: | Height: | Size: 231 B After Width: | Height: | Size: 231 B |
Before Width: | Height: | Size: 281 B After Width: | Height: | Size: 281 B |
Before Width: | Height: | Size: 321 B After Width: | Height: | Size: 321 B |
Before Width: | Height: | Size: 381 B After Width: | Height: | Size: 381 B |
Before Width: | Height: | Size: 445 B After Width: | Height: | Size: 445 B |
Before Width: | Height: | Size: 467 B After Width: | Height: | Size: 467 B |
Before Width: | Height: | Size: 513 B After Width: | Height: | Size: 513 B |
|
@ -1,10 +1,10 @@
|
|||
from . import _image_path
|
||||
from . import path
|
||||
from .abc import Style
|
||||
|
||||
|
||||
_image_path = _image_path + "background/"
|
||||
path = path / "background"
|
||||
|
||||
|
||||
class Background(Style):
|
||||
main = _image_path + "main.png"
|
||||
game = _image_path + "game.png"
|
||||
main = path / "main.png"
|
||||
game = path / "game.png"
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
from . import _image_path
|
||||
from . import path
|
||||
from .abc import Style
|
||||
|
||||
_image_path = _image_path + "button/"
|
||||
path = path / "button"
|
||||
|
||||
|
||||
class Button:
|
||||
class Style1(Style):
|
||||
normal = _image_path + "normal.png"
|
||||
click = _image_path + "clicking.png"
|
||||
hover = _image_path + "hovering.png"
|
||||
normal = path / "normal.png"
|
||||
click = path / "clicking.png"
|
||||
hover = path / "hovering.png"
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
from . import _image_path
|
||||
from . import path
|
||||
from .abc import Style
|
||||
|
||||
_image_path = _image_path + "checkbox/"
|
||||
path = path / "checkbox"
|
||||
|
||||
|
||||
class Checkbox:
|
||||
class Style1(Style):
|
||||
disabled = _image_path + "disabled.png"
|
||||
enabled = _image_path + "enabled.png"
|
||||
disabled = path / "disabled.png"
|
||||
enabled = path / "enabled.png"
|
||||
|
|
|
@ -1,17 +1,28 @@
|
|||
from . import _image_path
|
||||
from . import path
|
||||
from .abc import Style
|
||||
|
||||
_image_path = _image_path + "grid/"
|
||||
_image_boat_path = _image_path + "boat/"
|
||||
path = path / "grid"
|
||||
path_boat = path / "boat"
|
||||
path_bomb = path / "bomb"
|
||||
|
||||
|
||||
class Grid:
|
||||
class Style1(Style):
|
||||
background = _image_path + "background.png"
|
||||
background = path / "background.png"
|
||||
|
||||
class Boat:
|
||||
class Style1(Style):
|
||||
body = _image_boat_path + "body.png"
|
||||
edge = _image_boat_path + "edge.png"
|
||||
broken = _image_boat_path + "broken.png"
|
||||
solo = _image_boat_path + "solo.png"
|
||||
body = path_boat / "body.png"
|
||||
edge = path_boat / "edge.png"
|
||||
broken = path_boat / "broken.png"
|
||||
solo = path_boat / "solo.png"
|
||||
|
||||
class Bomb:
|
||||
class Style1(Style):
|
||||
_animation = sorted(
|
||||
(path_bomb / "animation").iterdir(),
|
||||
key=lambda path: int(path.stem)
|
||||
)
|
||||
|
||||
missed = [*_animation, path_bomb / "missed.png"], 0.03, False
|
||||
touched = [*_animation, path_bomb / "touched.png"], 0.03, False
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
from . import _image_path
|
||||
from . import path
|
||||
from .abc import Style
|
||||
|
||||
_image_path = _image_path + "input/"
|
||||
path = path / "input"
|
||||
|
||||
|
||||
class Input:
|
||||
class Style1(Style):
|
||||
normal = _image_path + "normal.png"
|
||||
active = _image_path + "active.png"
|
||||
error = _image_path + "error.png"
|
||||
normal = path / "normal.png"
|
||||
active = path / "active.png"
|
||||
error = path / "error.png"
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
from . import _image_path
|
||||
from . import path
|
||||
from .abc import Style
|
||||
|
||||
_image_path = _image_path + "scroller/"
|
||||
path = path / "scroller"
|
||||
|
||||
|
||||
class Scroller:
|
||||
class Style1(Style):
|
||||
background = _image_path + "background.png"
|
||||
cursor = _image_path + "cursor.png"
|
||||
background = path / "background.png"
|
||||
cursor = path / "cursor.png"
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
_image_path: str = "./assets/image/"
|
||||
from pathlib import Path
|
||||
|
||||
path: Path = Path("./assets/image")
|
||||
|
||||
from .Background import Background # NOQA: E402
|
||||
from .Button import Button # NOQA: E402
|
||||
from .Checkbox import Checkbox # NOQA: E402
|
||||
from .Grid import Grid # NOQA: E402
|
||||
from .Input import Input # NOQA: E402
|
||||
from .Scroller import Scroller # NOQA: E402
|
||||
from .Background import Background
|
||||
from .Button import Button
|
||||
from .Checkbox import Checkbox
|
||||
from .Grid import Grid
|
||||
from .Input import Input
|
||||
from .Scroller import Scroller
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from abc import ABC
|
||||
from pathlib import Path
|
||||
from typing import Optional, Any
|
||||
|
||||
import pyglet
|
||||
|
@ -8,9 +9,23 @@ class Style(ABC):
|
|||
def __init_subclass__(cls, **kwargs):
|
||||
atlas = pyglet.image.atlas.TextureAtlas()
|
||||
|
||||
for name, path in cls.__dict__.items():
|
||||
for name, args in cls.__dict__.items():
|
||||
if name.startswith("_"): continue
|
||||
setattr(cls, name, atlas.add(pyglet.image.load(path)))
|
||||
|
||||
if isinstance(args, Path): # if this is a normal path for a normal image
|
||||
path = args
|
||||
texture = atlas.add(pyglet.image.load(path))
|
||||
|
||||
elif isinstance(args, tuple): # if this is a tuple for an animation
|
||||
paths, duration, loop = args
|
||||
|
||||
textures = map(lambda path: atlas.add(pyglet.image.load(path)), paths)
|
||||
texture = pyglet.image.Animation.from_image_sequence(textures, duration, loop)
|
||||
|
||||
else:
|
||||
raise ValueError(f"Invalid type : {type(args)}")
|
||||
|
||||
setattr(cls, name, texture)
|
||||
|
||||
setattr(cls, "_atlas", atlas)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from copy import copy
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Type
|
||||
|
||||
import pyglet
|
||||
import numpy as np
|
||||
|
@ -8,6 +8,7 @@ from source.core.enums import Orientation
|
|||
from source.core.error import InvalidBoatPosition
|
||||
from source.gui import texture
|
||||
from source.gui.sprite import Sprite
|
||||
from source.gui.texture.abc import Style
|
||||
from source.gui.widget.grid.abc import GameGrid
|
||||
from source.core import Board, Boat
|
||||
from source.type import Point2D, ColorRGB
|
||||
|
@ -20,13 +21,18 @@ if TYPE_CHECKING:
|
|||
class GameGridAlly(GameGrid):
|
||||
def __init__(self, scene: "Scene",
|
||||
|
||||
rows: int,
|
||||
columns: int,
|
||||
|
||||
style: Type[Style],
|
||||
|
||||
boats_length: list[int],
|
||||
preview_color: ColorRGB = (150, 255, 150),
|
||||
|
||||
**kwargs):
|
||||
self.cell_sprites: dict[Point2D, "Sprite"] = {}
|
||||
|
||||
super().__init__(scene, **kwargs)
|
||||
super().__init__(scene, rows, columns, style, **kwargs)
|
||||
|
||||
self.boats_length = boats_length # the list of the size of the boats to place
|
||||
self.preview_color = preview_color
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
from typing import Type
|
||||
|
||||
from source.gui.texture.abc import Style
|
||||
from source.gui.widget.grid.abc import GameGrid
|
||||
|
||||
|
||||
class GameGridEnemy(GameGrid):
|
||||
pass
|
||||
def __init__(self, scene: "Scene", rows: int, columns: int, style: Type[Style], **kwargs):
|
||||
super().__init__(scene, rows, columns, style, **kwargs)
|
||||
|
||||
|
|
|
@ -8,4 +8,4 @@ ColorRGBA = tuple[int, int, int, int]
|
|||
|
||||
DistanceFunction = Callable[[Any], int] # a function that return a distance
|
||||
# a distance, represented either by a whole number, a percentage or a function
|
||||
Distance = Union[Percentage, int, DistanceFunction]
|
||||
Distance = Union[Percentage, int, DistanceFunction]
|
||||
|
|