Browse Source

#31 本日作業分

ai-migration
みてるぞ 1 month ago
parent
commit
c83c99bc74
1 changed files with 51 additions and 18 deletions
  1. +51
    -18
      test.py

+ 51
- 18
test.py View File

@@ -15,9 +15,25 @@ def main (
) -> None: ) -> None:
pygame.init () pygame.init ()
game = Game () game = Game ()
bg = Bg (game)
deerjika = Deerjika (game, DeerjikaPattern.RELAXED) deerjika = Deerjika (game, DeerjikaPattern.RELAXED)
while True: 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: class Game:
@@ -32,12 +48,15 @@ class Game:
self.screen = pygame.display.set_mode ((CWindow.WIDTH, CWindow.HEIGHT)) self.screen = pygame.display.set_mode ((CWindow.WIDTH, CWindow.HEIGHT))
self.clock = Clock () self.clock = Clock ()
self.frame = 0 self.frame = 0
self.redrawers = []


def redraw ( def redraw (
self, self,
) -> None: ) -> None:
for redrawer in sorted (self.redrawers, key = lambda x: x['layer']): for redrawer in sorted (self.redrawers, key = lambda x: x['layer']):
redrawer['func'] () redrawer['func'] ()
pygame.display.update ()
self.clock.tick ()




class GameObject: class GameObject:
@@ -47,16 +66,18 @@ class GameObject:
height: int height: int
x: float x: float
y: 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__ ( def __init__ (
self, self,
game: Game, game: Game,
layer: int | None = None, layer: int | None = None,
x: float = 0,
y: float = 0,
): ):
self.game = game self.game = game
self.frame = 0 self.frame = 0
@@ -66,6 +87,8 @@ class GameObject:
else: else:
layer = 0 layer = 0
self.game.redrawers.append ({ 'layer': layer, 'func': self.redraw }) self.game.redrawers.append ({ 'layer': layer, 'func': self.redraw })
self.x = x
self.y = y


def redraw ( def redraw (
self, self,
@@ -77,6 +100,24 @@ class GameObject:
self.frame += 1 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): class Deerjika (GameObject):
surfaces: list[Surface] surfaces: list[Surface]
size: int size: int
@@ -87,8 +128,10 @@ class Deerjika (GameObject):
pattern: DeerjikaPattern = DeerjikaPattern.NORMAL, pattern: DeerjikaPattern = DeerjikaPattern.NORMAL,
direction: Direction = Direction.LEFT, direction: Direction = Direction.LEFT,
layer: int | None = None, layer: int | None = None,
x: float = 0,
y: float = 0,
): ):
super ().__init__ (game, layer)
super ().__init__ (game, layer, x, y)
self.pattern = pattern self.pattern = pattern
self.direction = direction self.direction = direction
match pattern: match pattern:
@@ -97,7 +140,7 @@ class Deerjika (GameObject):
case DeerjikaPattern.RELAXED: case DeerjikaPattern.RELAXED:
match direction: match direction:
case Direction.LEFT: 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: case Direction.RIGHT:
... ...
self.size = len (self.surfaces) self.size = len (self.surfaces)
@@ -110,16 +153,6 @@ class Deerjika (GameObject):
super ().redraw () super ().redraw ()




class DeerjikaPattern (Enum):
NORMAL = auto ()
RELAXED = auto ()


class Direction (Enum):
LEFT = auto ()
RIGHT = auto ()


class CWindow: class CWindow:
WIDTH = 1024 WIDTH = 1024
HEIGHT = 768 HEIGHT = 768


Loading…
Cancel
Save