diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-04 23:05:42 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-04 23:05:42 +0200 |
| commit | 5224fdc80913597287a5f67efec5d0be3254ce59 (patch) | |
| tree | 7b6c4cac23223926ffb620a2c9a6a43caab6b613 | |
| parent | a5fef758107888853c14a592696b45768ef56df8 (diff) | |
Fmt
| -rw-r--r-- | README.md | 23 | ||||
| -rw-r--r-- | gather_order.go | 10 | ||||
| -rw-r--r-- | main.go | 6 | ||||
| -rw-r--r-- | order.go | 7 | ||||
| -rw-r--r-- | selection.go | 2 |
5 files changed, 14 insertions, 34 deletions
@@ -5,27 +5,8 @@ ## TODO - atm, stops moving if someone settles at destination - -```go -func (g \*Game) updatePlacingWall(cursor Point) { - if inpututil.IsMouseButtonJustReleased(ebiten.MouseButtonLeft) { - if cursor.In(soil.Bounds()) { - position := cursor.Sub(soil.Position).Div(100).Mul(100).Add(Point{50, 50}) - g.Blocks = append(g.Blocks, Block{NewTile(Point{100, 100}, position, color.RGBA{0x00, 0x00, 0x00, 0xff}), WallBlock}) - } - } -} -``` - -```go - if inpututil.IsMouseButtonJustReleased(ebiten.MouseButtonLeft) && cursor.In(wallButton.CollisionBounds()) { - if g.CurrentAction == PlacingWall { - g.CurrentAction = Selecting - } else { - g.CurrentAction = PlacingWall - } - } -``` +- save globally resources +- an entity may spawn other enities with a cost ## Dependencies diff --git a/gather_order.go b/gather_order.go index 2f5a060..e359146 100644 --- a/gather_order.go +++ b/gather_order.go @@ -24,8 +24,8 @@ func (o *GatherOrder) Update(e *Entity, g *Game) { return } if physics.Distance(e.Position.Value, gatherer.CurrentTarget.Position.Value) <= 100 { - o.updateGathering(gatherer, source) - return + o.updateGathering(gatherer, source) + return } if !e.Move.Value.IsActive { o.startMoveToSource(e, gatherer, g) @@ -57,7 +57,7 @@ func (o *GatherOrder) updateGathererFull(e *Entity, g *Game, gatherer *ResourceG slog.Info("storage target", slog.String("storage", destination.String()), slog.Int("distance", distance)) if distance > 1 { slog.Info("moving to storage", slog.String("storage", destination.String())) - physics.StartMove(&e.Move,e.Position, destination, g.getMoveMap()) + physics.StartMove(&e.Move, e.Position, destination, g.getMoveMap()) return } gatherer.CurrentVolume = 0 @@ -73,7 +73,7 @@ func (o *GatherOrder) startMoveToSource(e *Entity, gatherer *ResourceGatherer, g e.Order.Value = nil return } - physics.StartMove(&e.Move,e.Position, destination, g.getMoveMap()) + physics.StartMove(&e.Move, e.Position, destination, g.getMoveMap()) } func getAllStorageDockings(g *Game) []physics.Point { @@ -99,7 +99,7 @@ func Gather(e *Entity, source *Entity, g *Game) Order { e.Order.Value = nil return nil } - physics.StartMove(&e.Move,e.Position, destination, g.getMoveMap()) + physics.StartMove(&e.Move, e.Position, destination, g.getMoveMap()) } } return &GatherOrder{source: source} @@ -35,7 +35,7 @@ type Game struct { Selection GlobalSelection } -func DrawMove(screen *ebiten.Image, e *Entity) { +func DrawMove(screen *ebiten.Image, e *Entity) { if e.Move.IsEnabled && e.Position.IsEnabled && e.Selection.IsEnabled { if e.Selection.Value.IsSelected && e.Move.Value.IsActive { last := e.Position.Value @@ -96,7 +96,7 @@ func (g *Game) updateSelecting(cursor physics.Point, moveMap physics.MoveMap) { if entityAtDestination != nil && entityAtDestination.ResourceSource.IsEnabled { Gather(e, entityAtDestination, g) } else { - physics.StartMove(&e.Move,e.Position, destination, moveMap) + physics.StartMove(&e.Move, e.Position, destination, moveMap) } } } @@ -147,7 +147,7 @@ func (g *Game) Update() error { g.updatePatrolling(cursor) } for _, e := range g.Entities { - physics.UpdateMove(&e.Move,&e.Position, moveMap) + physics.UpdateMove(&e.Move, &e.Position, moveMap) e.UpdateOrder(g) } return nil @@ -5,9 +5,8 @@ type Order interface { } func (e *Entity) UpdateOrder(g *Game) { - if e.Order.IsEnabled { - if e.Order.Value != nil { - e.Order.Value.Update(e, g) - } + if !e.Order.IsEnabled || e.Order.Value == nil { + return } + e.Order.Value.Update(e, g) } diff --git a/selection.go b/selection.go index 91f35fe..d9120d2 100644 --- a/selection.go +++ b/selection.go @@ -17,7 +17,7 @@ type Selection struct { func (e *Entity) SelectMultiple(cursor physics.Point, selection GlobalSelection) { if e.Selection.IsEnabled { e.Selection.Value.IsSelected = false - selectionBounds := physics.Rectangle{Min:selection.Start, Max:cursor}.Canon() + selectionBounds := physics.Rectangle{Min: selection.Start, Max: cursor}.Canon() if selectionBounds.Overlaps(e.Bounds()) { e.Selection.Value.IsSelected = true slog.Info("entity selected", slog.String("position", e.Position.Value.String())) |
