#31 本日作業分

このコミットが含まれているのは:
2024-12-09 17:34:57 +09:00
コミット c83c99bc74
+51 -18
ファイルの表示
@@ -15,9 +15,25 @@ def main (
) -> None:
pygame.init ()
game = Game ()
bg = Bg (game)
deerjika = Deerjika (game, DeerjikaPattern.RELAXED)
while True:
pass
for event in pygame.event.get ():
if event.type == pygame.QUIT:
pygame.quit ()
sys.exit ()
game.redraw ()
class DeerjikaPattern (Enum):
NORMAL = auto ()
RELAXED = auto ()
SLEEPING = auto ()
class Direction (Enum):
LEFT = auto ()
RIGHT = auto ()
class Game:
@@ -32,12 +48,15 @@ class Game:
self.screen = pygame.display.set_mode ((CWindow.WIDTH, CWindow.HEIGHT))
self.clock = Clock ()
self.frame = 0
self.redrawers = []
def redraw (
self,
) -> None:
for redrawer in sorted (self.redrawers, key = lambda x: x['layer']):
redrawer['func'] ()
pygame.display.update ()
self.clock.tick ()
class GameObject:
@@ -47,16 +66,18 @@ class GameObject:
height: int
x: float
y: float
vx: float
vy: float
ax: float
ay: float
arg: float
vx: float = 0
vy: float = 0
ax: float = 0
ay: float = 0
arg: float = 0
def __init__ (
self,
game: Game,
layer: int | None = None,
x: float = 0,
y: float = 0,
):
self.game = game
self.frame = 0
@@ -66,6 +87,8 @@ class GameObject:
else:
layer = 0
self.game.redrawers.append ({ 'layer': layer, 'func': self.redraw })
self.x = x
self.y = y
def redraw (
self,
@@ -77,6 +100,24 @@ class GameObject:
self.frame += 1
class Bg (GameObject):
surface: Surface
def __init__ (
self,
game: Game,
):
super ().__init__ (game)
self.surface = pygame.image.load ('assets/bg.jpg')
self.surface = pygame.transform.scale (self.surface, (CWindow.WIDTH, CWindow.HEIGHT))
def redraw (
self,
) -> None:
self.game.screen.blit (self.surface, (self.x, self.y))
super ().redraw ()
class Deerjika (GameObject):
surfaces: list[Surface]
size: int
@@ -87,8 +128,10 @@ class Deerjika (GameObject):
pattern: DeerjikaPattern = DeerjikaPattern.NORMAL,
direction: Direction = Direction.LEFT,
layer: int | None = None,
x: float = 0,
y: float = 0,
):
super ().__init__ (game, layer)
super ().__init__ (game, layer, x, y)
self.pattern = pattern
self.direction = direction
match pattern:
@@ -97,7 +140,7 @@ class Deerjika (GameObject):
case DeerjikaPattern.RELAXED:
match direction:
case Direction.LEFT:
self.surfaces = get_surfaces_from_video ('deerjika_relax.mp4')
self.surfaces = get_surfaces_from_video ('assets/deerjika_relax.mp4')
case Direction.RIGHT:
...
self.size = len (self.surfaces)
@@ -110,16 +153,6 @@ class Deerjika (GameObject):
super ().redraw ()
class DeerjikaPattern (Enum):
NORMAL = auto ()
RELAXED = auto ()
class Direction (Enum):
LEFT = auto ()
RIGHT = auto ()
class CWindow:
WIDTH = 1024
HEIGHT = 768