From 99471afc4a6931e4b8510f05027467954473fd40 Mon Sep 17 00:00:00 2001 From: Abdulmujeeb Raji Date: Sun, 23 Jul 2023 09:20:48 +0100 Subject: [PATCH] feat(frontend): basic player structure Player has health, level, exp (which is gained constantly while online) and ambition (which affects the rate of exp gain). More stats will be added later. This is mostly just a test implementation. Will clean up later. --- frontend/main.go | 13 +++++++++++++ frontend/player.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 frontend/player.go diff --git a/frontend/main.go b/frontend/main.go index 64b9204..520df0c 100644 --- a/frontend/main.go +++ b/frontend/main.go @@ -6,14 +6,18 @@ import ( // Logs "log" + + "strconv" // Ebitengine "github.com/hajimehoshi/ebiten/v2" + "github.com/hajimehoshi/ebiten/v2/ebitenutil" ) // Create the `Game` struct type Game struct { ui UI + activePlayer Player } const ( @@ -24,6 +28,7 @@ const ( // Update implements Game func (g *Game) Update() error { g.ui.base.Update() + g.activePlayer.update() return nil } @@ -31,6 +36,11 @@ func (g *Game) Update() error { func (g *Game) Draw(screen *ebiten.Image) { // Draw the UI onto the screen g.ui.base.Draw(screen) + + ebitenutil.DebugPrintAt(screen, "health: " + strconv.Itoa(g.activePlayer.health), 0, 0) + ebitenutil.DebugPrintAt(screen, "level: " + strconv.Itoa(g.activePlayer.level), 0, 10) + ebitenutil.DebugPrintAt(screen, "exp: " + strconv.Itoa(int(g.activePlayer.exp)), 0, 20) + ebitenutil.DebugPrintAt(screen, "ambittion: " + strconv.Itoa(int(g.activePlayer.ambition)), 0, 30) } // Layout implements Game @@ -53,11 +63,14 @@ func main() { // Engine setup ebiten.SetWindowSize(window_width, window_height) ebiten.SetWindowTitle(window_title) + + testPlayer := initPlayer() // Initialise the game game := Game{ // Initialise the UI ui: uiInit(window_width, window_height), + activePlayer: testPlayer, } // Log and exit on error diff --git a/frontend/player.go b/frontend/player.go new file mode 100644 index 0000000..ea12fd0 --- /dev/null +++ b/frontend/player.go @@ -0,0 +1,43 @@ +package main + +import ( + "math/rand" +) + +type Player struct { + health int + level int + exp float32 + ambition float32 +} + +// NOTE(midnadimple): These gates are temporary. We'll decide on real values later +var level_gates = map[int]float32{ + 1: 100.0, + 2: 150.0, + 3: 300.0, +} + +// TODO(midnadimple): Move player initialization to server upon login +func initPlayer() Player { + return Player{ + health: 100, + level: 1, + exp: 0.0, + ambition: (rand.Float32() * 10), // NOTE(midnadimple): In the future this will be affected by player activity + } +} + +func (p *Player) update() { + // TODO(midnadimple): update health upon damage + + if p.exp >= level_gates[p.level] { + p.exp = 0.0 + p.level += 1 + } + + // NOTE(midnadimple): This formula for exp gain is pretty simple, maybe devraza can think of + // a more practical one + p.exp += 10.0 * (1.0/60.0) * p.ambition + +} \ No newline at end of file