Skip to content

Commit

Permalink
Start adding color
Browse files Browse the repository at this point in the history
  • Loading branch information
bobtfish committed Feb 6, 2021
1 parent f1c6cdd commit 4434895
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 15 deletions.
8 changes: 4 additions & 4 deletions character/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions fx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
4 changes: 2 additions & 2 deletions grid/empty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions grid/gameobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type GameObject interface {
GetSpriteSheetCoordinates() logical.Vec
GetColor() color.Color
IsEmpty() bool
Describe() string
Describe() (string, string)
SetBoardPosition(logical.Vec)
}

Expand Down Expand Up @@ -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()
}

Expand Down
4 changes: 2 additions & 2 deletions player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion screen/castspell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
}
Expand Down
16 changes: 16 additions & 0 deletions screen/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package screen

import (
"fmt"
"image/color"
"strings"

"github.com/faiface/pixel"
Expand Down Expand Up @@ -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)
}
10 changes: 8 additions & 2 deletions screen/with_cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 4434895

Please sign in to comment.