feat(frontend): Basic Player Init
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.
This commit is contained in:
parent
8b0bcef568
commit
9157bfe8a1
|
@ -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
|
||||
|
|
43
frontend/player.go
Normal file
43
frontend/player.go
Normal file
|
@ -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
|
||||
|
||||
}
|
Reference in a new issue