From 4434895570c07f227ded5a2fe94e85524d4ca087 Mon Sep 17 00:00:00 2001 From: Tomas Doran Date: Sat, 6 Feb 2021 21:02:38 +0000 Subject: [PATCH] Start adding color --- character/character.go | 8 ++++---- fx/main.go | 4 ++-- grid/empty.go | 4 ++-- grid/gameobject.go | 4 ++-- player/player.go | 4 ++-- screen/castspell.go | 7 ++++++- screen/utils.go | 16 ++++++++++++++++ screen/with_cursor.go | 10 ++++++++-- 8 files changed, 42 insertions(+), 15 deletions(-) diff --git a/character/character.go b/character/character.go index e5e553b..3b6cb95 100644 --- a/character/character.go +++ b/character/character.go @@ -303,18 +303,18 @@ func (c *Character) GetColor() color.Color { return c.Color } -func (c *Character) Describe() string { +func (c *Character) Describe() (string, string) { if c.BelongsTo != nil { carry := "" if c.CarryingPlayer { carry = "#" } - return fmt.Sprintf("%s%s (%s)", c.Name, carry, c.BelongsTo.Name) + return fmt.Sprintf("%s%s", c.Name, carry), c.BelongsTo.Name } if c.IsDead { - return fmt.Sprintf("%s (Dead)", c.Name) + return fmt.Sprintf("%s (Dead)", c.Name), "" } - return c.Name + return c.Name, "" } func (c *Character) SetBoardPosition(v logical.Vec) { diff --git a/fx/main.go b/fx/main.go index 78c39e5..ede6008 100644 --- a/fx/main.go +++ b/fx/main.go @@ -44,8 +44,8 @@ func (f *Fx) GetColor() color.Color { return f.Color } -func (f *Fx) Describe() string { - return fmt.Sprintf("Fx:%T", *f) +func (f *Fx) Describe() (string, string) { + return fmt.Sprintf("Fx:%T", *f), "" } func (f *Fx) SetBoardPosition(v logical.Vec) {} diff --git a/grid/empty.go b/grid/empty.go index d22fba9..02e77ee 100644 --- a/grid/empty.go +++ b/grid/empty.go @@ -30,8 +30,8 @@ func (e EmptyObject) GetColor() color.Color { return render.GetColor(0, 0, 0) } -func (e EmptyObject) Describe() string { - return "" +func (e EmptyObject) Describe() (string, string) { + return "", "" } func (e EmptyObject) IsEmpty() bool { diff --git a/grid/gameobject.go b/grid/gameobject.go index 238bdc7..fce9df0 100644 --- a/grid/gameobject.go +++ b/grid/gameobject.go @@ -12,7 +12,7 @@ type GameObject interface { GetSpriteSheetCoordinates() logical.Vec GetColor() color.Color IsEmpty() bool - Describe() string + Describe() (string, string) SetBoardPosition(logical.Vec) } @@ -62,7 +62,7 @@ func (s *GameObjectStack) GetColor() color.Color { return (*s)[0].GetColor() } -func (s *GameObjectStack) Describe() string { +func (s *GameObjectStack) Describe() (string, string) { return (*s)[0].Describe() } diff --git a/player/player.go b/player/player.go index eb4319e..2d5b56a 100644 --- a/player/player.go +++ b/player/player.go @@ -73,8 +73,8 @@ func (p *Player) GetColor() color.Color { return p.Color } -func (p *Player) Describe() string { - return p.Name +func (p *Player) Describe() (string, string) { + return p.Name, "" } // GameObjectStackable interface diff --git a/screen/castspell.go b/screen/castspell.go index 874faac..baf018a 100644 --- a/screen/castspell.go +++ b/screen/castspell.go @@ -8,6 +8,7 @@ import ( "github.com/bobtfish/mayhem/fx" "github.com/bobtfish/mayhem/game" "github.com/bobtfish/mayhem/logical" + "github.com/bobtfish/mayhem/render" screeniface "github.com/bobtfish/mayhem/screen/iface" ) @@ -46,7 +47,11 @@ func (screen *DisplaySpellCastScreen) Enter(ctx screeniface.GameCtx) { if thisPlayer.ChosenSpell >= 0 { spell := thisPlayer.Spells[thisPlayer.ChosenSpell] batch := DrawBoard(ctx) - textBottom(fmt.Sprintf("%s %s %d", thisPlayer.Name, spell.GetName(), spell.GetCastRange()), ss, batch) + textBottomMulti([]TextWithColor{ + TextWithColor{Text: fmt.Sprintf("%s ", thisPlayer.Name), Color: render.GetColor(255, 255, 0)}, + TextWithColor{Text: fmt.Sprintf("%s ", spell.GetName()), Color: render.GetColor(0, 242, 0)}, + TextWithColor{Text: fmt.Sprintf("%d", spell.GetCastRange()), Color: render.GetColor(244, 244, 244)}, + }, ss, batch) batch.Draw(win) } } diff --git a/screen/utils.go b/screen/utils.go index 8eebb9b..9322b15 100644 --- a/screen/utils.go +++ b/screen/utils.go @@ -2,6 +2,7 @@ package screen import ( "fmt" + "image/color" "strings" "github.com/faiface/pixel" @@ -174,3 +175,18 @@ func textBottom(text string, ss pixel.Picture, target pixel.Target) { td.DrawText(text, logical.ZeroVec(), target) td.DrawText(strings.Repeat(" ", 32-len(text)), logical.V(len(text), 0), target) } + +type TextWithColor struct { + Color color.Color + Text string +} + +func textBottomMulti(texts []TextWithColor, ss pixel.Picture, target pixel.Target) { + var idx int + td := render.NewTextDrawer(ss) + for _, t := range texts { + td.DrawTextColor(t.Text, logical.V(idx, 0), t.Color, target) + idx = idx + len(t.Text) + } + td.DrawText(strings.Repeat(" ", 32-idx), logical.V(idx, 0), target) +} diff --git a/screen/with_cursor.go b/screen/with_cursor.go index edea6d6..8bcfd5a 100644 --- a/screen/with_cursor.go +++ b/screen/with_cursor.go @@ -58,8 +58,14 @@ func (screen *WithCursor) DrawCursor(ctx screeniface.GameCtx, batch pixel.Target if !objectAtCursor.IsEmpty() { cursorColor = objectAtCursor.GetColor() } - description := objectAtCursor.Describe() - textBottom(description, ss, batch) + description1, description2 := objectAtCursor.Describe() + if len(description2) > 0 { + description2 = fmt.Sprintf("(%s)", description2) + } + textBottomMulti([]TextWithColor{ + TextWithColor{Text: description1, Color: render.GetColor(0, 246, 246)}, + TextWithColor{Text: description2, Color: render.GetColor(241, 241, 0)}, + }, ss, batch) if screen.ShouldIDrawCursor() || objectAtCursor.IsEmpty() { sd.DrawSpriteColor(cursorSprite(screen.CursorSprite), screen.CursorPosition, cursorColor, batch) }