Skip to content

Commit

Permalink
unit: Added the ability 'Burrow' for the 'Mole'
Browse files Browse the repository at this point in the history
  • Loading branch information
xescugc committed Jun 6, 2024
1 parent 23f77aa commit 27666c7
Show file tree
Hide file tree
Showing 16 changed files with 378 additions and 36 deletions.
4 changes: 3 additions & 1 deletion action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ type SyncStateTowerPayload struct {

type SyncStateUnitPayload struct {
utils.MovingObject
AnimationCount int

ID string
Type string
Expand All @@ -491,7 +492,8 @@ type SyncStateUnitPayload struct {
HashPath string
CreatedAt time.Time

AbilitiesMetadata map[string]interface{}
Abilities map[string]interface{}
Buffs map[string]interface{}
}

// TODO: or make the action.Action separated or make the store.Player separated
Expand Down
10 changes: 10 additions & 0 deletions assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ var MoleWalk_png []byte
//go:embed ninja_adventure_asset_pack/Actor/Monsters/Mole/Faceset.png
var MoleFaceset_png []byte

// go:embed ninja_adventure_asset_pack/FX/Particle/Rock.png
//
// go:embed ninja_adventure_asset_pack/FX/Smoke/Smoke/SpriteSheet.png
//
// go:embed ninja_adventure_asset_pack/Backgrounds/Animated/QuickSand/QuickSand32x32.png
// var MoleBurrowed_png []byte
//
//go:embed ninja_adventure_asset_pack/Backgrounds/Tilesets/TilesetNature.png
var TilesetNature_png []byte

//go:embed ninja_adventure_asset_pack/Actor/Characters/SkeletonDemon/SeparateAnim/Walk.png
var SkeletonDemonWalk_png []byte

Expand Down
3 changes: 2 additions & 1 deletion assets/units.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"gold": 10,
"keybind":"5",
"environment":"terrestrial",
"movement_speed": 50
"movement_speed": 50,
"abilities": ["burrow"]
},
"skeleton_demon":{
"health": 7,
Expand Down
10 changes: 10 additions & 0 deletions client/game/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ var (
const (
crossImageKey string = "cross-image"
arrowImageKey string = "arrow"

buffBurrowedKey string = "buff-burrowed"
buffBurrowedReadyKey string = "buff-burrowed-ready"
)

// ImagesCache is a simple cache for all the images, so instead
Expand Down Expand Up @@ -56,6 +59,13 @@ func init() {

imagesCache.images[crossImageKey] = ebiten.NewImageFromImage(ebiten.NewImageFromImage(tli).SubImage(image.Rect(4*16, 5*16, 4*16+16, 5*16+16)))
imagesCache.images[arrowImageKey] = ebiten.NewImageFromImage(ai)

tsn, _, err := image.Decode(bytes.NewReader(assets.TilesetNature_png))
if err != nil {
panic(err)
}
imagesCache.images[buffBurrowedReadyKey] = ebiten.NewImageFromImage(ebiten.NewImageFromImage(tsn).SubImage(image.Rect(4*16, 17*16, 4*16+16, 17*16+16)))
imagesCache.images[buffBurrowedKey] = ebiten.NewImageFromImage(ebiten.NewImageFromImage(tsn).SubImage(image.Rect(6*16, 17*16, 6*16+16, 17*16+16)))
}

// Get will return the image from 'key', if it does not
Expand Down
24 changes: 21 additions & 3 deletions client/game/lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/xescugc/maze-wars/assets"
cutils "github.com/xescugc/maze-wars/client/utils"
"github.com/xescugc/maze-wars/store"
"github.com/xescugc/maze-wars/unit/buff"
"github.com/xescugc/maze-wars/utils"
)

Expand Down Expand Up @@ -73,7 +74,7 @@ func (ls *Lines) Draw(screen *ebiten.Image) {
for _, t := range l.Towers {
ls.DrawTower(screen, ls.game.Camera, t)
}
for _, u := range l.Units {
for _, u := range l.ListSortedUnits() {
ls.DrawUnit(screen, ls.game.Camera, u)
}
}
Expand Down Expand Up @@ -104,12 +105,20 @@ func (ls *Lines) DrawUnit(screen *ebiten.Image, c *CameraStore, u *store.Unit) {
return
}
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(u.X-cs.X), float64(u.Y-cs.Y))
op.GeoM.Translate(u.X-cs.X, u.Y-cs.Y)
op.GeoM.Scale(cs.Zoom, cs.Zoom)
sx := directionToTile[u.Facing] * u.W
i := (u.MovingCount / 5) % 4
sy := i * u.H
screen.DrawImage(imagesCache.Get(u.WalkKey()).SubImage(image.Rect(sx, sy, sx+u.W, sy+u.H)).(*ebiten.Image), op)
if u.HasBuff(buff.Burrowoed) {
if u.CanUnburrow(time.Now()) {
screen.DrawImage(imagesCache.Get(buffBurrowedReadyKey), op)
} else {
screen.DrawImage(imagesCache.Get(buffBurrowedKey), op)
}
} else {
screen.DrawImage(imagesCache.Get(u.WalkKey()).SubImage(image.Rect(sx, sy, sx+u.W, sy+u.H)).(*ebiten.Image), op)
}

// Only draw the Health bar if the unit has been hit
if u.Health != u.MaxHealth {
Expand All @@ -121,4 +130,13 @@ func (ls *Lines) DrawUnit(screen *ebiten.Image, c *CameraStore, u *store.Unit) {
op.GeoM.Translate(u.X-cs.X, u.Y-cs.Y-float64(ls.lifeBarProgress.Bounds().Dy()))
screen.DrawImage(ls.lifeBarProgress.(*ebiten.Image).SubImage(image.Rect(0, 0, int(float64(ls.lifeBarProgress.Bounds().Dx())*(u.Health/u.MaxHealth)), ls.lifeBarProgress.Bounds().Dy())).(*ebiten.Image), op)
}

// TODO: Animation logic
//if u.HasBuff(buff.Burrowoed) {
//i := (u.AnimationCount / 15) % 8
//op = &ebiten.DrawImageOptions{}
//op.GeoM.Translate(u.X-cs.X-float64(u.W/2), u.Y-cs.Y-float64(u.H/2))
//img := imagesCache.Get(buffBurrowedKey)
//screen.DrawImage(img.SubImage(image.Rect(i*32, 0, i*32+32, i*32+32)).(*ebiten.Image), op)
//}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/gorilla/mux v1.8.1
github.com/hajimehoshi/ebiten/v2 v2.6.4
github.com/joeycumines/go-behaviortree v1.8.0
github.com/mitchellh/mapstructure v1.5.0
github.com/sagikazarmark/slog-shim v0.1.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.1
Expand All @@ -31,7 +32,6 @@ require (
github.com/jezek/xgb v1.1.1 // indirect
github.com/joeycumines/go-bigbuff v1.14.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
Expand Down
Binary file modified server/assets/wasm/maze-wars.wasm
Binary file not shown.
8 changes: 5 additions & 3 deletions server/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ func (b *Bot) findTowerToUpdate() func(children []bht.Node) (bht.Status, error)
cp := b.store.Lines.FindPlayerByID(b.playerID)
for _, t := range b.store.Lines.FindLineByID(cp.LineID).Towers {
tu := tower.FindUpdateByLevel(t.Type, t.Level+1)
if cp.Gold-tu.UpdateCost > 0 {
b.towerIDToUpdate = t.ID
return bht.Success, nil
if tu != nil {
if cp.Gold-tu.UpdateCost > 0 {
b.towerIDToUpdate = t.ID
return bht.Success, nil
}
}
}
return bht.Failure, nil
Expand Down
34 changes: 34 additions & 0 deletions store/abilities.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package store

import "time"

type AbilitySplit struct {
// UnitID is the other unit
// that belong to this Split.
// The bounty must only be given
// when all are dead
UnitID string `mapstructure:"UnitID"`
}

const (
burrowTime = time.Second * 15
maxBurrowTime = time.Second * 45
)

type AbilityBurrow struct {
// BurrowAt is the time in which it was burrowed.
// It'll stay there for 15s and then the next unit
// that steps on it it'll pop up again.
// If in 45s no unit stept on it it'll unburrow
// itself up
BurrowAt time.Time `mapstructure:"BurrowAt"`
Unburrowed bool `mapstructure:"Unburrowed"`
}

func (ab AbilityBurrow) CanUnburrow(t time.Time) bool {
return t.Sub(ab.BurrowAt) > burrowTime
}

func (ab AbilityBurrow) MustUnburrow(t time.Time) bool {
return t.Sub(ab.BurrowAt) > maxBurrowTime
}
9 changes: 0 additions & 9 deletions store/abilities_metadata.go

This file was deleted.

7 changes: 7 additions & 0 deletions store/buffs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package store

type Buffs struct {
Burrowed *BuffBurrowed
}

type BuffBurrowed struct{}
Loading

0 comments on commit 27666c7

Please sign in to comment.