Skip to content

Commit

Permalink
Player names
Browse files Browse the repository at this point in the history
  • Loading branch information
benc-uk committed Sep 27, 2024
1 parent 8dfb4ec commit 754c6b2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
13 changes: 12 additions & 1 deletion engine/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package engine

import (
"roguelike/core"
"strings"

fn "github.com/s0rg/fantasyname"
)

// ============================================================================
Expand All @@ -24,9 +27,17 @@ type Player struct {
}

func NewPlayer(pos core.Pos) *Player {
name := "Jimmy No Name"
gen, err := fn.Compile("sd", fn.Collapse(true), fn.RandFn(rng.IntN))
if err == nil {
name = gen.String()
// capitalize the first letter
name = strings.ToUpper(name[:1]) + name[1:]
}

return &Player{
pos: pos,
name: "Player",
name: name,
currentHP: 10,
maxHP: 10,
exp: 0,
Expand Down
2 changes: 2 additions & 0 deletions game/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,10 @@ func main() {
ebitenGame.viewPort = game.GetViewPort(VP_COLS, VP_ROWS)
game.UpdateFOV(ebitenGame.viewDist)

// TODO: Move this to a more appropriate place like the engine
levelText := fmt.Sprintf("You are on level %d of %s", game.Map().Depth(), game.Map().Description())
ebitenGame.events = append(ebitenGame.events, &engine.GameEvent{Type: "game_state", Text: "Version " + version})
ebitenGame.events = append(ebitenGame.events, &engine.GameEvent{Type: "game_state", Text: "Welcome adventurer " + game.Player().Name()})
ebitenGame.events = append(ebitenGame.events, &engine.GameEvent{Type: "game_state", Text: levelText})

// Phew - finally start the ebiten game loop with RunGame
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ require (
github.com/hajimehoshi/bitmapfont/v3 v3.2.0
github.com/hajimehoshi/ebiten/v2 v2.8.0
github.com/pterm/pterm v0.12.79
github.com/s0rg/fantasyname v1.3.5
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561
gopkg.in/yaml.v3 v3.0.1
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ github.com/pterm/pterm v0.12.79/go.mod h1:1v/gzOF1N0FsjbgTHZ1wVycRkKiatFvJSJC4IG
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/s0rg/fantasyname v1.3.5 h1:7DWARGrTsyb4uyN7JJUYdE2EXPP6kbNc2sjbqUJiuZ8=
github.com/s0rg/fantasyname v1.3.5/go.mod h1:oPRoapYwGx1sY0jXkr82dtDfa5GiGvo9ukQE8P36rJg=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down

0 comments on commit 754c6b2

Please sign in to comment.