Browse Source

大月追加

ai-migration
みてるぞ 1 month ago
parent
commit
05cd19525c
1 changed files with 59 additions and 14 deletions
  1. +59
    -14
      test.py

+ 59
- 14
test.py View File

@@ -108,16 +108,19 @@ class Game:
ゲーム・クラス

Attributes:
clock (Clock): Clock オブゼクト
frame (int): フレーム・カウンタ
redrawers (list[Redrawer]): 再描画するクラスのリスト
screen (Surface): 基底スクリーン
sky (Sky): 天体情報
clock (Clock): Clock オブゼクト
frame (int): フレーム・カウンタ
last_answered_at (datetime): 最後に回答した時刻
now (datetime): 基準日時
redrawers (list[Redrawer]): 再描画するクラスのリスト
screen (Surface): 基底スクリーン
sky (Sky): 天体情報
"""

clock: Clock
frame: int
last_answered_at: datetime
now: datetime
redrawers: list[Redrawer]
screen: Surface
sky: Sky
@@ -134,6 +137,8 @@ class Game:
def redraw (
self,
) -> None:
self.now = datetime.now ()
self.sky.observer.date = self.now - timedelta (hours = 9)
for redrawer in sorted (self.redrawers, key = lambda x: x['layer']):
if redrawer['obj'].enabled:
redrawer['obj'].redraw ()
@@ -339,7 +344,7 @@ class CurrentTime (GameObject):
) -> None:
for i in range (4):
self.game.screen.blit (
self.font.render (str (datetime.now ()), True, (0, 0, 0)),
self.font.render (str (self.game.now), True, (0, 0, 0)),
(i % 2, i // 2 * 2))
super ().redraw ()

@@ -384,7 +389,7 @@ class Balloon (GameObject):
) -> None:
if self.frame >= self.length:
self.enabled = False
self.game.last_answered_at = datetime.now ()
self.game.last_answered_at = self.game.now
return
query = self.query
if CommonModule.len_by_full (query) > 21:
@@ -451,7 +456,6 @@ class KitaSun (GameObject):
surface = pygame.transform.rotate (self.surface, -(90 + math.degrees (self.arg)))
self.game.screen.blit (surface, surface.get_rect (center = (self.x, self.y)))
super ().redraw ()
self.game.sky.observer.date = datetime.now () - timedelta (hours = 9)
self.sun.compute (self.game.sky.observer)
self.alt = self.sun.alt
self.az = self.sun.az
@@ -488,11 +492,14 @@ class Jojoko (GameObject):
Attributes:
base (Surface): 満月ヨヨコ Surface
moon (Moon): ephem の月オブゼクト
surface (Surface): 缺けたヨヨコ Surface
surface (Surface): 缺けたヨヨコ
"""

alt: float
az: float
base: Surface
moon: Moon
surface: Surface

def __init__ (
self,
@@ -500,25 +507,43 @@ class Jojoko (GameObject):
):
super ().__init__ (game)
self.base = pygame.transform.scale (pygame.image.load ('assets/moon.png'), (200, 200))
self.moon = Moon ()
self.surface = self._get_surface ()

def redraw (
self,
) -> None:
...
if self.frame % 300 == 0:
self.surface = self._get_surface ()
surface = pygame.transform.rotate (self.surface, -(90 + math.degrees (self.arg)))
surface.set_colorkey ((0, 255, 0))
self.game.screen.blit (surface, surface.get_rect (center = (self.x, self.y)))
super ().redraw ()
self.moon.compute (self.game.sky.observer)
self.alt = self.moon.alt
self.az = self.moon.az
if abs (self.new_arg - self.arg) > math.radians (15):
self.arg = self.new_arg
self.x = self.new_x
self.y = self.new_y

@property
def phase (
self,
) -> float:
dt: datetime = ephem.localtime (ephem.previous_new_moon (self.game.sky.observer.date))
return (datetime.now () - dt).total_seconds () / 60 / 60 / 24
return (self.game.now - dt).total_seconds () / 60 / 60 / 24

@property
def surface (
def _get_surface (
self,
) -> Surface:
"""
ヨヨコを月齢に応じて缺かす.

Returns:
Surface: 缺けたヨヨコ
"""
jojoko = self.base.copy ()
jojoko.set_colorkey ((0, 255, 0))
for i in range (200):
if 1 <= self.phase < 15:
pygame.gfxdraw.bezier (jojoko, ((0, 100 + i), (100, 180 * self.phase / 7 - 80 + i), (200, 100 + i)), 3, (0, 255, 0))
@@ -530,6 +555,26 @@ class Jojoko (GameObject):
jojoko.fill ((0, 255, 0))
return jojoko

@property
def new_x (
self,
) -> float:
return CWindow.WIDTH * (math.degrees (self.az) - 80) / 120

@property
def new_y (
self,
) -> float:
return ((CWindow.HEIGHT / 2)
- ((CWindow.HEIGHT / 2 + 100) * math.sin (self.alt)
/ math.sin (math.radians (60))))

@property
def new_arg (
self,
) -> float:
return math.atan2 (self.new_y - self.y, self.new_x - self.x)


class Sky:
"""


Loading…
Cancel
Save