diff --git a/assets/towers.json b/assets/towers.json index ebbc117..260df0a 100644 --- a/assets/towers.json +++ b/assets/towers.json @@ -2,11 +2,13 @@ "soldier": { "range": 16, "damage": 5, - "gold": 10 + "gold": 10, + "keybind": "w" }, "monk": { "range": 80, "damage": 1, - "gold": 10 + "gold": 10, + "keybind": "q" } } diff --git a/assets/units.json b/assets/units.json index 6c7007f..7e50d18 100644 --- a/assets/units.json +++ b/assets/units.json @@ -2,51 +2,61 @@ "spirit":{ "health": 100, "income": 1, - "gold": 10 + "gold": 10, + "keybind":"1" }, "spirit2":{ "health": 200, "income": 2, - "gold": 20 + "gold": 20, + "keybind":"2" }, "flam2":{ "health": 300, "income": 3, - "gold": 30 + "gold": 30, + "keybind":"3" }, "flam":{ "health": 400, "income": 4, - "gold": 40 + "gold": 40, + "keybind":"4" }, "octopus":{ "health": 500, "income": 5, - "gold": 50 + "gold": 50, + "keybind":"5" }, "octopus2":{ "health": 600, "income": 6, - "gold": 60 + "gold": 60, + "keybind":"6" }, "raccon":{ "health": 700, "income": 7, - "gold": 70 + "gold": 70, + "keybind":"7" }, "gold_racoon":{ "health": 800, "income": 8, - "gold": 80 + "gold": 80, + "keybind":"8" }, "cyclope2":{ "health": 900, "income": 9, - "gold": 90 + "gold": 90, + "keybind":"9" }, "cyclope":{ "health": 1000, "income":10, - "gold": 100 + "gold": 100, + "keybind":"0" } } diff --git a/client/hud.go b/client/hud.go index d5b1061..e6ab7fc 100644 --- a/client/hud.go +++ b/client/hud.go @@ -13,6 +13,7 @@ import ( "github.com/ebitenui/ebitenui/image" "github.com/ebitenui/ebitenui/widget" "github.com/hajimehoshi/ebiten/v2" + "github.com/hajimehoshi/ebiten/v2/inpututil" "github.com/xescugc/go-flux" "github.com/xescugc/maze-wars/action" "github.com/xescugc/maze-wars/inputer" @@ -57,6 +58,32 @@ type SelectedTower struct { Invalid bool } +var ( + // The key value of this maps is the TYPE of the Unit|Tower + unitKeybinds = make(map[string]ebiten.Key) + towerKeybinds = make(map[string]ebiten.Key) +) + +func init() { + for _, u := range unit.Units { + var k ebiten.Key + err := k.UnmarshalText([]byte(u.Keybind)) + if err != nil { + panic(err) + } + unitKeybinds[u.Type.String()] = k + } + + for _, t := range tower.Towers { + var k ebiten.Key + err := k.UnmarshalText([]byte(t.Keybind)) + if err != nil { + panic(err) + } + towerKeybinds[t.Type.String()] = k + } +} + // NewHUDStore creates a new HUDStore with the Dispatcher d and the Game g func NewHUDStore(d *flux.Dispatcher, i inputer.Inputer, g *Game) (*HUDStore, error) { hs := &HUDStore{ @@ -150,11 +177,18 @@ func (hs *HUDStore) Update() error { } } - // TODO: https://github.com/xescugc/maze-wars/issues/60 - //if cp.Gold >= tower.Towers[tower.Soldier.String()].Gold && hs.input.IsKeyJustPressed(ebiten.KeyT) { - //actionDispatcher.SelectTower(tower.Soldier.String(), x, y) - //return nil - //} + for ut, kb := range unitKeybinds { + if inpututil.IsKeyJustPressed(kb) { + actionDispatcher.SummonUnit(ut, cp.ID, cp.LineID, hs.game.Store.Map.GetNextLineID(cp.LineID)) + return nil + } + } + for tt, kb := range towerKeybinds { + if inpututil.IsKeyJustPressed(kb) { + actionDispatcher.SelectTower(tt, x, y) + return nil + } + } if hst.TowerOpenMenuID != "" { if hs.input.IsKeyJustPressed(ebiten.KeyEscape) { actionDispatcher.CloseTowerMenu() @@ -607,7 +641,7 @@ func (hs *HUDStore) buildUI() { toolTxt := widget.NewText( widget.TextOpts.Position(widget.TextPositionCenter, widget.TextPositionCenter), - widget.TextOpts.Text(fmt.Sprintf("Gold: %d\nHP: %.0f\nIncome: %d ", u.Gold, u.Health, u.Income), smallFont, color.White), + widget.TextOpts.Text(fmt.Sprintf("Gold: %d\nHP: %.0f\nIncome: %d\nKeybind: %s", u.Gold, u.Health, u.Income, u.Keybind), smallFont, color.White), widget.TextOpts.WidgetOpts(widget.WidgetOpts.MinSize(100, 0)), ) tooltipContainer.AddChild(toolTxt) @@ -676,7 +710,7 @@ func (hs *HUDStore) buildUI() { toolTxt := widget.NewText( widget.TextOpts.Position(widget.TextPositionCenter, widget.TextPositionCenter), - widget.TextOpts.Text(fmt.Sprintf("Gold: %d\nRange: %.0f\nDamage: %.0f", t.Gold, t.Range, t.Damage), smallFont, color.White), + widget.TextOpts.Text(fmt.Sprintf("Gold: %d\nRange: %.0f\nDamage: %.0f\nKeybind: %s", t.Gold, t.Range, t.Damage, t.Keybind), smallFont, color.White), widget.TextOpts.WidgetOpts(widget.WidgetOpts.MinSize(100, 0)), ) tooltipContainer.AddChild(toolTxt) diff --git a/server/assets/wasm/maze-wars.wasm b/server/assets/wasm/maze-wars.wasm index 7081a25..53ccc6f 100755 Binary files a/server/assets/wasm/maze-wars.wasm and b/server/assets/wasm/maze-wars.wasm differ diff --git a/tower/tower.go b/tower/tower.go index fd16d4f..2eebbe2 100644 --- a/tower/tower.go +++ b/tower/tower.go @@ -16,6 +16,8 @@ type Tower struct { Damage float64 `json:"damage"` Gold int `json:"gold"` + Keybind string + Faceset image.Image } diff --git a/unit/unit.go b/unit/unit.go index 2c1448d..00884d9 100644 --- a/unit/unit.go +++ b/unit/unit.go @@ -16,6 +16,8 @@ type Unit struct { Income int `json:"income"` Gold int `json:"gold"` + Keybind string + Faceset image.Image Sprite image.Image }