Line data Source code
1 : package components
2 :
3 : import (
4 : "fmt"
5 : "image/color"
6 :
7 : "github.com/hajimehoshi/ebiten/v2/text/v2"
8 : "github.com/kijimaD/ruins/internal/consts"
9 : )
10 :
11 : // SplashTextEffect はダンジョン開始時などに画面中央にスプラッシュ表示するエフェクト。
12 : // 指定フォントで描画し、テキストの下に水平線を付ける
13 : type SplashTextEffect struct {
14 : FadeAnimation
15 : TextProperties
16 : Face text.Face // 描画に使用するフォント
17 : LineWidth float64 // テキスト下の水平線の幅
18 : }
19 :
20 : // DamageTextEffect はエンティティ座標で浮遊テキストを表示するエフェクト。
21 : // ダメージ、回復、ミス、ヒットなどに使用する
22 : type DamageTextEffect struct {
23 : FadeAnimation
24 : TextProperties
25 : VelocityY float64 // Y方向の速度(上に浮かぶ効果用)
26 : }
27 :
28 : // Update はフェードアニメーションを進めつつY座標を移動させる
29 : func (e *DamageTextEffect) Update(deltaMs float64) bool {
30 1 : e.Offset.Y += e.VelocityY
31 1 : return e.FadeAnimation.Update(deltaMs)
32 1 : }
33 :
34 : // SpriteFadeoutEffect はスプライトをフェードアウト表示するエフェクト。
35 : // 敵撃破時などに使用する
36 : type SpriteFadeoutEffect struct {
37 : FadeAnimation
38 : SpriteSheetName string // スプライトシート名
39 : SpriteKey string // スプライトキー
40 : }
41 :
42 : // NewSplashTextEffect はダンジョン開始時などのスプラッシュエフェクトを作成する
43 : func NewSplashTextEffect(textStr string, face text.Face, screenW, screenH int) *SplashTextEffect {
44 1 : fadeInMs := 800.0
45 1 : holdMs := 1600.0
46 1 : fadeOutMs := 800.0
47 1 : totalMs := fadeInMs + holdMs + fadeOutMs
48 1 :
49 1 : return &SplashTextEffect{
50 1 : FadeAnimation: FadeAnimation{
51 1 : FadeInMs: fadeInMs,
52 1 : HoldMs: holdMs,
53 1 : FadeOutMs: fadeOutMs,
54 1 : TotalMs: totalMs,
55 1 : RemainingMs: totalMs,
56 1 : Alpha: 0.0,
57 1 : },
58 1 : TextProperties: TextProperties{
59 1 : Offset: consts.Coord[float64]{X: float64(screenW) / 2, Y: float64(screenH) * 2 / 5},
60 1 : Text: textStr,
61 1 : Color: color.RGBA{255, 255, 255, 255},
62 1 : },
63 1 : Face: face,
64 1 : LineWidth: float64(screenW) * 0.7,
65 1 : }
66 : }
67 :
68 : // NewDamageEffect はダメージ数値表示エフェクトを作成する
69 : func NewDamageEffect(damage int) *DamageTextEffect {
70 1 : totalMs := 800.0
71 1 : return &DamageTextEffect{
72 1 : FadeAnimation: FadeAnimation{
73 1 : FadeInMs: 100,
74 1 : HoldMs: 500,
75 1 : FadeOutMs: 200,
76 1 : TotalMs: totalMs,
77 1 : RemainingMs: totalMs,
78 1 : Alpha: 0.0,
79 1 : },
80 1 : TextProperties: TextProperties{
81 1 : Offset: consts.Coord[float64]{X: 0, Y: -8},
82 1 : Text: fmt.Sprintf("%d", damage),
83 1 : Color: color.RGBA{255, 80, 80, 255},
84 1 : },
85 1 : VelocityY: -0.5,
86 1 : }
87 : }
88 :
89 : // NewMissEffect はミス表示エフェクトを作成する
90 : func NewMissEffect() *DamageTextEffect {
91 1 : totalMs := 600.0
92 1 : return &DamageTextEffect{
93 1 : FadeAnimation: FadeAnimation{
94 1 : FadeInMs: 50,
95 1 : HoldMs: 400,
96 1 : FadeOutMs: 150,
97 1 : TotalMs: totalMs,
98 1 : RemainingMs: totalMs,
99 1 : Alpha: 0.0,
100 1 : },
101 1 : TextProperties: TextProperties{
102 1 : Offset: consts.Coord[float64]{X: 0, Y: -8},
103 1 : Text: "MISS",
104 1 : Color: color.RGBA{180, 180, 180, 255},
105 1 : },
106 1 : VelocityY: -0.3,
107 1 : }
108 : }
109 :
110 : // NewHealEffect は回復数値表示エフェクトを作成する
111 : func NewHealEffect(amount int) *DamageTextEffect {
112 1 : totalMs := 800.0
113 1 : return &DamageTextEffect{
114 1 : FadeAnimation: FadeAnimation{
115 1 : FadeInMs: 100,
116 1 : HoldMs: 500,
117 1 : FadeOutMs: 200,
118 1 : TotalMs: totalMs,
119 1 : RemainingMs: totalMs,
120 1 : Alpha: 0.0,
121 1 : },
122 1 : TextProperties: TextProperties{
123 1 : Offset: consts.Coord[float64]{X: 0, Y: -8},
124 1 : Text: fmt.Sprintf("+%d", amount),
125 1 : Color: color.RGBA{80, 255, 80, 255},
126 1 : },
127 1 : VelocityY: -0.5,
128 1 : }
129 : }
130 :
131 : // NewSpriteFadeoutEffect はスプライトフェードアウトエフェクトを作成する
132 : func NewSpriteFadeoutEffect(spriteSheetName, spriteKey string) *SpriteFadeoutEffect {
133 1 : totalMs := 400.0
134 1 : return &SpriteFadeoutEffect{
135 1 : FadeAnimation: FadeAnimation{
136 1 : FadeInMs: 0,
137 1 : HoldMs: 100,
138 1 : FadeOutMs: 300,
139 1 : TotalMs: totalMs,
140 1 : RemainingMs: totalMs,
141 1 : Alpha: 1.0,
142 1 : },
143 1 : SpriteSheetName: spriteSheetName,
144 1 : SpriteKey: spriteKey,
145 1 : }
146 : }
|