fix(controller): update particle positioning and compositing for padded canvas
This commit is contained in:
+13
-15
@@ -437,11 +437,11 @@ class CatController:
|
|||||||
heart_alpha = 1.0 - progress
|
heart_alpha = 1.0 - progress
|
||||||
heart = self.assets.get_heart_particle(size=28, alpha=heart_alpha)
|
heart = self.assets.get_heart_particle(size=28, alpha=heart_alpha)
|
||||||
|
|
||||||
canvas = Image.new("RGBA", (self.config.cat_width, self.config.cat_height), (0, 0, 0, 0))
|
canvas = Image.new("RGBA", (self.config.canvas_width, self.config.canvas_height), (0, 0, 0, 0))
|
||||||
canvas.paste(base, (0, 0), base)
|
canvas.paste(base, (0, 0), base)
|
||||||
# Heart floats upwards
|
# Heart floats upwards
|
||||||
hx = int(self.config.cat_width * 0.65)
|
hx = self.config.pad_x + int(self.config.cat_width * 0.65)
|
||||||
hy = int(self.config.cat_height * 0.15 - progress * 20.0)
|
hy = self.config.pad_y + int(self.config.cat_height * 0.15 - progress * 20.0)
|
||||||
canvas.paste(heart, (hx, max(0, hy)), heart)
|
canvas.paste(heart, (hx, max(0, hy)), heart)
|
||||||
return self._composite_with_shadow(canvas, 0.0)
|
return self._composite_with_shadow(canvas, 0.0)
|
||||||
|
|
||||||
@@ -467,10 +467,10 @@ class CatController:
|
|||||||
base = self.assets.get_walk_frame(0, coat, self.facing_left, "blink")
|
base = self.assets.get_walk_frame(0, coat, self.facing_left, "blink")
|
||||||
# Animated zzz particle
|
# Animated zzz particle
|
||||||
zzz = self.assets.get_zzz_indicator(size=22)
|
zzz = self.assets.get_zzz_indicator(size=22)
|
||||||
canvas = Image.new("RGBA", (self.config.cat_width, self.config.cat_height), (0, 0, 0, 0))
|
canvas = Image.new("RGBA", (self.config.canvas_width, self.config.canvas_height), (0, 0, 0, 0))
|
||||||
canvas.paste(base, (0, 0), base)
|
canvas.paste(base, (0, 0), base)
|
||||||
zx = int(self.config.cat_width * 0.65)
|
zx = self.config.pad_x + int(self.config.cat_width * 0.65)
|
||||||
zy = int(self.config.cat_height * 0.10 + math.sin(elapsed * 2.0) * 4.0)
|
zy = self.config.pad_y + int(self.config.cat_height * 0.10 + math.sin(elapsed * 2.0) * 4.0)
|
||||||
canvas.paste(zzz, (zx, max(0, zy)), zzz)
|
canvas.paste(zzz, (zx, max(0, zy)), zzz)
|
||||||
return self._composite_with_shadow(canvas, 0.0)
|
return self._composite_with_shadow(canvas, 0.0)
|
||||||
|
|
||||||
@@ -543,14 +543,14 @@ class CatController:
|
|||||||
|
|
||||||
def _composite_with_shadow(self, sprite: Image.Image, lift: float) -> Image.Image:
|
def _composite_with_shadow(self, sprite: Image.Image, lift: float) -> Image.Image:
|
||||||
"""Draws soft contact shadow underneath the cat sprite."""
|
"""Draws soft contact shadow underneath the cat sprite."""
|
||||||
w = self.config.cat_width
|
w = self.config.canvas_width
|
||||||
h = self.config.cat_height
|
h = self.config.canvas_height
|
||||||
canvas = Image.new("RGBA", (w, h), (0, 0, 0, 0))
|
canvas = Image.new("RGBA", (w, h), (0, 0, 0, 0))
|
||||||
|
|
||||||
lift_ratio = min(1.0, lift / max(1.0, self.floor_y))
|
lift_ratio = min(1.0, lift / max(1.0, self.floor_y))
|
||||||
shadow = self.assets.get_shadow(w, lift_ratio)
|
shadow = self.assets.get_shadow(self.config.cat_width, lift_ratio)
|
||||||
sx = (w - shadow.width) // 2
|
sx = self.config.pad_x + (self.config.cat_width - shadow.width) // 2
|
||||||
sy = h - shadow.height - 1
|
sy = self.config.pad_y + self.config.cat_height - shadow.height - 1
|
||||||
canvas.paste(shadow, (sx, sy), shadow)
|
canvas.paste(shadow, (sx, sy), shadow)
|
||||||
|
|
||||||
# Cat sprite on top
|
# Cat sprite on top
|
||||||
@@ -559,12 +559,10 @@ class CatController:
|
|||||||
|
|
||||||
def _composite_with_alert(self, sprite: Image.Image) -> Image.Image:
|
def _composite_with_alert(self, sprite: Image.Image) -> Image.Image:
|
||||||
"""Paints alert exclamation mark bubble above the cat's head."""
|
"""Paints alert exclamation mark bubble above the cat's head."""
|
||||||
w = self.config.cat_width
|
|
||||||
h = self.config.cat_height
|
|
||||||
canvas = self._composite_with_shadow(sprite, 0.0)
|
canvas = self._composite_with_shadow(sprite, 0.0)
|
||||||
|
|
||||||
alert_bubble = self.assets.get_alert_bubble(size=30)
|
alert_bubble = self.assets.get_alert_bubble(size=30)
|
||||||
ax = int(w * 0.70) if not self.facing_left else int(w * 0.05)
|
ax = self.config.pad_x + (int(self.config.cat_width * 0.70) if not self.facing_left else int(self.config.cat_width * 0.05))
|
||||||
ay = 2
|
ay = self.config.pad_y + 2
|
||||||
canvas.paste(alert_bubble, (ax, ay), alert_bubble)
|
canvas.paste(alert_bubble, (ax, ay), alert_bubble)
|
||||||
return canvas
|
return canvas
|
||||||
|
|||||||
Reference in New Issue
Block a user