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
|
// Logs
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"strconv"
|
||||||
|
|
||||||
// Ebitengine
|
// Ebitengine
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
|
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create the `Game` struct
|
// Create the `Game` struct
|
||||||
type Game struct {
|
type Game struct {
|
||||||
ui UI
|
ui UI
|
||||||
|
activePlayer Player
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -24,6 +28,7 @@ const (
|
||||||
// Update implements Game
|
// Update implements Game
|
||||||
func (g *Game) Update() error {
|
func (g *Game) Update() error {
|
||||||
g.ui.base.Update()
|
g.ui.base.Update()
|
||||||
|
g.activePlayer.update()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +36,11 @@ func (g *Game) Update() error {
|
||||||
func (g *Game) Draw(screen *ebiten.Image) {
|
func (g *Game) Draw(screen *ebiten.Image) {
|
||||||
// Draw the UI onto the screen
|
// Draw the UI onto the screen
|
||||||
g.ui.base.Draw(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
|
// Layout implements Game
|
||||||
|
@ -53,11 +63,14 @@ func main() {
|
||||||
// Engine setup
|
// Engine setup
|
||||||
ebiten.SetWindowSize(window_width, window_height)
|
ebiten.SetWindowSize(window_width, window_height)
|
||||||
ebiten.SetWindowTitle(window_title)
|
ebiten.SetWindowTitle(window_title)
|
||||||
|
|
||||||
|
testPlayer := initPlayer()
|
||||||
|
|
||||||
// Initialise the game
|
// Initialise the game
|
||||||
game := Game{
|
game := Game{
|
||||||
// Initialise the UI
|
// Initialise the UI
|
||||||
ui: uiInit(window_width, window_height),
|
ui: uiInit(window_width, window_height),
|
||||||
|
activePlayer: testPlayer,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log and exit on error
|
// 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