Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: Changed the font to be a monospaced one #87

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed assets/NormalFont.ttf
Binary file not shown.
4 changes: 2 additions & 2 deletions assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ var Towers_json []byte
//go:embed units.json
var Units_json []byte

//go:embed NormalFont.ttf
var NormalFont_ttf []byte
//go:embed kongtext.ttf
var Kongtext_ttf []byte

//go:embed LifeBarMiniProgress.png
var LifeBarMiniProgress_png []byte
Expand Down
Binary file added assets/kongtext.ttf
Binary file not shown.
47 changes: 44 additions & 3 deletions client/hud.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"image/color"
"math"
"sort"
"strconv"
"strings"

"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/text"
Expand Down Expand Up @@ -323,19 +325,58 @@ func (hs *HUDStore) Draw(screen *ebiten.Image) {
screen.DrawImage(ebiten.NewImageFromImage(hst.SelectedTower.Faceset()), op)
}

// To make the table for the players more readable we are gonna make a table,
// the table will have headers and here I'm gonna put the characters each one
// will have from left to right:
// * -Space-: 2 "|\s"
// * Name: 20
// * -Space-: 3 "\s|\s"
// * Lives: 8
// * -Space-: 3 "\s|\s"
// * Gold: 8
// * -Space-: 3 "\s|\s"
// * Income: 8
// * -Space-: 2 "\s|"
// Total of 57
psit := hs.game.Store.Players.GetState().(store.PlayersState).IncomeTimer
players := hs.game.Store.Players.List()
text.Draw(screen, fmt.Sprintf("Income Timer: %ds", psit), smallFont, 0, 15, color.White)
var pcount = 2
text.Draw(screen, fmt.Sprintf("Income Timer: %ds", psit), smallFont, 0, 16, color.White)
var pcount = 4
var sortedPlayers = make([]*store.Player, 0, 0)
for _, p := range players {
sortedPlayers = append(sortedPlayers, p)
}
sort.Slice(sortedPlayers, func(i, j int) bool { return sortedPlayers[i].LineID < sortedPlayers[j].LineID })
text.Draw(screen, "---------------------------------------------------------", smallFont, 0, 32, color.White)
text.Draw(screen, "| Name | Lives | Gold | Income |", smallFont, 0, 48, color.White)
for _, p := range sortedPlayers {
text.Draw(screen, fmt.Sprintf("Name: %s, Lives: %d, Gold: %d, Income: %d", p.Name, p.Lives, p.Gold, p.Income), smallFont, 0, 15*pcount, color.White)
var c color.Color = color.White
if p.ID == cp.ID {
c = green
}
text.Draw(screen, fmt.Sprintf(
"| %s | %s | %s | %s |",
fillIn(p.Name, 20),
fillIn(strconv.Itoa(p.Lives), 8),
fillIn(strconv.Itoa(p.Gold), 8),
fillIn(strconv.Itoa(p.Income), 8),
), smallFont, 0, 16*pcount, c)
pcount++
}
text.Draw(screen, "_________________________________________________________", smallFont, 0, 16*pcount, color.White)
}

func fillIn(s string, l int) string {
ss := make([]string, l, l)
for i, v := range s {
ss[i] = string(v)
}
for i, v := range ss {
if string(v) == "" {
ss[i] = " "
}
}
return strings.Join(ss, "")
}

func (hs *HUDStore) Reduce(state, a interface{}) interface{} {
Expand Down
3 changes: 2 additions & 1 deletion client/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func init() {
rand.Seed(time.Now().UnixNano())

// Initialize Font
tt, err := opentype.Parse(assets.NormalFont_ttf)
tt, err := opentype.Parse(assets.Kongtext_ttf)
if err != nil {
log.Fatal(err)
}
Expand All @@ -55,6 +55,7 @@ func init() {
if err != nil {
log.Fatal(err)
}

}

func New(ctx context.Context, ad *ActionDispatcher, rs *RouterStore, opt Options) error {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/xescugc/maze-wars
go 1.21

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/gofrs/uuid v4.4.0+incompatible
github.com/golang/mock v1.6.0
github.com/gorilla/handlers v1.5.2
Expand All @@ -18,6 +17,7 @@ require (
)

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/ebitengine/purego v0.4.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand Down
Binary file modified server/assets/wasm/maze-wars.wasm
Binary file not shown.